Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext - Recursive grammar
Xtext - Recursive grammar [message #1066988] Fri, 05 July 2013 11:00 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
How can I use a recursive grammar?

I have the following code:
model:
defs += CFG_objects
;

CFG_objects:
statement=ID name=ID '{'
(par+=CFG_pars)*
'}' (':' comment=STRING)? ';'
;

CFG_pars:
condition=ID val=ID
('{' (pars+=CFG_pars) '}')?
(':' comment=STRING)? ';'
;


It throws me an error with this:

switch answer
{
case good : do_nothing ;
}: store answer;


What is wrong with my grammar? How can I implement a recursive grammar rule? I was expecting the above example to work.

[Updated on: Fri, 05 July 2013 11:01]

Report message to a moderator

Re: Xtext - Recursive grammar [message #1066991 is a reply to message #1066988] Fri, 05 July 2013 11:13 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

you define your comments as String, but in your sample they are not. STRING requires single or double quotes.

Also, you are probably missing "+" or "*" in your list definitions (model feature defs, CFG_pars feature pars).

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Xtext - Recursive grammar [message #1067246 is a reply to message #1066991] Mon, 08 July 2013 03:39 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Hello,

I have changed the code and my configuration. But I am still getting an error.

model:
defs += CFG_objects
;

CFG_objects:
statement=ID name=ID '{'
(pars+=CFG_pars)*
'}' (':' comment=STRING1)? ';'
;

CFG_pars:
condition=ID val=ID
('{' (pars+=CFG_pars)* '}')?
(':' comment=STRING1)? ';'
;
terminal STRING1: '"' -> '"';




switch answer
{
case good : "do nothing" ;
TYPE bad;
}: "store answer";



The error I am getting is:
ERROR:mismatched input 'TYPE' expecting '}'
ERROR:extraneous input ';' expecting RULE_ID

[Updated on: Mon, 08 July 2013 03:40]

Report message to a moderator

Re: Xtext - Recursive grammar [message #1067254 is a reply to message #1067246] Mon, 08 July 2013 06:31 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

this is not the complete grammar. It does not rise the problem you claim.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Xtext - Recursive grammar [message #1067327 is a reply to message #1066988] Mon, 08 July 2013 10:15 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I have modified the grammar a bit.

Model:
defs += CFG_objects*
;

CFG_objects:
	statement=ID name=ID '{'
	(pars+=CFG_pars)*
	'}'  comment=CFG_comment ';'
;

CFG_pars:
	name=ID value=SPECIAL
	('{' (pars+=CFG_pars)* '}')?
	comment=CFG_comment ';'
;

CFG_comment: {CFG_comment}
	(':' comment=STRING1)?
;

SPECIAL hidden():
	STRING1 | ID | INT| HEX | DOUBLE
;

terminal STRING1: '"' -> '"';
terminal DOUBLE:  INT '.' INT;
terminal HEX: '0' ('x' | 'X')(('0'..'9') | ('a'..'f') | ('A'..'F'))+;


I noticed that the error only occur in some scenarios.

switch answer
{
case good : "do nothing" ;
TYPE BAD; <--Problem line-->
PRIO HIGH;
}: "store answer";


If I change the problem line to "type", parsing still will not work. But other keywords works fine (e.g.STATUS, Size, size).



Re: Xtext - Recursive grammar [message #1067330 is a reply to message #1067327] Mon, 08 July 2013 10:24 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

this is still not the complete grammar, the example is processed without errors. My guess is that you use "TYPE" as a keyword somewhere in your real grammar. That way TYPE will not be read as ID (as your rule reqires) but as keyword token.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Xtext - Recursive grammar [message #1067481 is a reply to message #1067330] Tue, 09 July 2013 01:48 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
OH! You are right! [Banging head on the monitor screen]
Been staring at this for a week now.

Is there a way to fix this? I do not want to specify each possible keyword. But other rules do require for the "TYPE" keyword to be there.

[Updated on: Tue, 09 July 2013 01:57]

Report message to a moderator

Re: Xtext - Recursive grammar [message #1067499 is a reply to message #1067481] Tue, 09 July 2013 06:25 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
See e.g. here. I'd recommend simple escaping if possible.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Previous Topic:XText rejects user defined hidden terminal rules
Next Topic:Factoring out rules with no wrapper return types
Goto Forum:
  


Current Time: Fri Mar 29 06:08:01 GMT 2024

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

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

Back to the top