[antlr-interest] same character for multiple rules?

Jim Idle jimi at temporal-wave.com
Tue Jul 5 13:00:41 PDT 2011


For visual basic you need a much more involved rule:


assignStatement
	: lvalues
		(
			  // Assignments
			  //
			  (
				compoundBinaryOperator
			  )

		 	  expression

		 	  	-> ^(compoundBinaryOperator lvalues
expression)

		 	| // Without any operators, then we must have had
an invocation
		 	  //
				-> ^(CALL lvalues)
		)
	;


compoundBinaryOperator
	: OPCATEQ
	| OPEXPEQ
	| OPMULEQ
	| OPDIVEQ
	| OPIDIVEQ
	| OPPLUSEQ
	| OPMINUSEQ
	| OPSLEQ
	| OPSREQ
	| OPEQ
	;


Then your expression tree can use OPEQ in the correct precedence order as
needed.

I have commercially available grammars for VB.Net and C# if you (or anyone
else) are interested.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Roy Metzger
> Sent: Tuesday, July 05, 2011 5:00 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] same character for multiple rules?
>
> Hi and Hello to everyone,
>
> I would really appreciate any hints and advices if someone can give my
> relating to my problem. I would like to know how to deal with the
> situation where you would use same character for multiple
> rules/operations. For example in Visual Basic you use '=' for both
> variable assignment (a=10) and for comparison (if(a=10 then ....).
>
> Clearly, using assignment rule:assignment:
>
>   ID '=' expression;
>
> and later relation rule:
> relation:
> atom ('=' atom)*;
>
> gives out error like rule relation has non-LL(*) decision due to
> recursive rule  invocations reachable from alts 1,6.  Resolve by left-
> factoring or using syntactic predicates or using backtrack=true option.
> And, yes, it is clear that antlr can not decide when to use assignment
> and when comparison, makes sense. But, my question is, how to deal with
> this? I'm not interested in using different characters for rules(e.x.
> '==' etc.). Is this where I have to look into the backtracking? Or is
> there some other way, that I'm not aware of?
>
>
> Help would be most appreciated,
> Lee
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list