%{ #include #include /* #include "gram.h" #include "proto.h" */ int R=0; %} %token NOUN VERB DET PREP AP PUNCT UNDEF PIND INTEIRO %% SS : S PUNCT { puts("S ");R=0; return ;} /* | NP [puts("NP");] PUNCT {return ;} */ | PREP PUNCT {R=33; return ;} | error ANY {yyerrok; puts("ANY? "); R=2; return ;} ; ANY : NOUN | VERB | DET | PREP | AP | PUNCT | UNDEF | PIND ; S : NP VP ; S : S PP ; S : PP S ; NP : NP1 | PIND ; NP : DET inte NP1 ; inte : | INTEIRO ; NP1 : NOUN {puts("a name...!!!");} ; NP1 : AP NP1 ; PP : PREP NP ; VP : VERB NP ; VP : VERB ; %% FILE* yyin; extern int yydebug; #include "gramlex1.c" int main(argc, argv) int argc; char *argv[]; { int result; yydebug = 1; yyin = stdin; do { result = yyparse(); printf("res= %d.\n",R);} while (R != 33); /* printf("Result = %d\n", result); */ return 0; } static void yyinit() {} static void yyerror(message) char* message; { fprintf(stderr, "%s\n", message); /*exit(1);*/ }