Design Language For Compiler
Design Language For Compiler
S# TOPIC Date
DESIGN LANGUAGE FOR COMPILER
With reference to python
TOKENS
( Smallest individual unit in a program is known as token. )
Keyword Description
And A logical operator
As To create an alias
Assert For debugging
Break To break out of a loop
Class To define a class
Continue To continue to the next iteration of a loop
def To define a function
Del To delete an object
Elif Used in conditional statements, same as else if
Else Used in conditional statements
Except Used with exceptions, what to do when an exception occurs
False Boolean value, result of comparison operations
Finally Used with exceptions, a block of code that will be executed
no matter if there is an exception or not
For To create a for loop
From To import specific parts of a module
Global To declare a global variable
If To make a conditional statement
Import To import a module
In To check if a value is present in a list, tuple, etc.
Is To test if two variables are equal
Lambda To create an anonymous function
None Represents a null value
Nonlocal To declare a non-local variable
Not A logical operator
Or A logical operator
Pass A null statement, a statement that will do nothing
Raise To raise an exception
Return To exit a function and return a value
True Boolean value, result of comparison operations
Try To make a try...except statement
While To create a while loop
With Used to simplify exception handling
yield To end a function, returns a generator
Operators Constants
Arithmetic operators Integer
Assignment operators Float
Relational Operators String
Bitwise operators Boolean
Logical operators Character
Increment / Decrement
Identifiers
Punctuators
: ; . , ( ) { } [ ] “ ‘ ::
With reference to python
CLASSIFICATION
( Lexemes that are syntactically replaceable and have same precedence would be placed in same class )
Else Else
If If
Switch Switch
Exception Try , except , else
Case Switch
Class Class
Object Object
Method Method
Inheritance Inheritance
Encapsulation Encapsulation
Polymorphism Polymorphism
Regular Expression
Identifiers :
“ ^ ( - | A-Z a-z ) + [ a – z A – Z 0 – 9 _ ] * [ a – z A – Z 0 – 9 ] * [ a – z A – Z ] $ “
Integer Constant : “ ^ ( - | + ) ? [ 0 – 9 ] + $ “
Float Constant : “ ^ ( - | + ) ? [ 0 – 9 ] * . [ 0 – 9 ] * $ “
Char Constant :“^‘(\(A|C))|(B)|(C)‘$“
A = Characters with \ { | , “ }
B = without backlash \ { @ , # , + … }
C = with or without backlash { b , a , t , o }
String Constant : “ ^ “ ( \ ( A|C) ) | (B ) | ( C ) “ $ “
SYNTAX
If statement ( Python ) If else statement ( Python )
if expression: if expression:
statement(s) statement(s)
else:
statement(s)
While loop ( Python ) For Loop ( Python )
while expression: for iterating_var in sequence:
statement(s) statements(s)
List / Array Tuple ( Python )
Variable = [ ‘ item ‘ , item ] tup1 =('physics', 'chemistry );
tup2 = (1, 2, 3, 4, 5 );
tup3 = "a", "b", "c", "d";
Exception ( Python ) Class
try:
You do your operations here; class ClassName:
...................... 'Optional class documentation
except ExceptionI: string'
If there is ExceptionI, then class_suite
execute this block.
except ExceptionII:
If there is ExceptionII, then Object
execute this block.
...................... Variable = class( )
else:
If there is no exception then
execute this block.
case value-n:
Block-n;
Break;
default:
Block-1;
Break;
}
Statement-x;