2 Replies - 14076 Views - Last Post: 15 July 2010 - 01:47 PM

#1 largedimples   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-October 09

FIRST AND FOLLOW GRAMMAR

Posted 14 July 2010 - 08:51 PM

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 { $, ; }

Is This A Good Question/Topic? 0
  • +

Replies To: FIRST AND FOLLOW GRAMMAR

#2 largedimples   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-October 09

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
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: FIRST AND FOLLOW GRAMMAR

Posted 15 July 2010 - 01:47 PM

Topics merged. Please avoid duplicate posting. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1