LANGUAGE CONSTRUCTS
There are five language constructs of M#.
1. Keyword
2. Identifier
3. Comment
4. Terminator
5. Operators
KEYWORDS:
Keywords are the defined words or commands of the language. All keywords in this language are in upper-case to distinguish them from other normal words. M# focuses on five basic keywords, which are as follows:
1. START
2. END
3. INTEGER …show more content…
4. IF
5. DISPLAY
A brief description of each keyword is given below:
START:
Keyword that tells the compiler that program starts now, like main( ) in C/C++.
END:
Keyword that tells the compiler that program ends here.
INTEGER:
Keyword that tells the compiler that the data type of the identifier is a number.
IF:
Keyword for the conditional statement, to execute certain code if the expression is true
DISPLAY:
Keyword used for displaying or printing on the screen.
IDENTIFIERS:
An identifier is just like a variable which can hold different values. Identifiers in M# cannot have a number/digit in them. All characters in an identifier must be in small-case. Valid Identifiers Invalid Identifiers
Var Var1
Int 5int num 2nuM
COMMENTS:
Comments in M# are defined as any no. of strings or digits between the two hash ‘#’ symbols. Comments are represented as follows: #….. #
TERMINATOR:
Period or dot (.) is used for the termination of statements in this language. Each statement must end by a terminator.
OPERATORS:
The table below shows the valid Arithmetic and Relational Operators for the language.
Arithmetic Operators Relational Operators
1. + (Add) 1. = (Equal)
2. - (Subtract) 2. < (Less Than)
3. * (Multiply) 3. > (Greater Than)
4. / (Divide) ------
PHASE 1
LEXICAL …show more content…
ANALYZER
INTRODUCTION:
This is the first phase of compiler construction.
In this phase a token is generated against all the lexemes in the source code. These lexemes and tokens are stored in the Symbol Table. Tokens against the lexemes are generated based on some patterns or rules.
PATTERNS / REGULAR EXPRESSIONS
The patterns or regular expressions for the M# language constructs are given below.
KEYWORDS:
Keyword → START / END / INTEGER / IF / DISPLAY
This shows that any other word, even in upper-case letters will not be considered as the keyword for this language.
IDENTIFIER:
letter → a | b | … | z Identifier → letter (letter)*
This shows that there must be atleast one letter present for being identified as an identifier. It can have any number of letters in an identifier but they should be in lower-case.
COMMENTS:
Comment → # (string)* # where, string → letter | digit | operator | space etc letter → A | B | C | … | Z | a | b | … | z digit → 0 | 1 | 2 | … | 9 operator → + | * | - | / | > | < | = etc.
Comments can have any no. of letters, digits or operators within the two hash symbols. There may or may not be any character enclosed within the # symbol.
OPERATORS:
Arithmetic Operators ArthOp → + | - | * |
/
Relational Operators RelOp → = | < | >
TRANSITION DIAGRAMS
Transition diagrams show different states of transition of lexemes. A lexemes becomes acceptable if it reaches the final state. Transition diagrams for the language constructs are drawn below.
1. KEYWORDS:
START
END
INTEGER
IF
DISPLAY
2. IDENTIFIER:
letter → a | b | … | z
3. COMMENTS:
string → letter | digit | operator | space etc letter → A | B | C | … | Z | a | b | … | z digit → 0 | 1 | 2 | … | 9 operator → + | * | - | / | > | < | = etc.
4. OPERATORS:
Arithmetic Operators
Relational Operators