Advertisement
Guest User

correções para sistemas debian

a guest
Apr 29th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #compiling flex only
  2. $ flex file.l
  3. $ gcc lex.yy.c -o file
  4. $ ./file
  5.  
  6. #compiling flex + bison
  7. $ flex file.l
  8. $ bison -d file.y
  9. $ gcc file.tab.c -o file lex.yy.c
  10. $ ./file
  11.  
  12.  
  13.  
  14.  
  15. /*lexico.l ou eg1.l*/
  16. %{
  17.     #include "eg1.tab.h"
  18. %}
  19.  
  20. %%
  21. [0-9]+                  {return NUM;}
  22. [a-zA-Z][a-zA-Z0-9]*    {return ID;}
  23. [ \t]+                  {;}
  24. .|\n                    {return yytext[0];}
  25.  
  26. %%
  27. int yywrap() {
  28.     return 1;
  29. }
  30.  
  31.  
  32.  
  33.  
  34. /*sintatico.y ou eg1.y*/
  35. /* Verificando a sintaxe de programas segundo nossa GLC-exemplo */
  36. /* considerando notacao polonesa para expressoes */
  37. %{
  38.     #include <stdio.h>
  39.     void yyerror(char *); /* added */
  40.     int yylex(void); /* added */
  41. %}
  42. %token NUM
  43. %token ID
  44.  
  45. %%
  46. /* Regras definindo a GLC e acoes correspondentes */
  47. /* neste nosso exemplo quase todas as acoes estao vazias */
  48. input:      /* empty */
  49.             | input line
  50. ;
  51. line:       '\n'
  52.             | programa '\n'         { printf ("Programa sintaticamente correto!\n"); }
  53. ;
  54. programa:   '{' lista_cmds '}'      {;}
  55. ;
  56. lista_cmds: cmd ';'                 {;}
  57.             | cmd ';' lista_cmds    {;}
  58. ;
  59. cmd:        ID '=' exp              {;}
  60. ;
  61. exp:        NUM                     {;}
  62.             | ID                    {;}
  63.             | exp exp '+'           {;}
  64. ;
  65.  
  66. %%
  67. int main(void)
  68. {
  69.     yyparse ();
  70. }
  71.  
  72. void yyerror (char *s) /* Called by yyparse on error */
  73. {
  74.     printf ("Problema com a analise sintatica!\n");
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement