Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Interger declared as keyword cannot be reused in other rules.(Interger declared as keyword cannot be reused in other rules.)
Interger declared as keyword cannot be reused in other rules. [message #1729753] Mon, 18 April 2016 16:35 Go to next message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
Hi all,

I declared 16 and 32 to be used together with a rule named code.
when i have another rule text, it is declared to be used with integer.
but it return errors when i typed 16 or 32 after rule text. Any idea how to fix it? attached is the snip shot of error result.

Here is my rules.

syntax used to reproduce:

.code 32 //ok
.align 0 //ok
.align 32 //error
.align 16 //error
.align 77 //ok
************************************************************
Model:
elements+=ARMInstr*
;

ARMInstr:
Ccode
;

Ccode:
ARM_MACHINE_DIRECTIVES_align (int=INT | hex=HEX)?
| ARM_Machine_Directives_code (arm?='16' | thumb?='32')
;

ARM_MACHINE_DIRECTIVES_align:
dot?=('.')code?='align'
;

ARM_Machine_Directives_code:
dot?=('.') code?= 'code'
;

terminal HEX:
('='|'#')?('0x' | '&')(('0'..'9')|('a'..'f') | ('A'..'F'))*
;

***********************************************************

Thank you =)
Re: Interger declared as keyword cannot be reused in other rules. [message #1729754 is a reply to message #1729753] Mon, 18 April 2016 16:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13220
Registered: July 2009
Senior Member
hi the lexer is context free. thus 16 and 32 will always be lexed as keywords and not as int

you have to introduce a special parser rule = datatype rule like

MyINT : INT | '16' | '32';

and use that one insteadof INT

you may additionally change the returntype of MyINT to be ecore::EInt + use a value converter to do the conversion
if needed

ARM_MACHINE_DIRECTIVES_align (int=MyINT | hex=HEX)?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Interger declared as keyword cannot be reused in other rules. [message #1729758 is a reply to message #1729754] Mon, 18 April 2016 17:03 Go to previous message
Jia Poh Kow is currently offline Jia Poh KowFriend
Messages: 25
Registered: November 2015
Junior Member
It works well now! Laughing
Thank you Christian!
Previous Topic:Disable formatting feature
Next Topic:How to call AST contents
Goto Forum:
  


Current Time: Fri Nov 22 10:54:50 GMT 2019

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

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

Back to the top