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

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
Andy Bisson
  • 580
  • 5
  • 19

1 Answers1

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.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • 2
    Thanks, I couldn't find any documentation to this effect. – Andy Bisson Jun 20 '11 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 Jun 20 '11 at 13:23