Did I compute the first and follow grammar correctly?
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 { $, ; }
FIRST AND FOLLOW GRAMMAR
Page 1 of 12 Replies - 14076 Views - Last Post: 15 July 2010 - 01:47 PM
Replies To: FIRST AND FOLLOW GRAMMAR
#2
Re: FIRST AND FOLLOW GRAMMAR
Posted 15 July 2010 - 03:47 AM
Did I compute the first and follow grammar correctly?
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 { $, ; }
Was This Post Helpful? 0
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 { $, ; }
Was This Post Helpful? 0
#3
Re: FIRST AND FOLLOW GRAMMAR
Posted 15 July 2010 - 01:47 PM
Topics merged. Please avoid duplicate posting.
Page 1 of 1

New Topic/Question
Reply



MultiQuote





|