Xtext Grammar [message #1015528] |
Fri, 01 March 2013 06:12 |
rohit ahuja Messages: 27 Registered: February 2013 |
Junior Member |
|
|
Hi All,
I am new to Xtext and writing a DSL.
I have something like
'Case:' CaseName = ID
Now the variable CaseName can contain simple only Integer Values i.e any combination of 0-9, or only Alphabets i.e. any combination of the A-Z or a-z, or a mixed case.
If i keep it as above, xtext doesn't allow me to have a single int value,
say 'Case: 0'
I tried with the below method
'Case:' CaseName = ID|INT -- but it doesn't work for obvious reasons.
If i try to create another terminal like (0-9|a-z|A-Z)*, it starts interfering with other rules in the grammar.
I think there must be some other way, can anyone help me with this?
In general, can any variable be assigned to two types?
Thanks,
Rohit Ahuja
|
|
|
|
|
Re: Xtext Grammar [message #1015564 is a reply to message #1015561] |
Fri, 01 March 2013 09:07 |
|
Hi,
this is a question of lexing and parsing
lexing is done first and is context free.
parsing in done on the lexical token stream and context sensitive.
terminal IDORINT: ID|INT;
is a lexer rule
IDORINT: ID|INT;
is a parser rule (datatype rule)
so use the datatype rule and not the terminal rule
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.05089 seconds