[antlr-interest] Reuse of tokens and rules

Thomas Brandon tbrandonau at gmail.com
Sat Jul 1 12:20:00 PDT 2006


No problem, though note, as Ter says, that just having your lexer rule
handle the whole action block and then parsing the resulting string to
another parser may be a more straightforward option.
So, to handle multiple languages you could have something like:
ACTION:
   (    {isPython}? a=PYTHON_ACTION
   |    {isJava}? a=JAVA_ACTION
...
   ) { parseAction($a.text); }

fragment PYTHON_ACTION ...;

Though if you want to extend the set of languages later then seperate
grammars as in the example is probably better. Also, any errors found
parsing this way would need to be translated to proper locations for
reporting.

Tom.

On 7/1/06, Emond Papegaaij <e.papegaaij at student.utwente.nl> wrote:
> On Friday 30 June 2006 16:48, Thomas Brandon wrote:
> > Check out the island-grammar example in the v3 examples pack. Should give
> > you the basis for everything you need.
>
> Thanks for the hint. I think the island-grammar will work pretty well.
>
> Best regards,
> Emond
>


More information about the antlr-interest mailing list