[antlr-interest] Variable definition annoyances

Scott Stanchfield scott at javadude.com
Sat Mar 26 12:03:26 PST 2005


> > Though while we're at it, I'd really like to define a 
> standard syntax 
> > that can be for antlr replacement in action code with an 
> obvious start 
> > and end, which is why I suggested a paired delimiter like 
> :: on either 
> > end.
> > We'd just
> > need to pick something not super likely to appear in the 
> action code...
> 
> Why do you need the replacement thing?  So you could alter 
> the code generator more easily?  I'm trying to avoid 
> translation but I need to for @i.

I'm trying to come up with a common way that code generators could find
things they want to replace.

Code gens could allow "replacement plugins" to add function.

For example, in the XML support I wrote, I wanted to replace "@foo" with
attributes. I had to add this to the action processor, which basically makes
it all-or-nothing.

I'd love to be able to have a generalized action scanner that does the
following:

  for each delimited thing t in the action code
      for each replacement plugin p
          if p.wantsToReplace(t)
              replace t with p.getReplacement(thing)

Something like that. This would allow custom action code plugins,
simplifying the code generator.

For the XML support, I replace @foo with something like
    ((XMLToken)_startToken).getAttributes().get("foo")

Now to make this work right as a plugin, it would have to cooperate with the
code generator. In this example, I'd need to know the "_startToken" that
matched the xml token. So the action processing plugin would have to either
cooperate with the code gen, or be explicit like @startToken:foo. Have to
think ont to get it right.

> >> rule returns [int i, String s] : ... {@i=3; @s="foo";} ... ;
> >>
> >> Cool eh?  Does this satisfy you?  It integrates very 
> nicely with the 
> >> dynamically scoped attributes and trees etc...
> >
> > Actually, why would we need to use the @ in that syntax? In 
> ANTLR 2.0 
> > with the same syntax we just use i and s...
> 
> Because these suckers can be dynamically scoped and don't 
> translate to simply i and s. :)
> 
> >  Wait a sec... Multiple return
> > values? Are you pushing them on a stack or something?
> 
> Currently I'm using the method stack, but I'm going to change 
> that to my own stack.  I push an aggregate with the return 
> values as fields.

That's what I thought...

Later,
-- Scott





More information about the antlr-interest mailing list