\ %class lex %{ #include <iostream.h> #include "yacc.tab.h" #include <grammar/lex.h> %} %% [a-z]+ { return token(A,yytext); } [A-Z]+ { return token(B,yytext); } %%
\ %class yacc\ %token A B %{ #include <grammar/yacc.h> %}\ %start sequence %% sequence : { cout << "empty\n"; } | A { cout << (char*) *$1 << " : A\n"; } sequence | B { cout << *$1 << " : B\n"; } sequence ; %%
// file main.c
#include <grammar/lex.h>
#include <grammar/yacc.h>
main() { lex sc; yacc y(sc); y(); }
The example makes use of a parser class yacc for which a (pre-defined) declaration is given in <grammar/yacc.h>. The user may declare other parser classes in a similar way.
// file <grammar/yacc.h>
#include <grammar/parser.h>
class yacc : public yacc_parser {
public:
yacc(scanner& sc) : parser(sc) { }
term* operator()();
};
|
Hush Online Technology
hush@cs.vu.nl
09/24/99 |
|
|