grammar expr;
assign : ID '=' expr;
expr : term ( ('+' | '-') term)*;
term : unary ( ('*' | '/') unary)*;
unary : '-' unary | factor;
factor : '(' expr ')'
| ID
| INT
;
INT: [0-9]+ ;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;
virtual antlrcpp::Any visitNumberexpr(toyParser::NumberexprContext *ctx) override {
int val = 2;
antlrcpp::Any any(val);
return any;
}
virtual antlrcpp::Any visitPrimary(toyParser::PrimaryContext *ctx) override {
antlrcpp::Any ret = visitChildren(ctx);
int val = 0;
if (ret.isNotNull())
val = (int)ret;
return ret;
}
I use antlrcpp::Any as contener. For example for int type:
I am writing:
virtual antlrcpp::Any visitNumberexpr(toyParser::NumberexprContext *ctx) override {
int val = 2;
antlrcpp::Any any(val);
return any;
}
I think it would be easy using llvm::Value
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussion+unsubscribe@googlegroups.com.