Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* (Definitions Section) */
- %start program
- %token LET INTEGER IN
- %token SKIP IF THEN ELSE END WHILE DO READ WRITE
- %token NUMBER
- %token IDENTIFIER
- %left ’-’ ’+’
- %left ’*’ ’/’
- %right ’ˆ ’
- %%
- /* (Rules Section) */
- program : LET declarations IN commands END ;
- declarations : /* empty */
- | INTEGER id seq IDENTIFIER ’.’
- ;
- id seq : /* empty */
- | id seq IDENTIFIER ’,’
- ;
- commands : /* empty */
- | commands command ’;’
- ;
- command : SKIP
- | READ IDENTIFIER
- | WRITE exp
- | IDENTIFIER ASSGNOP exp
- | IF exp THEN commands ELSE commands FI
- | WHILE exp DO
- ;
- exp : NUMBER
- | IDENTIFIER
- | exp ’<’ exp
- | exp ’=’ exp
- | exp ’>’ exp
- | exp ’+’ exp
- | exp ’−’ exp
- | exp ’∗’ exp
- | exp ’/’ exp
- | exp ’ˆ ’ exp
- | ’(’ exp ’)’
- ;
- %%
- /* (C Section) */
- main( int argc, char *argv[] )
- { extern FILE *yyin;
- ++argv; −−argc;
- yyin = fopen( argv[0], ”r” );
- yydebug = 1;
- errors = 0;
- yyparse ();
- }
- yyerror (char *s) /* Called by yyparse on error */
- {
- printf (”%s\n”, s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement