[antlr-interest] Tricky vector constructor syntax

Paul Johnson gt54-antlr at cyconix.com
Sun Jul 17 23:46:03 PDT 2005


Nigel Sheridan-Smith wrote:
>>-----Original Message-----
>>From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>>bounces at antlr.org] On Behalf Of Richard Matthias
>>The grammar (which I've attached) has an expression section shamelessly
>>lifted from the java.g sample grammar but altered slightly to match the
>>original yacc grammar supplied by the makers of the game. For the moment

Does the yacc grammar handle the vector init? If so, it would be 
(very)interesting to see how they do it.

>>I've
>>placed a rule for just the vector at the same level as the other constants
>>(the last alt of the postfixExpression rule) and even with a syntactic
>>predicate it still causes the same ambiguity warning. Does this look right
>>or
>>should I try and shoehorn it in at the same level as the < operator?

At first sight, I'd say it's in the wrong place; an initialiser isn't a 
postfix expression. It should have a very low priority, which might fix 
your immediate problem by itself. Look at a real C grammar; Tom 
Stockfisch's yacc grammar is a good starting point.

> What this means is that the following bits of code are ambiguous:
> 
> x = < 1, 1, 1 > 5 >;
> 
> Not sure how to solve this one, as I have trouble getting syntactic
> predicates in the optional alternatives right. Maybe someone else can
> suggest an appropriate change?

If you have to give your initialiser such a high priority, then your 
answer may be to exclude relationals from the expressions in the list. 
You'll need two expression syntaxes: a normal one, and one which 
excludes relationals; then you might have

postfixExpression
     ...
     < expr_non_relational , expr_non_relational , expr_non_relational >

HTH

Paul



More information about the antlr-interest mailing list