[antlr-interest] On to the next issue: error(211)

Hendrik Maryns qwizv9b02 at sneakemail.com
Tue Nov 11 04:52:19 PST 2008


Gavin Lambert schreef:
> At 00:33 11/11/2008, Hendrik Maryns wrote:
>  >error(211): fsqTreeParser.g:68:3: [fatal] rule body has 
> non-LL(*)
>  >decision due to recursive rule invocations reachable from alts
>  >3,5. Resolve by left-factoring or using syntactic predicates or
>  >using backtrack=true option.
> [...]
>  >body returns [Formula result]
>  >  : label { $result = $label.result; }
>  >  | atomic { $result = $atomic.result; }
>  >  | unary { $result = $unary.result; }
>  >  | binary { $result = $binary.result; }
>  >  | n_ary { $result = $n_ary.result; }
>  >  | quantor { $result = $quantor.result; }
>  >  ;
>  >
>  >Indeed, the unary, binary, n_ary and quantor rules (indirectly)
>  >refer to formula:
> 
> It's unlikely that this would be the problem, or at least not 
> directly.  It's more likely an issue with your AST structure being 
> too ambiguous.

You are right, I had a lisp-like grammar in the parser, so there it
worked fine, since it saw the functor first, which disambiguated the
rules.  However, I rewrote them for the tree parser with the arguments
coming first, introducing the ambiguities.  I did this because it made
the Java code in the background simpler.

I stepped away from this approach, making my parser radically simpler.
Focussing first on getting my parser to recognize the proper strings has
now worked (some details aside), and I will now gently try to adopt it
to produce the right output.

The thing I am having trouble with is that, with the idea of
polymorphism etc., I’d like to have things dealt with at the appropriate
place.

I have rules like

atomic : atomicHead variable label ;

atomicHead : EQUALITY | DOMINANCE | INCLUSION | … ;

and depending on the value of atomicHead, I want a different Java object
to be created.  The solution I see now is stuff like

if ($atomicHead.text == "=") {
  new Equality($first, $second);
} else if ($functor.text == ">" {
  new Dominance($first, $second);
} else …

and so on.  But it would be better if I could delegate this to
atomicHead, which would have code execution for each subrule.  However,
I cannot do

atomic return [Formula result] : atomicHead[$variable.result,
$label.result] variable label { $result = $atomicHead.result; };

since $variable.result and $label.result will not have been evaluated at
that point.

Anyone better suggestions?

> Can you post your unary, binary, and n_ary rules (and any subrules 
> they refer to)?

I am sure even in the simpler grammar enough questions will arise, to be
handled later :-)

Thanks a lot, H.
-- 
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 257 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081111/6aa7f35f/attachment.bin 


More information about the antlr-interest mailing list