test.g
资源名称:pccts133.zip [点击查看]
上传用户:itx_2006
上传日期:2007-01-06
资源大小:493k
文件大小:2k
源码类别:
编译器/解释器
开发平台:
Others
- /* This tests a simple DLG-based scanner plus (...)? predicates */
- <<
- typedef ANTLRCommonToken ANTLRToken;
- #include "DLGLexer.h"
- #include "PBlackBox.h"
- int main()
- {
- ParserBlackBox<DLGLexer, Expr, ANTLRToken> p(stdin);
- p.parser()->begin();
- return 0;
- }
- void doit(Expr *p)
- {
- printf("LT(1) is %sn", ((ANTLRToken *)p->LT(1))->getText());
- printf("LT(2) is %sn", ((ANTLRToken *)p->LT(2))->getText());
- printf("LT(3) is %sn", ((ANTLRToken *)p->LT(3))->getText());
- printf("LT(4) is %sn", ((ANTLRToken *)p->LT(4))->getText());
- printf("LT(5) is %sn", ((ANTLRToken *)p->LT(5))->getText());
- printf("LT(6) is %sn", ((ANTLRToken *)p->LT(6))->getText());
- printf("LT(7) is %sn", ((ANTLRToken *)p->LT(7))->getText());
- printf("LT(8) is %sn", ((ANTLRToken *)p->LT(8))->getText());
- printf("LT(9) is %sn", ((ANTLRToken *)p->LT(9))->getText());
- printf("LT(10) is %sn", ((ANTLRToken *)p->LT(10))->getText());
- printf("LT(11) is %sn", ((ANTLRToken *)p->LT(11))->getText());
- }
- >>
- #token "[ tn]+" <<skip();>>
- #token Eof "@"
- class Expr { /* Define a grammar class */
- begin
- : <</*doit(this);*/>>
- e
- ;
- e : ( list "=" )? list "=" list Eof
- <<printf("list = listn");>>
- | list Eof
- <<printf("listn");>>
- ;
- list: "(" (IDENTIFIER|NUMBER)* ")"
- ;
- predict
- : ( "(" (IDENTIFIER|NUMBER)* ")" "=")?
- | "(" ")" "="
- ;
- /*
- Here's another example...
- #token INT "int"
- #token SEMI ";"
- #token STAR "*"
- #token ASSIGN "="
- begin: "extern" "char" declarator ";"
- ;
- e : (decl)?
- | expr
- ;
- expr: IDENTIFIER "=" NUMBER
- ;
- decl: "int" declarator ";"
- ;
- declarator
- : ( "*" )? "*" declarator
- | IDENTIFIER
- ;
- */
- }
- #token IDENTIFIER "[a-z]+"
- #token NUMBER "[0-9]+"