test.g
资源名称:pccts133.zip [点击查看]
上传用户:itx_2006
上传日期:2007-01-06
资源大小:493k
文件大小:1k
源码类别:
编译器/解释器
开发平台:
Others
- /* This is test.g which tests a simple DLG-based scanner using string input */
- <<
- typedef ANTLRCommonToken ANTLRToken;
- #include "DLGLexer.h"
- #include "PBlackBox.h"
- int main(int argc, char **argv)
- {
- if ( argc==1 ) {fprintf(stderr, "how about an argument?n"); exit(1);}
- DLGStringInput in(argv[1]); /* create an input stream for DLG */
- DLGLexer scan(&in); /* create scanner reading from stdin */
- ANTLRTokenBuffer pipe(&scan); /* make pipe between lexer & parser */
- ANTLRTokenPtr aToken = new ANTLRToken;
- scan.setToken(mytoken(aToken));
- Expr parser(&pipe); /* create parser of type Expr hooked to scanner */
- parser.init(); /* init the parser; prime lookahead etc... */
- parser.e(); /* start parsing at rule 'e' of that parser */
- return 0;
- }
- >>
- #token "[ tn]+" <<skip();>>
- #token Eof "@"
- #tokclass My { IDENTIFIER NUMBER }
- class Expr { /* Define a grammar class */
- e : My My Eof
- <<fprintf(stderr, "text is %s,%sn", $1->getText(), $2->getText());>>
- ;
- }
- #token IDENTIFIER "[a-z]+"
- #token NUMBER "[0-9]+"