Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » extend xbase with a binary literal
extend xbase with a binary literal [message #707387] Mon, 01 August 2011 15:30 Go to next message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 4
Registered: August 2010
Junior Member
Hello,

I would like to add binary literals to my DSL that extends xbase. More specifically I would like to be able to type "0b1" (binary 1) "0b10" (binary 2) etc. This syntax is inspired from Python.


For this I followed Jan Koehnlein's very helpful blog post (extending xbase).


and added these rules to my grammar:

XLiteral returns XExpression:
XClosure |
XBooleanLiteral |
...
DecimalLiteral |
BinaryLiteral;


BinaryLiteral:
'0b'binary=ZerosOrOnes;

ZerosOrOnes : ('0'|'1')('0'|'1')*;


When I try this "0b1" and "0b0" are recognized

but I get the error message below for "0b100" :

no viable alternative at input '100'

Any info would be greatly appreciated.
Arye.

[Updated on: Tue, 02 August 2011 10:59]

Report message to a moderator

Re: extend xbase with a binary literal [message #707425 is a reply to message #707387] Mon, 01 August 2011 16:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the problem is that 100 is recognized as int and not as a 1 and 0 and 0
since the lexer is greedy.

the easiest would be to add the ob into the (now terminal) rule
and registerening a valueconverter to cut it off.

terminal ZerosOrOnes : '0' 'b' ('0'|'1')('0'|'1')*;

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: extend xbase with a binary literal [message #708026 is a reply to message #707425] Tue, 02 August 2011 10:58 Go to previous message
Missing name Missing name is currently offline Missing name Missing nameFriend
Messages: 4
Registered: August 2010
Junior Member
Hello,

Thanks a lot for your answer. Pb solved!

Regards.
Arye.
Previous Topic:UnsupportedOperationException: getEObjectURI
Next Topic:Xtext dsl file extensions
Goto Forum:
  


Current Time: Fri Apr 19 10:52:17 GMT 2024

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

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

Back to the top