test.sor
来自「SRI international 发布的OAA框架软件」· SOR 代码 · 共 58 行
SOR
58 行
#header <<
#include <stdio.h>
#include "SCommonAST.h"
class SORAST;
#include <string.h>
>>
<<
class SORAST : public SORCommonAST {
protected:
char text[50];
public:
SORAST() {setType(0);}
SORAST(ExprTreeParser::STokenType tok, char *s);
char *getText() { return text; }
void lisp_action(FILE *f);
};
/* This constr is implicitly called when you ref node constructor #[tok,s] */
SORAST::SORAST(ExprTreeParser::STokenType tok, char *s)
{
setType(tok);
strcpy(getText(), s);
}
void SORAST::
lisp_action(FILE *f)
{
fprintf(f, " %s", getText());
}
main()
{
SORAST *a, *result=NULL;
ExprTreeParser myparser;
/* M a k e I n p u t T r e e T o P a r s e */
/* 'a' expr is ( * a b ) == "a * b" */
a = #[ExprTreeParser::Mult,"*"];
a->addChild(#[ExprTreeParser::Var,"a"]);
a->addChild(#[ExprTreeParser::Var,"b"]);
printf("tree parser input: "); a->lisp(stdout); printf("\n");
myparser.expr((SORASTBase **)&a);
}
>>
class ExprTreeParser {
expr: #( Plus b:expr expr )
<<printf("plus opnds are : "); b->lisp(stdout); printf("\n");>>
| #( Mult b:expr expr )
<<printf("mult opnds are : "); b->lisp(stdout); printf("\n");>>
| Var
;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?