Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #compiling flex only
- $ flex file.l
- $ gcc lex.yy.c -o file
- $ ./file
- #compiling flex + bison
- $ flex file.l
- $ bison -d file.y
- $ gcc file.tab.c -o file lex.yy.c
- $ ./file
- /*lexico.l ou eg1.l*/
- %{
- #include "eg1.tab.h"
- %}
- %%
- [0-9]+ {return NUM;}
- [a-zA-Z][a-zA-Z0-9]* {return ID;}
- [ \t]+ {;}
- .|\n {return yytext[0];}
- %%
- int yywrap() {
- return 1;
- }
- /*sintatico.y ou eg1.y*/
- /* Verificando a sintaxe de programas segundo nossa GLC-exemplo */
- /* considerando notacao polonesa para expressoes */
- %{
- #include <stdio.h>
- void yyerror(char *); /* added */
- int yylex(void); /* added */
- %}
- %token NUM
- %token ID
- %%
- /* Regras definindo a GLC e acoes correspondentes */
- /* neste nosso exemplo quase todas as acoes estao vazias */
- input: /* empty */
- | input line
- ;
- line: '\n'
- | programa '\n' { printf ("Programa sintaticamente correto!\n"); }
- ;
- programa: '{' lista_cmds '}' {;}
- ;
- lista_cmds: cmd ';' {;}
- | cmd ';' lista_cmds {;}
- ;
- cmd: ID '=' exp {;}
- ;
- exp: NUM {;}
- | ID {;}
- | exp exp '+' {;}
- ;
- %%
- int main(void)
- {
- yyparse ();
- }
- void yyerror (char *s) /* Called by yyparse on error */
- {
- printf ("Problema com a analise sintatica!\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement