14

I'm building a parser in antlr which compiles to a working java target. When I retarget for c#2 it produces a parser in which all of the parse methods are private but marked with a [GrammarRule("rulename")] attribute.

What is the approved means to actually invoke the parser?

I am using ANTLR 3.3 Nov 30, 2010 12:45:30

Thanks, Andy

1 Answer 1

20

Make at least one parser rule "public" like this:

grammar T;

options {
  language=CSharp2;
}

public parse
  :  privateRule+ EOF
  ;

privateRule
  :  Token+
  ;

// ...

You can then call parse() on the generated parser.

protected and private (the default if nothing is specified) are also supported.

2
  • 2
    Thanks, I couldn't find any documentation to this effect. Commented Jun 20, 2011 at 13:19
  • @Andy, you're welcome. Yeah, it works a bit differently than the Java target where you can use these keywords, but are not implemented. ANTLR's Java target by default produces the public modifier. So it should still work with the Java target if you put a public before some parser rule.
    – Bart Kiers
    Commented Jun 20, 2011 at 13:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.