%{ #define YYDEBUG 1 #include "wspace.h" static int counter = 0; %} %union { tokenInfo ti; } %token COMMENT NEWLINE TAB SPACE %{ /* Here is an example comment. */ %} %% program: program statement | ; statement: COMMENT { printf("A COMMENT\n"); } | NEWLINE { printf("NEWLINE: %c\n", top()); } | TAB { printf("TAB: %d\n", top()); } | SPACE { counter++; push(counter); printf("SPACE\n"); } ; %% #include "lex.yy.c" int yyerror(char *s, int lineNumber) { fprintf(stderr, "Error: %s at line number %d\n", s, lineNumber); return 0; } int main( int argc, char **argv ) { yydebug = 0; /* increment everything so we skip the program name */ ++argv; --argc; if (argc == 1) { yyin = fopen( argv[0], "r"); } else { printf("Usage: ws filename\n"); exit(0); } createStack(); printf("***** Starting to parse\n"); yyparse(); printf("***** Ending the parse\n"); deleteStack(); return 0; }