|
Re: Decision can match input such as "'(' RULE_ID '=' RULE_INT ')'" using multiple [message #900095 is a reply to message #900049] |
Fri, 03 August 2012 22:03 |
Henrik Lindberg Messages: 2509 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04951 seconds