Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to write terminals/rules with same subset of characters
How to write terminals/rules with same subset of characters [message #1494778] Mon, 01 December 2014 19:04 Go to next message
Grégoire Avot is currently offline Grégoire AvotFriend
Messages: 7
Registered: December 2014
Junior Member
Hello Forum,

I am new user on Xtext, I want to understand how to be able to parse the following input:

129
o 37

Each line is either
- a decimal formed of one or more DECIMAL_DIGIT: '0'..'9'
- an octal value: 'o' <optional space> OCTAL_DIGIT: '0'..'7'

I am not able to find an elegant solution, based either on terminal or parser rules.

Does anybody have the solution,

Thank you very much in advance,

Regards,

Grégoire.
Re: How to write terminals/rules with same subset of characters [message #1495321 is a reply to message #1494778] Tue, 02 December 2014 05:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
What about keeping the int rule and introducing a data type rule for the octal one?

Octal: "o" INT;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to write terminals/rules with same subset of characters [message #1495350 is a reply to message #1495321] Tue, 02 December 2014 06:14 Go to previous messageGo to next message
Grégoire Avot is currently offline Grégoire AvotFriend
Messages: 7
Registered: December 2014
Junior Member
Hello Christian

Thank you for your reply.

I do not understand your reply: your proposed parser rule will accept "o 78", which is not correct.

Today the only solution I found is to implement a rule in the way you proposed, and use a Validator to check legal value. But in my mind I think there could be a purely grammatical solution.

Regards,

Grégoire.
Re: How to write terminals/rules with same subset of characters [message #1495359 is a reply to message #1495350] Tue, 02 December 2014 06:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi pure grammatical solutions are pain. Especially if you want to support binary and hexadecimal as well. But the same principal should be possible if you introduce terminals for 0+1 and 2 3 4 5 6 7 and 8 9 and datatype rules for INT and OCTAL (and maybe ID as well) but as said before this wil be pita

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to write terminals/rules with same subset of characters [message #1495519 is a reply to message #1495359] Tue, 02 December 2014 09:23 Go to previous message
Grégoire Avot is currently offline Grégoire AvotFriend
Messages: 7
Registered: December 2014
Junior Member
Thank you Christian for your feedback. You are right, next step is Hex + Binary. Furthermore, real example I have to handle is much more complex.
So I will continue to use Validator for these local check to avoid a too complex Xtext rules. But I keep in mind the purpose of Validator is to handle semantic, no grammar.
Regards,
Grégoire.
Previous Topic:simple xbase project causes antlr timeout
Next Topic:Internal "Literals" class not generated after grammar change
Goto Forum:
  


Current Time: Thu Apr 25 17:24:28 GMT 2024

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

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

Back to the top