/* match1.y MR 04/07/99 Input file to 'bison' (or 'yacc'). How to generate the parser program: 1) Run bison on this file: bison match1.y 2) Compile the bison output: gcc match1.tab.c -o match1 */ %token ID %token OTHER %start input %% input : /* empty */ | input token ; token : ID { printf( "ID\n" ); } | '(' { printf( "(\n" ); } | ')' { printf( ")\n" ); } | '{' { printf( "{\n" ); } | '}' { printf( "}\n" ); } | ';' { printf( ";\n" ); } | OTHER { printf( "OTHER\n" ); } ; %% #include main() { yyparse(); } yyerror( char * str ) { printf( "match1: %s\n", str ); } int isLetter( int c ) { if ( 'a' <= (char)c && (char)c <= 'z' ) { return 1; } else if ( 'A' <= (char)c && (char)c <= 'Z' ) { return 1; } else { return 0; } } int isDigit( int c ) { return ( '0' <= (char)c && (char)c <= '9' ); } int yylex( void ) { int ic; /* Eat up white space */ while ( ic = getchar(), ic == ' ' || ic == '\t' || ic == '\n' ) { ; } if ( ic == EOF ) { return 0; /* End of input text */ } else if ( isLetter(ic) ) { do { ic = getchar(); } while ( isLetter(ic) || isDigit(ic) ); ungetc( ic, stdin ); /* yylval = ...; */ return ID; } else if ( ic == '(' || ic == ')' || ic == '{' || ic == '}' || ic == ';' ) { return ic; /* Return special operator as character */ } else { return OTHER; } /* Nog toe te voegen als ``OTHER'': comment, literal numbers/characters/strings ... */ /* Vooral z.d.d. dingen binnen strings en binnen comment niet als functie calls/definities worden gezien. */ }