Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Data type rules - Can someone explain this concept to me?
Data type rules - Can someone explain this concept to me? [message #685770] Sun, 19 June 2011 18:50 Go to next message
john doe is currently offline john doeFriend
Messages: 74
Registered: June 2011
Member
I have read the tutorial on data types here (www.eclipse.org/Xtext/documentation/latest/xtext.html#datatypeRules), however I still don't really get why you would use a data type rule instead of a terminal rule.

If you look at the link above, why could you not just do the following instead?
terminal QUALIFIEDNAME :
  ID ('.' ID)*
;


Why can't we declare this as a lexer (terminal) rule instead of a parser rule? What exactly is a data type rule?

Thanks
Re: Data type rules - Can someone explain this concept to me? [message #685771 is a reply to message #685770] Sun, 19 June 2011 18:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

terminal rules go into the lexer. leing is done in the first phase of the parsing process and is done context free => ID ('.' ID)* will be always parsed
as that and something like parent=ID "." child=ID won't be possible. datatype rules are like other parser rules context sensitive.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Data type rules - Can someone explain this concept to me? [message #685774 is a reply to message #685771] Sun, 19 June 2011 19:28 Go to previous messageGo to next message
john doe is currently offline john doeFriend
Messages: 74
Registered: June 2011
Member
Thanks for the reply. When you say that

parent=ID "." child=ID


won't be possible, why is that?

And why would I not just define a terminal rule instead? Such as
that outlined in my first post?

Thank you!

[Updated on: Sun, 19 June 2011 19:42]

Report message to a moderator

Re: Data type rules - Can someone explain this concept to me? [message #685775 is a reply to message #685774] Sun, 19 June 2011 19:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi, if the lexer finds a x.y in the text it will be always parsed as a fqn and never as and ID followed by a . followe by a ID.
the lexers thus creates a token stream of the file and handles this to the parser.
so if the parser wants and ID and a . and another ID but always gets and FQN you ll get an unexpected token error.

So the basic problem is that there is first lexing (context free) and then parsing.

=> Terminal rules are for the lexer, Datatype rules for the parser
=> Terminal rules are context free, datatype rules are context sensitive.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Data type rules - Can someone explain this concept to me? [message #685776 is a reply to message #685775] Sun, 19 June 2011 19:37 Go to previous message
john doe is currently offline john doeFriend
Messages: 74
Registered: June 2011
Member
Makes sense.
Thank you very much for the help Christian.

Previous Topic:[Xtext2] Xtend RichStrings: Where is «REM»«ENDREM»?
Next Topic:DSL with mandatory prefix - incorporate in grammar ?
Goto Forum:
  


Current Time: Fri Apr 26 06:46:07 GMT 2024

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

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

Back to the top