
July 11th, 2010, 08:57 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 3
Time spent in forums: 1 h 26 m 51 sec
Reputation Power: 0
|
|
|
Help with LEX/YACC homework [was: First and Follow set for c grammar]
Please tell me if I did this homework correctly. If it not correct please provide directions which will help me understand it better.
5.1 Compute the first sets for the following grammar:
%token ID ‘==’ ‘<’ ‘>’ ‘(‘ ‘)’ ‘=’ ‘if’ ‘;’
%start Stmts
%%
Stmts : Stmt ‘;’ Stmts ;
Stmt : Var ‘=’ Expr
| ‘if’ Expr Stmt ;
Expr : ‘(‘ ID Op ID ‘)’ ;
Var : ID ;
Op : ‘>’
| ‘<’
| ‘==’ ;
First
Stmts { ID, ; }
Stmt { ID Op ID, ( }
Expr { ID Op ID, ( }
Var { ID }
Op { >, <, ==, }
5.2 Compute the follow sets for the grammar in question 5.1
Follow
Stmts { $, ; }
Stmt { $, ) }
Expr { ;, ) }
Var { $, ; }
Op { $, ; }
thanks in advance
|