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 11:30 Go to next message
Missing name Missing name is currently offline Missing name Missing name
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 06: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 12:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 4419
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
Re: extend xbase with a binary literal [message #708026 is a reply to message #707425] Tue, 02 August 2011 06:58 Go to previous message
Missing name Missing name is currently offline Missing name Missing name
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: Wed May 22 08:49:27 EDT 2013

Powered by FUDForum. Page generated in 0.11570 seconds