Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

MUHAMMAD MUKARRAM (02-134192-054)

Assignment:1
Q1. What is compiler? Why should we study Compiler; Give at least 5 suitable
reasons
A compiler is a program that converts statements written in a programming language into
machine language, or "code," that is used by a computer's processor. A programmer often
uses an editor to write language statements in a language such as Pascal or C one line at a
time. The source statements are contained in the file that is created. The programmer then
launches the appropriate language compiler, giving the name of the source statement file.

It is useful for a computer scientist to study compiler design for several reasons.

1. Anyone who does any software development needs to use a compiler. It is a good
idea to understand what is going on inside the tools that you use.
2. Compilers are sophisticated text processors. Most programs need to do some text
processing, even if only to read in the contents of a configuration file.

3. A useful software design technique for large projects is to develop a special-purpose


language that makes the project easy to implement.
4. Compilers benefit tremendously from careful analysis of a problem, and from tools
for performing that analysis. A study of compiler design gives a good feeling for how
a large problem can be broken down and solved in a manner that is not ad-hoc.
5. Compiler design makes use of formal methods that are rarely seen elsewhere except
when quite difficult formal methods are used for general purpose software design.
The study of compilers provides a gentle introduction to formal methods.

Q2. Design Regular Expression for password that must hold the following conditions and
then write code.
INPUT:
import re
pattern = r"^[?_][?_][C][A-z+0-9][A-z+0-9][d][d][A-z+0-9][A-z+0-9][z][0-9][0-9]$"
password = input("Enter string to test: ")
result = re.findall(pattern, password)
if (result):
print ("Valid password")
else:
print ("Password not valid")
• Password should be 11 characters in length
1
MUHAMMAD MUKARRAM (02-134192-054)

• 3rd character should be C and 10th character should be z

• First two characters should belong to { (,* , ? ,_ }

• Last two should be digits (0 to 9)

• Password should contain a sub string dd

You might also like