Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- /****************************************************************************
- parser.y
- ParserWizard generated YACC file.
- Author: .................................
- Date: 8 padziernika 2009
- ****************************************************************************/
- //#include <conio.h> /* getch() */
- #include "common.h" /* MAX_STR_LEN */
- #if defined( PG )
- #include "lexer.h" /* tylko dla Parser Generatora */
- #endif
- %}
- /***************************************************************************/
- /* declarations section - place any declarations here */
- /***************************************************************************/
- /* DEKLARACJA TOKENÓW */
- %token KW_CHAR KW_UNSIGNED KW_INT KW_VOID KW_FOR KW_DOUBLE
- %token INT_NUMBER FLOAT_NUMBER IDENT TEXT_CONST
- %token INC LE
- %token CHAR
- %union
- { /* DEKLARACJA TYPU TOKENÓW */
- char s[ MAX_STR_LEN + 1 ]; /* pole tekstowe dla nazw itp. */
- int i; /* pole całkowite */
- double d; /* pole zmiennoprzecinkowe */
- }
- %%
- /***************************************************************************/
- /* rules section - place your YACC rules here (there must be at least one) */
- /***************************************************************************/
- Grammar: /* empty */
- | TOKENS
- ;
- TOKENS: TOKEN
- | TOKENS TOKEN
- ;
- TOKEN: KW_CHAR | KW_UNSIGNED | KW_INT | KW_VOID | KW_FOR | KW_DOUBLE
- | INT_NUMBER | FLOAT_NUMBER | IDENT | TEXT_CONST | CHAR
- | INC | LE | '+' | '-' | '*' | '/' | ';' | ',' | '='
- | '(' | ')' | '{' | '}'
- | error
- ;
- %%
- /***************************************************************************/
- /* programs section */
- /***************************************************************************/
- int main( void )
- {
- int ret;
- printf( "Autor: Gerwazy Żeberko\n" );
- printf( "yytext Typ tokena Wartosc tokena znakowo\n\n" );
- #if defined( PG ) /* Parser Generator */
- /* poniższa inicjalizacja strumieni wyłšcznie dla Parser Generatora */
- yyin = stdin;
- yyout = stdout;
- yylexerr = stderr;
- #endif
- /* wywołanie parsera */
- ret = yyparse();
- #if defined( PG ) /* Parser Generator */
- getch();
- #endif
- return ret;
- }
- #if defined( PG ) /* Parser Generator */
- void yyerror( const char *txt )
- #else
- int yyerror( const char *txt )
- #endif
- {
- printf( "Syntax error %s", txt );
- #if !defined( PG ) /* Parser Generator */
- return( 0 );
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement