test.g
资源名称:pccts133.zip [点击查看]
上传用户:itx_2006
上传日期:2007-01-06
资源大小:493k
文件大小:1k
源码类别:
编译器/解释器
开发平台:
Others
- <<
- #include ATOKPTR_H // define smart pointers
- class ANTLRToken : public ANTLRCommonToken {
- public:
- int muck;
- public:
- ANTLRToken(ANTLRTokenType t, ANTLRChar *s) : ANTLRCommonToken(t,s)
- { muck = atoi(s); }
- ANTLRToken() {;}
- ANTLRChar *getText() const { return ""; }
- void setText(const ANTLRChar *s) { ; }
- virtual ANTLRAbstractToken *makeToken(ANTLRTokenType t, char *s, int line)
- {
- ANTLRToken *tk = new ANTLRToken(t,s);
- tk->muck = atoi(s);
- return tk;
- }
- };
- #include "DLGLexer.h"
- #include "PBlackBox.h"
- int main()
- {
- ParserBlackBox<DLGLexer, Expr, ANTLRToken> p(stdin);
- p.parser()->calc();
- return 0;
- }
- >>
- #token "[ tn]+" <<skip();>>
- class Expr {
- calc: <<int r;>>
- e>[r]
- <<printf("result is %dn", r);>>
- ;
- e > [int r]
- : <<int b;>>
- e2>[$r] ( "+" e2>[b] <<$r+=b;>> )*
- ;
- e2 > [int r]
- : NUMBER <<$r=mytoken($1)->muck;>>
- ( "*" NUMBER <<$r*=mytoken($2)->muck;>> )*
- ;
- }
- #token NUMBER "[0-9]+"