Professional Documents
Culture Documents
Definition :-
TYPE VALUE
IDENT sqrt
INTCONSTANT 1
RELOP >
ADDOP -
Token Definition Example
Numeric literals in Pascal
◦ Definition of the token unsigned_number
digit 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Example :- “sqrt”
Lexical Analysis
Consider this expression in the C programming language:
sum=3+2;
Token stream
Parsing
Abstract syntax tree
Intermediate code
Code Generation
Assembly code
Lexical Analysis
Source code if (b == 0) a = “hi”;
(character stream) Lexical analysis
Token
stream if ( b == 0 ) a = “hi” ;
Parsing
Semantic Analysis
i f ( x 1 * x 2 <1 . 0 ) { \n
ID CONSTANT CONSTANT
IFKEY LPAREN ID(b) RELOP(E CONSTANT(0) RPAREN ID(a) ASSIGNOP CONSTANT(63) SEM
Q) I
i f ( b = = 0 ) a = 6 3 ;
GetNextToken:
Calls AssembleSimpleToken
GetNextToken Changes Ids to keywords where necessary
Returns next token in input stream
AssembleSimpleToken :
Calls GetNextChar repeatedly The FSA
AssembleSimpleToken Assembles char sequences into valid tokens
Returns simple token
GetNextChar :
Returns the next significant
GetNextChar token in the input stream