Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolve Non-LL(*) decisions
Resolve Non-LL(*) decisions [message #827372] Fri, 23 March 2012 08:33
Alex G is currently offline Alex GFriend
Messages: 96
Registered: January 2012

Let's assume the following grammar:

	name = ID (indexList = IndexList)?;
IndexList: ('[' args+=LogicalExpr (',' args+=LogicalExpr)* ']');

LogicalExpr: LogExprAtom;
LogExprAtom returns LogicalExpr:
	{LogicalAtom} someref = [AnotherType] |
	{BooleanAtom} bool = 'true' |
	"(" LogicalExpr ")";
AnotherType: ...

QualifiedRule: // we are looking at this
	"Rule_nonLL" (s1=SimpleRule '.')? s2=SimpleRule;

QualifiedRule is non-LL(*), since SimpleRule leads to a theoretically infinite recursion on LogicalExpr and it's not possible with ANTLR to decide which rule we consumed, the first SimpleRule or the second SimpleRule. We can force the parser in two ways:

Way 1: Introduce a syntactic predicate
	"Rule_nonLL_hacked" (s1=SimpleRule '.')? s2=SimpleRule;

Ways 2: Make the optional statement on the right, since we parse from left to right:
	"Rule_Working" s1=SimpleRule ('.' s2=SimpleRule)?;

The problem now is, that an introduction of syntactic predicates makes it hard to follow the grammar locally, meaning, that we have to know exactly, what the grammar does globally. Way 2 helps here, but consider the following type cross-reference problem:

	"Rule_TypeA" (s1=SimpleRule '.')? s2=SimpleRuleTypeA;

	"Rule_TypeB" (s1=SimpleRule '.')? s2=SimpleRuleTypeB;

	name = [TypeA|ID] (indexList = IndexList)?;

	name = [TypeB|ID] (indexList = IndexList)?;

TypeA: name="TypeA";
TypeB: name="TypeB";

If we want here to enable "Way 2", we have to declare a supertype for TypeA and TypeB for references, since both consume an ID.

Is there an alternative way to solve this problem without introducing syntactic predicates or an artificial supertype (which makes the generated ecore model unnecessary enhanced)?

Previous Topic:Wiki-like Syntax
Next Topic:Get src path inside the plugin
Goto Forum:

Current Time: Wed Apr 08 19:17:58 GMT 2020

Powered by FUDForum. Page generated in 0.01779 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top