parser: scanning, main routine

Lex input:

%{ #include "k.h" /* data type defs (INCL. YYSTYPE) */ #include "y.tab.h" /* yacc (token) definitions */ %} %% [\t\n ] { ; } /* skip white space */ [0-9]+ { yylval.yt_int = atoi(yytext); return T_INT; } . { return yytext[0]; }
Main routine that parses an expression, and then displays it:

%{ #include "y.tab.h" /* yacc (token) definitions */ expr the_expr; /* the root of our parse tree */ %} int main() { yyparse(); /* invoke parser */ fdotprint_expr( stdout, e, "the_expr", 0, 0, True, True, True ); exit(0); /* success! */ } void yyerror(char *s) { fprintf(stderr, "%s\n", s); exit(1); }
We now can use this parser from the Unix command line, eg. like this:

$ echo '(1+1) * (1+1)' | parser | dot -Tps | ghostview -

next overview up


Last updated at 03 February '98 by kimwitu@cs.utwente.nl