Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » difference terminals and datatypes
icon5.gif  difference terminals and datatypes [message #1692515] Thu, 16 April 2015 10:28 Go to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
Hi,
I am developing a language that has a part of its terminals and a rule like the below:

-------------------------------------------------------
terminal fragment BASIC_ID:
LETTER('_' | LETTER_OR_DIGIT)*
;
terminal fragment SPECIAL_ID:
GRAPHICS_CHAR | LC_LETTERS
;

terminal ID: BASIC_ID | SPECIAL_ID ;

terminal INTEGER :
DIGIT | DIGIT ('_'? DIGIT)+
;

time_rule:
INTEGER ID ;
--------------------------------------------------------
Now when I write 6000ns it gives an error while 6000 ns is not giving errors. I want to allow both cases (with/without) spaces.

Shall I change terminals to datatypes or vice versa? Any Help with that please.

Thanks
Re: difference terminals and datatypes [message #1692518 is a reply to message #1692515] Thu, 16 April 2015 10:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

just some hints

- use as few terminals as possible
- do not use spaces in terminal


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: difference terminals and datatypes [message #1692519 is a reply to message #1692518] Thu, 16 April 2015 10:40 Go to previous messageGo to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
you mean these terminals:

terminal WS:
(' ' | '\t' | '\r' | '\n')+
;


terminal SL_COMMENT:
'//' !('\n' | '\r')* ('\r'? '\n')?
;

terminal ML_COMMENT:
'/*'->'*/'
;

I am added them and set them as Hidden rules
Re: difference terminals and datatypes [message #1692522 is a reply to message #1692519] Thu, 16 April 2015 10:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
No other terminals you did not show

if the lexer recognizes 12345ns as a terminal it cannot be parsed as a datatype rule "firstterminal secondterminal"


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: difference terminals and datatypes [message #1692526 is a reply to message #1692522] Thu, 16 April 2015 10:58 Go to previous messageGo to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
What should be defined as terminals and what should be defined as datatypes? Integers and letters for example?
Re: difference terminals and datatypes [message #1692527 is a reply to message #1692526] Thu, 16 April 2015 11:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

this depends on your usecase

if you want to have 1234ns being parsed as two parts and 1234 ns beeing identified as two parts
you should not have a terminal rules that matches 1234ns but one that matches 1234 and another that matches ns (e.g. a keyword)

=> do the basic parts only as terminals and those who do not interfere e.g. strings comments etc


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: difference terminals and datatypes [message #1692532 is a reply to message #1692527] Thu, 16 April 2015 11:21 Go to previous messageGo to next message
Eleanor Richie is currently offline Eleanor RichieFriend
Messages: 125
Registered: August 2014
Senior Member
The problem is solved but wherever I use the ns for example as a variable name it is highlighted and gives an error. I don't want it to be a keyword so I can use it in different places. the same issue with exponential numbers, the 'e' is always highlighted but I don't want it as a keyword in the same time I want specifically 'e' and not any other letter
Re: difference terminals and datatypes [message #1692533 is a reply to message #1692532] Thu, 16 April 2015 11:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

if ns is a keyword or a terminal then it will be not ne recognized as an ID by the lexer anymore

=> you have to use a datatype rule for name names as well:

MyID : ID | "ns";

Variable:
"var" name=MyID;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: difference terminals and datatypes [message #1692534 is a reply to message #1692533] Thu, 16 April 2015 11:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
And if you dont want highlighting: have a look at semantic highlighting

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Protected region support
Next Topic:Extending the Xtext Generator
Goto Forum:
  


Current Time: Thu Mar 28 22:22:49 GMT 2024

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

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

Back to the top