Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Decision can match input such as "'(' RULE_ID '=' RULE_INT ')'" using multiple alternative
Decision can match input such as "'(' RULE_ID '=' RULE_INT ')'" using multiple alternative [message #900049] Fri, 03 August 2012 16:20 Go to next message
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
Hi,

I'm working on a DSL and i have a problem on declaration element
i want to support for example:
dcl a=3
dcl b=7
a=9

proc(a=3,b=7)


3 and 7 is the type of variable but 9 is an assignment
So, I've started with the following construct

Procedure:
'proc' name=ID (',d')? ('('argument+=VariableNameAndType (',' argument+=VariableNameAndType)* ')')? ((':' return+=VariableNameAndType)*)?
instructions+=Instruction* ;
Instruction:
VariableDeclaration|Expression;
Expression :
CompareOperator;
CompareOperator returns Expression:
PrimaryExpression(( {Inclusion.left=current} '='|{Equality.left=current}'=='|{NoInclusion.left=current}'!=') right=PrimaryExpression)*;
PrimaryExpression returns Expression:
NumericLiteral
| VariableOperande
| '(' Expression ')'
;
NumericLiteral:
value=Value;
Value:
NUMBER|INT
;
VariableOperande:
variable=[VariableName]
;
VariableDeclaration:
'dcl' variable=VariableNameAndType;
VariableName:name=ID;
VariableNameAndType:
name=VariableName type=Type;
Type:
BCDType
;
BCDType:
{BCDType}('='size=INT)?;

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

terminal NUMBER returns ecore::EBigDecimal:
('0'..'9')* ('.' ('0'..'9')+)?;

terminal ID : '<'?'^'?'"'? ('a'..'z'|'A'..'Z'|'$'|'_') ('a'..'z'|'A'..'Z'|'$'|'_'|'0'..'9')*'"'?'>'?;

But that's not working and I doubt that this is the right way. I'm new to Xtext and so this question might be quite stupid. Maybe somebody has an idea or can point me into the right direction? Thanks in advance!

Best regards,
Jérôme
Re: Decision can match input such as &quot;'(' RULE_ID '=' RULE_INT ')'&quot; using multiple [message #900095 is a reply to message #900049] Fri, 03 August 2012 22:03 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2501
Registered: July 2009
Senior Member
For starters, your INT and NUMBER terminals looks odd.

terminal INT returns ecore::EInt: ('0'..'9')*;
terminal NUMBER returns ecore::EBigDecimal:
('0'..'9')* ('.' ('0'..'9')+)?;

I think I get what you are trying to do here, but don' think that will
work. Ans since an INT was involved in the error message you got, I
think you need to address the terminals first.

Suggest writing a very small grammar with just your terminals, and some
very simple rules for parsing a sequence of INT and NUMBER, see if it
works ok.

This is what I used at one point:

terminal INT : ('0'..'9')+;
REAL hidden(): INT '.' (EXT_INT | INT);
terminal EXT_INT: INT ('e'|'E')('-'|'+') INT;

Note that REAL is *not* a terminal. If you don't need to support
scientific notation, simply do:

terminal INT : ('0'..'9')+;
REAL hidden(): INT '.' INT;

Other potential problems are keywords like ",d" - use ',' 'd' instead,
and if you do not allow whitspace do something like:

Procedure:
'proc' name=ID CommaD? ......
;
CommaD hidden():
',' 'd'
;

Where you have a problem if you need to know if there was a CommaD or
not. So you may want to do:
Procedure:
'proc' name=ID commaD ?= CommaD? ......
;

Your variable references also look odd. You probably want to have
variable reference the variable declarations itself, not the name of it.

i.e use:
VariableDeclaration:
'dcl' name = ID type = Type
;

VariableOperand:
variable = [VariableDeclaration]
;

Hope that helps, but there may be other things going on, as this does
not seem to be the entire grammar.

Regards
- henrik

On 2012-03-08 18:21, Laigle jérôme wrote:
> Hi,
>
> I'm working on a DSL and i have a problem on declaration element
> i want to support for example:
> dcl a=3
> dcl b=7
> a=9
>
> proc(a=3,b=7)
>
>
> 3 and 7 is the type of variable but 9 is an assignment
> So, I've started with the following construct
>
> Procedure:
> 'proc' name=ID (',d')? ('('argument+=VariableNameAndType (','
> argument+=VariableNameAndType)* ')')? ((':'
> return+=VariableNameAndType)*)? instructions+=Instruction* ;
> Instruction:
> VariableDeclaration|Expression;
> Expression :
> CompareOperator;
> CompareOperator returns Expression:
> PrimaryExpression(( {Inclusion.left=current}
> '='|{Equality.left=current}'=='|{NoInclusion.left=current}'!=')
> right=PrimaryExpression)*;
> PrimaryExpression returns Expression:
> NumericLiteral | VariableOperande
> | '(' Expression ')' ;
> NumericLiteral: value=Value; Value:
> NUMBER|INT
> ; VariableOperande:
> variable=[VariableName]
> ;
> VariableDeclaration:
> 'dcl' variable=VariableNameAndType;
> VariableName:name=ID;
> VariableNameAndType:
> name=VariableName type=Type;
> Type:
> BCDType
> ;
> BCDType:
> {BCDType}('='size=INT)?;
>
> terminal INT returns ecore::EInt: ('0'..'9')*;
>
> terminal NUMBER returns ecore::EBigDecimal:
> ('0'..'9')* ('.' ('0'..'9')+)?;
>
> terminal ID : '<'?'^'?'"'? ('a'..'z'|'A'..'Z'|'$'|'_')
> ('a'..'z'|'A'..'Z'|'$'|'_'|'0'..'9')*'"'?'>'?;
>
> But that's not working and I doubt that this is the right way. I'm new
> to Xtext and so this question might be quite stupid. Maybe somebody has
> an idea or can point me into the right direction? Thanks in advance!
>
> Best regards,
> Jérôme
Re: Decision can match input such as &quot;'(' RULE_ID '=' RULE_INT ')'&quot; using multiple [message #900267 is a reply to message #900095] Mon, 06 August 2012 09:20 Go to previous message
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
thank you for your help
Previous Topic:How to make the OutlineTreeProvider to not display children for an element
Next Topic:Why hyperlink is broken when corresponding Xtext resource is moved?
Goto Forum:
  


Current Time: Fri Dec 19 07:30:01 GMT 2014

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

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