|
|
|
Re: Syntactic predicates in 0.8M4 [message #509674 is a reply to message #509665] |
Sun, 24 January 2010 15:41 |
Steven Derrien Messages: 50 Registered: July 2009 |
Member |
|
|
Hi Sven,
> Hi Steven,
>
> syntactic predicates are not yet supported nor is it a planned item (we
> plan per milestone).
> Could you outline what you want to solve. Many situations can be solved
> with LL(*) and backtracking.
>
I just wanted to get an idea of the required effort to adapt an exising
ANTLR C-ANSI grammar to Xtext. I set backtrack=true in MWE, there was no
error message, but my grammar is obviously not working/
BTW, If some people are interested by an C-ANSI Xtext parser, I'd be
glad to share my efforts.
Following is an excerpt of the an ANTLR C-ANSI grammar
(http://www.antlr.org/grammar/1153358328744/C.g) which uses predicates
to cope with declarator/definition ambiguity.
> /** Either a function definition or any other kind of C decl/def.
> * The LL(*) analysis algorithm fails to deal with this due to
^^^^^^^^^^^^^^ ^^^^^
> * recursion in the declarator rules. I'm putting in a
> * manual predicate here so that we don't backtrack over
> * the entire function. Further, you get a better error
> * as errors within the function itself don't make it fail
> * to predict that it's a function. Weird errors previously.
> * Remember: the goal is to avoid backtrack like the plague
> * because it makes debugging, actions, and errors harder.
> *
> * Note that k=1 results in a much smaller predictor for the
> * fixed lookahead; k=2 made a few extra thousand lines. ;)
> * I'll have to optimize that in the future.
> */
> external_declaration
> options {k=1;}
> : ( declaration_specifiers? declarator declaration* '{' )=> function_definition
> | declaration
> ;
Steven
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02009 seconds