Advertisement
desdemona

PARSER.y

Oct 15th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. %{
  2. /****************************************************************************
  3. parser.y
  4. ParserWizard generated YACC file.
  5. Author: .................................
  6. Date: 8 paŸdziernika 2009
  7. ****************************************************************************/
  8.  
  9. //#include <conio.h> /* getch() */
  10. #include "common.h" /* MAX_STR_LEN */
  11. #if defined( PG )
  12. #include "lexer.h" /* tylko dla Parser Generatora */
  13. #endif
  14. %}
  15.  
  16. /***************************************************************************/
  17. /*           declarations section - place any declarations here            */
  18. /***************************************************************************/
  19.  
  20. /* DEKLARACJA TOKENÓW */
  21. %token KW_CHAR KW_UNSIGNED KW_INT KW_VOID KW_FOR KW_DOUBLE
  22. %token INT_NUMBER FLOAT_NUMBER IDENT TEXT_CONST
  23. %token INC LE
  24. %token CHAR
  25.  
  26. %union
  27. { /* DEKLARACJA TYPU TOKENÓW */
  28.     char s[ MAX_STR_LEN + 1 ]; /* pole tekstowe dla nazw itp. */
  29.     int i; /* pole całkowite */
  30.     double d; /* pole zmiennoprzecinkowe */
  31. }
  32.  
  33. %%
  34.  
  35. /***************************************************************************/
  36. /* rules section - place your YACC rules here (there must be at least one) */
  37. /***************************************************************************/
  38.  
  39. Grammar: /* empty */
  40.     | TOKENS
  41. ;
  42.    
  43. TOKENS: TOKEN
  44.     | TOKENS TOKEN
  45. ;
  46.  
  47. TOKEN: KW_CHAR | KW_UNSIGNED | KW_INT | KW_VOID | KW_FOR | KW_DOUBLE
  48.     | INT_NUMBER | FLOAT_NUMBER | IDENT | TEXT_CONST | CHAR
  49.     | INC | LE | '+' | '-' | '*' | '/' | ';' | ',' | '='
  50.     | '(' | ')' | '{' | '}'
  51.     | error
  52. ;  
  53.  
  54. %%
  55.  
  56. /***************************************************************************/
  57. /*                            programs section                             */
  58. /***************************************************************************/
  59.  
  60. int main( void )
  61. {
  62.     int ret;
  63.     printf( "Autor: Gerwazy Żeberko\n" );
  64.     printf( "yytext              Typ tokena      Wartosc tokena znakowo\n\n" );
  65. #if defined( PG ) /* Parser Generator */
  66.     /* poniższa inicjalizacja strumieni wyłšcznie dla Parser Generatora */
  67.     yyin = stdin;
  68.     yyout = stdout;
  69.     yylexerr = stderr;
  70. #endif
  71.     /* wywołanie parsera */
  72.     ret = yyparse();
  73. #if defined( PG ) /* Parser Generator */
  74.     getch();
  75. #endif
  76.     return ret;
  77. }
  78.  
  79. #if defined( PG ) /* Parser Generator */
  80. void yyerror( const char *txt )
  81. #else
  82. int yyerror( const char *txt )
  83. #endif
  84. {
  85.     printf( "Syntax error %s", txt );
  86. #if !defined( PG ) /* Parser Generator */
  87.     return( 0 );
  88. #endif
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement