[antlr-interest] Actions in predicates

Marcin Rzeźnicki marcin.rzeznicki at gmail.com
Mon Feb 22 08:56:10 PST 2010


Hi all
Yet another question from me ( if someone could reply to the old one, then
I'd be grateful:
http://www.antlr.org/pipermail/antlr-interest/2010-February/037693.html -
sorry for spamming):
Is there a way to fire an action during syntactic predicate and only then? I
am trying to parse language in which semicolons as delimiters are optional.
So my lexer puts them by default in different channel. But there are cases
when I need to resolve ambiguities using syntactic predicates and I'd really
need to switch to emitting semicolons during predicates because parser can
use this information to resolve an ambiguity. A short excerpt from the
grammar I am working on:

basic_expression
  :
  (
    (
      target
      | manifest_type
    )
    DOT
  )
    => call
  | target

During predicate used to disambiguate call subrule I'd need to fire action
which sets appropriate flag in my lexer ordering it to emit semicolons to
the main channel. Furthermore, I'd have to switch this mode off when exiting
a predicate. Following version of my grammar was produced as an attempt at
this:

basic_expression
  :
  ( { <<set_flag_here>> }
    (
      target
      | manifest_type


    DOT { <<unset_flag_here>> }
  )
    => call
  | target

Unfortunately it won't work because of two things. First of all, my actions
are within (state.backtracking == 0) which is obviously not true during
predicate evaluation, and, final action won't be executed if backtracking
fails. Any ideas?

 Thanks for your answers

-- 
Greetings
Marcin Rzeźnicki


More information about the antlr-interest mailing list