#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    3
    Rep 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
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Moved to other programming languages forum. This is a lex/yacc question rather than C
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0
    Originally Posted by Scorpions4ever
    Moved to other programming languages forum. This is a lex/yacc question rather than C
    Thank you

IMN logo majestic logo threadwatch logo seochat tools logo