Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include <stdio.h>
- #include "functii.h"
- extern FILE* yyin;
- extern char* yytext;
- extern int yylineno;
- extern int yylval;
- %}
- %start PRG
- %left PLUS MINUS
- %left INM IMP
- %token ID TIP
- %token BGINF ENDF
- %token EGAL
- %token NR
- %token PLUS MINUS
- %token INM IMP
- %token MOD
- %token PRINT
- %%
- PRG: declaratii bloc {printf("program corect sintactic\n");}
- ;
- declaratii : declaratie ';'
- | declaratii declaratie ';'
- ;
- declaratie : TIP ids
- | TIP ID '(' lista_param ')'
- | TIP ID '(' ')'
- ;
- ids : ID ',' ids
- | ID
- ;
- lista_param : param
- | lista_param ',' param
- ;
- param : TIP ID
- ;
- /* bloc */
- bloc : BGINF list ENDF
- ;
- lista_apel : NR
- | lista_apel ',' NR
- ;
- /* lista instructiuni */
- list : stmt ';'
- | list stmt ';'
- ;
- /* instructiuni */
- expr: ID | NR
- | expr PLUS expr {$$ = $1 + $3;}
- | expr MINUS expr {$$ = $1 - $3;}
- | expr INM expr {$$ = $1 * $3;}
- | expr IMP expr {if($3 != 0) $$ = $1 / $3;}
- | MOD '(' expr ',' expr ')' {$$ = f_mod($1, $3);}
- ;
- stmt: ID EGAL expr
- | ID '(' lista_apel ')'
- | PRINT '(' ids ')'
- ;
- %%
- int yyerror(char * s){
- printf("eroare: %s la linia:%d\n",s,yylineno);
- }
- int main(int argc, char** argv){
- yyin=fopen(argv[1],"r");
- yyparse();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement