Consider the following grammar: (//some alternative rules are listed on separate lines without using symbol |):
stmt −> assignment
−> subr call
assignment −> id := expr
subr call −> id ( arg list )
expr −> primary expr tail
expr tail −> op expr
−> ε
primary −> id
−> subr call
−> ( expr )
op −> + | - | * | /
arg list −> expr args tail
args tail −> , arg list
−> ε
(a) Construct a parse tree for the input string foo(a,b).
(b) Give a canonical (right-most) derivation of this same string.
(c) Prove that the grammar is not LL(1). (//hint: find an example that LL(1) does not work).
(d) Modify the grammar so that it is LL(1). (//hint: use left factoring)
Consider the following grammar: (//some alternative rules are listed on separate lines without using symbol |):...
Write a parser program for cSub using the method of recursive descent. The main program here will effectively be the main program of the compiler as a whole. The input to the program will be a Csub source file, specified on the command line. The program will construct a parse tree for the program, with one interior node for every nonterminal in the derivation of the program, and one leaf node for each of the id, num, and real tokens...