G is the following grammar, with start nonterminal S. Symbols 'x' ',' '(' and ')' are tokens.
1. S | → | '(' L ')' |
2. S | → | 'x' |
3. L | → | S R |
4. R | → | ε |
5. R | → | ',' L |
Define FIRST(S), FIRST(L) and FIRST(R) for grammar G.
Define FOLLOW(S), FOLLOW(L) and FOLLOW(R) for G.
Show an LL(1) parsing table for G.
Write a recursive-descent parser for G. Assume that function match(t) is available, and that the lookahead token is in global variable lookahead. The lookahead will be '$' at the end of the input.
Make each of your functions return the total number of 'x' tokens in the part of the input that it matches.
If your parser encounters a syntax error, make it call syntax_error(). syntax_error() will not return.
H is the following grammar, with start nonterminal S. Symbols 'a', 'b' and 'c' are tokens.
1. S | → | 'a' S 'a' |
2. S | → | 'b' S 'b' |
3. S | → | L |
4. L | → | ε |
5. L | → | 'c' L |
Define FIRST(S) and FIRST(L) for grammar H.
Define FOLLOW(S) and FOLLOW(L) for H.
Show an LL(1) parsing table for H.
Write a recursive-descent parser for H. Assume that function match(t) is available, and that the lookahead token is in global variable lookahead. The lookahead will be '$' at the end of the input.
Make each of your functions return the total number of 'c' tokens in the part of the input that it matches.
If your parser encounters a syntax error, make it call syntax_error(). syntax_error() will not return.