Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with my grammar(Need some clues)
Problem with my grammar [message #870199] Mon, 07 May 2012 08:55 Go to next message
Florian Yger is currently offline Florian YgerFriend
Messages: 5
Registered: May 2012
Junior Member
Hello,

I have some problems with writing my grammar.

Header: x=INT y=INT;

terminal INT returns ecore::EInt: ('1'..'9')* ('0'..'9');



For Header, if i put '0', i get an mismatch error, expected INT.

I just don't understand ...
Re: Problem with my grammar [message #870249 is a reply to message #870199] Mon, 07 May 2012 12:56 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-07-05 10:56, Florian Yger wrote:
> Hello,
>
> I have some problems with writing my grammar.
>
>
> Header: x=INT y=INT;
>
> terminal INT returns ecore::EInt: ('1'..'9')* ('0'..'9');
>
>
>
> For Header, if i put '0', i get an mismatch error, expected INT.
>
> I just don't understand ...
>
Can you post the complete grammar? Sounds like an overlapping terminals
problem.

- henrik
Re: Problem with my grammar [message #870330 is a reply to message #870249] Mon, 07 May 2012 16:29 Go to previous messageGo to next message
Florian Yger is currently offline Florian YgerFriend
Messages: 5
Registered: May 2012
Junior Member
grammar org.graphstream.DGS hidden(WS)

generate dGS "h ttp://www.graphstream.org/DGS"

import "h ttp://www.eclipse.org/emf/2002/Ecore" as ecore

Dgs: header=Header (event+=Event | comment+=COMMENT | EOL)*;

Header: magic=MAGIC EOL name=(ID | STRING) numberOfSteps=INT numberOfEvents=INT EOL;

terminal MAGIC: 'DGS003'|'DGS004';

Event: (an=An|cn=Cn|dn=Dn|ae=Ae|ce=Ce|de=De|cg=Cg|st=St|cl=Cl) (comment=COMMENT | EOL);

An: 'an' idNode=(ID | STRING) attributes=Attributes;
	
Cn: 'cn' idNode=(ID | STRING) attributes=Attributes;
	
Dn: 'dn' idNode=(ID | STRING);
	
Ae: 'ae' idEdge=(ID | STRING) idNode1=(ID | STRING) (direction=DIRECTION)? idNode2=(ID | STRING) attributes=Attributes;
	
Ce: 'ce' idNode=(ID | STRING) attributes=Attributes;
	
De: 'de' idEdge=(ID | STRING);
	
Cg: 'cg' attributes=Attributes;
	
St: 'st' real=Real;

terminal Cl: 'cl';

Attributes: {Attributes} (attribute+=Attribute)*;
	
Attribute: ('+'|'-')? idAttribute=(ID | STRING) (assign=ASSIGN value=Value (',' otherValues+=Value)*)?;
	
Value: (string=STRING | real=Real | array=Array | map=Map);
	
Array: {Array} '{' (value=Value (',' otherValues+=Value)*)? '}';
		
Map: '[' mapping=Mapping (',' otherMapping+=Mapping)* ']';

Mapping: id=(ID | STRING) assign=ASSIGN value=Value;

terminal DIRECTION: '<'|'>';
	
terminal ASSIGN: '='|':';

terminal COMMENT: '#' -> EOL;

Real returns ecore::EDouble: INT ('.' ('0')* INT)?;

terminal INT returns ecore::EInt: ('1'..'9')* ('0'..'9');

terminal STRING returns ecore::EString: '"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"';

terminal ID returns ecore::EString: ('a'..'z' | 'A'..'Z' | '0'..'9')+;

terminal EOL: ('\r')? '\n';

terminal WS: (' '|'\t')+;
Re: Problem with my grammar [message #870348 is a reply to message #870330] Mon, 07 May 2012 17:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13669
Registered: July 2009
Senior Member
Hi,

i cannot reproduce your problem. (using Xtext 2.2.1) can you share a test model?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with my grammar [message #870390 is a reply to message #870199] Mon, 07 May 2012 22:29 Go to previous messageGo to next message
Florian Yger is currently offline Florian YgerFriend
Messages: 5
Registered: May 2012
Junior Member
DGS004
null 0 0
Re: Problem with my grammar [message #870418 is a reply to message #870390] Tue, 08 May 2012 06:26 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13669
Registered: July 2009
Senior Member
Hi,

your ID rule and your INT rule are Actually colliding.
and your real rule is disturbing the parser as well (since it intoduces zero as keyword)

=> you could try something like (i did not look at the amiguity problem)

INT returns ecore::EInt: ZERO | (DIGIT (DIGIT|ZERO)*);

Real returns ecore::EDouble: DIGIT (DIGIT|ZERO)+ ('.' (DIGIT|ZERO)+)?;

ID returns ecore::EString: (ZERO|DIGIT|ALPHA)+;

terminal ZERO : '0';
terminal DIGIT : '1'..'9';
terminal ALPHA : ('a'..'z' | 'A'..'Z')+;


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 08 May 2012 06:29]

Report message to a moderator

Previous Topic:Setup Xpand workflow: No Definition 'MyTemplate::main ...' found!
Next Topic:generating wizards
Goto Forum:
  


Current Time: Sat Dec 05 00:58:56 GMT 2020

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

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

Back to the top