[antlr-interest] Context and @synpredgate

Julian Mensch jmensch at shaw.ca
Sat Mar 7 14:47:58 PST 2009


  Ok, second newbie question. I'm building a bytecode compiler
that uses multiple passes. Most of these are very, very simple
and have only a few actions for counting things and recognizing
early declarations. One has literally hundreds of actions, most
of which are under a line -- simple assignment statements to
memory structures that get allocated after the counting on the
first pass.

  So I'd like to use @synpredgate in order to turn off _most_
actions, but not all -- I'd like to exempt actions from certain
specific rules. This avoids me having to include if statement
macros in _every single action_. I thought I could use members
or somesuch, but I can't, for obvious reasons: once I set the
bool variable to turn actions off, they're off, and I can't reset
the variable later because actions aren't being executed
anymore.

  Is there any way to know what rule you're in when using
@synpredgate? Do @init and @after still get executed?

  Incidentally, I do know about the speed advantage of parse
trees for multi-pass compilers. I may wanr to refactor to that
eventually, but right now I just want to get my code to work
in close to the form it was when I used ACCENT.

  Thanks,

-- Julian Mensch


More information about the antlr-interest mailing list