test.g
资源名称:pccts133.zip [点击查看]
上传用户:itx_2006
上传日期:2007-01-06
资源大小:493k
文件大小:1k
源码类别:
编译器/解释器
开发平台:
Others
- /* This is test.g which tests a simple DLG-based scanner
- * with user-defined tokens
- */
- /* Here, we use #tokdefs to define token types, but still let DLG do the
- * lexing. ANTLR will not create a tokens.h file.
- */
- #tokdefs "mytokens.h"
- <<
- #include "DLGLexer.h" /* include definition of DLGLexer.
- * This cannot be generated automatically because
- * ANTLR has no idea what you will call this file
- * with the DLG command-line options.
- */
- typedef ANTLRCommonToken ANTLRToken;
- int main()
- {
- ANTLRTokenPtr aToken = new ANTLRToken;
- DLGFileInput in(stdin);
- DLGLexer scan(&in);
- ANTLRTokenBuffer pipe(&scan);
- scan.setToken(mytoken(aToken));
- Expr parser(&pipe);
- parser.init();
- parser.e();
- return 0;
- }
- >>
- #token "[ tn]+" <<skip();>>
- class Expr { /* Define a grammar class */
- e : IDENTIFIER NUMBER "@"
- <<fprintf(stderr, "text is %s,%sn", $1->getText(), $2->getText());>>
- ;
- }
- #token IDENTIFIER "[a-z]+"
- #token NUMBER "[0-9]+"
English
