1

I have a grammar as roughly defined in Tutorial for walking ANTLR ASTs in C#?:

grammar Test; 

options 
{
language = 'CSharp3'; 
output=AST; 
} 
public expr : mexpr (PLUS^ mexpr)* SEMI! 
; 
mexpr 
: atom (STAR^ atom)* 
; 
atom: INT 
; 
//class csharpTestLexer extends Lexer; 
WS : (' ' 
| '\t' 
| '\n' 
| '\r') 
{ $channel = Hidden; } 
; 
LPAREN: '(' 
; 
RPAREN: ')' 
; 
STAR: '*' 
; 
PLUS: '+' 
; 
SEMI: ';' 
; 
protected 
DIGIT 
: '0'..'9' 
; 
INT : (DIGIT)+ 
;

This builds, but leaves me with no parser.expr_result class which I did expect, and parser.expr() returns AstParserRuleReturnScope what am I doing wrong? Are it the options? tool commandline options? anything else?

1 Answer 1

1

ANTLR 3.3 declares rule expr like so:

    public TestParser.expr_return expr()

ANTLR 3.4 declares it like so:

    public AstParserRuleReturnScope<object, IToken> expr()

Here's the definition of TestParser.expr_return:

    public class expr_return : ParserRuleReturnScope<IToken>, IAstRuleReturnScope<object>
    {
        private object _tree;
        public object Tree { get { return _tree; } set { _tree = value; } }
    }

The AstParserRuleReturnScope class appears equivalent to the generated expr_return class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.