Question 7:
Lexical analyzer is the first phase of the compiler that is used to convert source code into stream of tokens which is passed to the next phase syntax analyzer.
For example: int x = 5;
will be converted to [int,keyword][x,identifier][assignment][5,constant][terminator]
Lexical analyzer uses the concept of regular languages such as regular expressions, finite automata, regular grammar,etc.
Question 8:
Let D be the set of digits, and N be the set of non-vowel upper case letter
D = {0,1,2,3,4,5,6,7,8,9}
N = {B,C,D,F,G,H,J,K,L,M,N,P,Q,R,S,T,V,W,X,Y,Z}
Regular expression:
(0+1+2+3+4+5+6+7+8+9)(a+b)(B+C+D+F+G+H+J+K+L+M+N+P+Q+R+S+T+V+W+X+Y+Z)
or
D(a+b)N
Question 9:
The language can be represented as:
S ={epsilon, ab, aabb, aaabbb, aaaabbbb,....} = {anbn, n>=0}
Context free grammar:
The regular expression cannot be constructed for the this language as this is not a regular language.
Question 10:
Regular expression is:
Corresponding NFA is:
7. Lexical analyzer, is the first phase in compiler, Of what use is this to the...
12. Use the following SDT to convert an infix expression (9*3+2) to it post-fix equivalent. Semantic rules Production (print(")) ) (priot ()) () (print (num.lval)) E E+T T TP- [5 marks F num 13. Briefly explain the relevance of DAG and TAC at the Intermediate code generation phase. Give an example of DAG(Directed Acyclic Graph) with its equivalent TAC(Three-Address Code). [6 marks 14. Parser table is very important in predictive parsing; construct a parser table for the following CFG: S...