test.g
资源名称:pccts133.zip [点击查看]
上传用户:itx_2006
上传日期:2007-01-06
资源大小:493k
文件大小:1k
源码类别:
编译器/解释器
开发平台:
Others
- /* This is test.g which tests simple AST refs and construction */
- <<
- typedef ANTLRCommonToken ANTLRToken;
- #include "DLGLexer.h"
- #include "PBlackBox.h"
- class AST : public ASTBase {
- public:
- ANTLRTokenPtr token;
- AST(ANTLRTokenPtr t) { token = t; }
- void preorder_action() {
- char *s = token->getText();
- printf(" %s", s);
- }
- };
- int main()
- {
- ParserBlackBox<DLGLexer, Expr, ANTLRToken> p(stdin);
- ASTBase *root = NULL;
- p.parser()->e(&root);
- root->preorder();
- printf("n");
- root->destroy();
- return 0;
- }
- >>
- #token "[ tn]+" <<skip();>>
- #token Eof "@"
- class Expr { /* Define a grammar class */
- e : mult_expr ( ("+"^|"-"^) mult_expr )*
- ;
- mult_expr
- : atom ( ("*"^|"/"^) atom )*
- ;
- atom: IDENTIFIER
- | NUMBER
- ;
- }
- #token IDENTIFIER "[a-z]+"
- #token NUMBER "[0-9]+"