Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext problem for definition terminal string
xtext problem for definition terminal string [message #669958] Thu, 12 May 2011 07:51 Go to next message
tian1qi  is currently offline tian1qi Friend
Messages: 21
Registered: May 2011
Junior Member
hi!
i'm a new in xtext,and i have a big problem that i have no idear how i can resolve it Mad
i have a grammar in which i define some rules. for exemple: i have a rule name "Clock_fonct"
Clock_fonct returns Clock_fonct:
{Clock_fonct}
'CLOCK'
name = EString
operateur=Operateur_Relationnel
'.'clock_attri=[AttributsDelegation]
;
and i define EString like terminal rule:
EString returns ecore::EString: ID ;

[Updated on: Thu, 12 May 2011 07:55]

Report message to a moderator

Re: xtext problem for definition terminal string [message #669960 is a reply to message #669958] Thu, 12 May 2011 07:57 Go to previous messageGo to next message
tian1qi  is currently offline tian1qi Friend
Messages: 21
Registered: May 2011
Junior Member
terminal ID returns ecore::EString: '^'?('a'..'z'|'A'..'Z'|'_'|':'|'$'|'`'|'#'|'é'|'è'|'ç'|'ù'|'à'|'ô'|"'"|'"'|'%'|'-') ('a'..'z'|'A'..'Z'|'_'|':'|'$'|'#'|'é'|'è'|'ç'|'ù'|'ê'|'à'|'ô'|'-'|'%'|'='|'<'|' '|'0'..'9'|'`')*; 

"Operateur_relationnel" is the type enum:
enum Operateur_Relationnel returns Operateur_Relationnel:
	egal='=' |presque_egal='<>' |different='/=' |inferieur='<' |inferieur_egal='<=' |superieur='>' |superieur_egal='>='
;

now the problem comes, the type "EString" can take all the carecters includes the operator, but if i define all the operator in the "EString", my grammar can't take the type enum "Operateur_Relationnel" as a enum but a "Estring", which is normal for it,i want to know if there is some way to resolve this problem, i tried lots of things but none if them works, can anyone helps me please?

[Updated on: Thu, 12 May 2011 07:59]

Report message to a moderator

Re: xtext problem for definition terminal string [message #669965 is a reply to message #669960] Thu, 12 May 2011 08:22 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
please see my reply to the post by Ed (forwarded to this forum). For any normal grammar, your terminal definition is unusable. Do you really want an ID to start with quotation marks?? Use datatype rules.

What you might want is something like the clocks name to be MyString and

MyString: STRING|MyId

(with the regular STRING definition and a sensible MyId definition)

Alex

[Updated on: Thu, 12 May 2011 08:24]

Report message to a moderator

Re: xtext problem for definition terminal string [message #670033 is a reply to message #669965] Thu, 12 May 2011 13:22 Go to previous messageGo to next message
tian1qi  is currently offline tian1qi Friend
Messages: 21
Registered: May 2011
Junior Member
i tried the way you told like:
EString returns ecore::EString:
	ID  ;  	
EStringNewID returns ecore::EString:
 (ID|ANY_OTHER)	;
terminal ID returns ecore::EString: ('a'..'z'|'A'..'Z'|'_'|'-'|':'|'#') ('a'..'z'|'A'..'Z'|'_'|':'|' '|'0'..'9')*;  
terminal ANY_OTHER: .;

and in some rule i call the diffrent type string:
Modele returns Modele: 
	{Modele}
	'[OBJET'identifiant=EString']' 
		'<NATURE>'('='|'^') nature=type_model
		'<.NOM>''=' nom=EString   
		('<.LIBELLE>''=' libelle=EStringNewID)?  
		'<.CLASSES>''{' (classes+=Classe)* '}'  
	;

but after that some fonction in my grammar doesn't work, did i do something wrong?
Re: xtext problem for definition terminal string [message #670037 is a reply to message #670033] Thu, 12 May 2011 13:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
What exactly do you mean by "some fonction" in my grammar? How can
people help you if you don't fully describe your problem?

(Note that "I" is always spelled with an upper case letter, never as
just "i". You might alway want to run a spell checker on your posts.)

tian1qi wrote:
> i tried the way you told like:
> EString returns ecore::EString:
> ID ;
> EStringNewID returns ecore::EString:
> (ID|ANY_OTHER) ;
> terminal ID returns ecore::EString:
> ('a'..'z'|'A'..'Z'|'_'|'-'|':'|'#')
> ('a'..'z'|'A'..'Z'|'_'|':'|' '|'0'..'9')*; terminal ANY_OTHER: .;
>
> and in some rule i call the diffrent type string:
> Modele returns Modele: {Modele}
> '[OBJET'identifiant=EString']' '<NATURE>'('='|'^')
> nature=type_model
> '<.NOM>''=' nom=EString ('<.LIBELLE>''='
> libelle=EStringNewID)? '<.CLASSES>''{' (classes+=Classe)*
> '}' ;
> but after that some fonction in my grammar doesn't work, did
> i do something wrong?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: xtext problem for definition terminal string [message #670038 is a reply to message #669958] Thu, 12 May 2011 13:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Maybe it's just me, but I'm not sure you've actually described what your
big problem is...

tian1qi wrote:
> hi!
> i'm a new in xtext,and i have a big problem that i have no
> idear how i can resolve it :x i have a grammar in which i define some
> rules. for exemple:
> i have a rule name "Clock_fonct"
> Clock_fonct returns Clock_fonct:
> {Clock_fonct}
> 'CLOCK'
> name = EString
> operateur=Operateur_Relationnel
> '.'clock_attri=[AttributsDelegation]
> ;
> and i define EString like terminal rule:
> EString returns ecore::EString: ID ; terminal ID returns
> ecore::EString: '^'?('a'..'z'|'A'..'Z'|'_'|':'|'$'|'`'|'#'|'é'|'è'|'ç'|'


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: xtext problem for definition terminal string [message #670057 is a reply to message #670038] Thu, 12 May 2011 14:13 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Please provide the full grammar and a sample model file which you expect to be parsed but which is not (please identify the location where the unexpected error occurs). You may also want to have a look at this blog post and the Xtext test infrastructure (search for a xtext junit plugin to add in your plugin dependencies) AbstractXtextTests in particular. Writing tests that ensure that a model can actually be parsed might be very helpful in your language development process

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: xtext problem for definition terminal string [message #670060 is a reply to message #670038] Thu, 12 May 2011 14:32 Go to previous messageGo to next message
tian1qi  is currently offline tian1qi Friend
Messages: 21
Registered: May 2011
Junior Member
I'm sorry, I didn't explain clearly.
this is parts of the grammar with the 2 type string:
Modele returns Modele: 
	{Modele}
	'[OBJET'identifiant=EString']' 
		'<NATURE>'('='|'^') nature=type_model
		'<.NOM>''=' nom=EStringNewID   
		('<.LIBELLE>''=' libelle=EString)?  
		'<.CLASSES>''{' (classes+=Classe)* '}'  
	;

Classe returns Classe: 
	('<.+>'|'<.'EInt'>')'{' 
		('<.NOM>''=' name=EString  & 
		(('<.LIBELLE>''=' libel=EStringNewID)? )  &  
		(('<.PERSISTANT>''='persistant?=EBooleanUPPER)?) &
 		(('<.MERE>''=' mere=[Classe])?  )   &
		('<.ATTRIBUTS>''{' attributs+=Attribut+ '}') )
    '}'	
    ;

enum type_model returns type_model:
	BOA_MODELE = '#BOA_MODELE';

Attribut returns Attribut:
	('<.+>'|'<.'EInt'>') '{'
		(('<.NOM>''=' name=EString) &		  
		(('<.LIBELLE>''=' libelle=EStringNewID)?) &
		(('<.CACHE>''=' cache ?=EBooleanUPPER)?) &
		('<.RESSOURCE>''=' la_ressource=[Ressource]) &  
		('<.NATURE>''=' nature=type_nature) &
		('<.VUE.' vues+=Vue_syntaxe_two)*	 &
		('<.VUE>''{'(vues_type_cle+=Vue_syntaxe_one)+ '}')? )
   '}'
   ;

when i apply the grammar to a file with extension .bdl
[OBJET #UTA_SDR]
 <NATURE> =#BOA_MODELE
 <.NOM> =#UTA_SDR
 <.LIBELLE> =Modèle Redondance  [color=red]]error mismatched input 'Mod' expecting RULE_ID[/color]
 <.CLASSES>{    [color=red]The feature 'attributs' of 'com.atosorigin.vigile.bdloc.modele_serv.impl.ClasseImpl@1348b49{platform:/resource/model/src_stsldas/prj-red/boa-red.bdl#//@loc_modeles.0/@classes.0}'
   with 0 values must have at least 1 values[/color]
--****************************************************************************
--                          Classe UTA_Etat_SDR                             --
--****************************************************************************
    <.1>{
      <.NOM> =#UTA_Etat_SDR
      <.LIBELLE> =service de redondance
      <.MERE> =#UTA_SYSTEME:#UTA_INTERFACE_CLIENT
      <.ATTRIBUTS>{
-- ------------------------------------------------------------------------------
-- attribut lu périodiquement pour connaître l'état de vie du serveur
-- ------------------------------------------------------------------------------
        <.1>{
           <.NOM> =AuditVg
           <.NATURE> =V
           <.RESSOURCE> =#UTA_SDR:#UTA_Etat_SDR:VAL_TEXTE
         }


in the "attribut" all the values are define, and the "libelle" it want the type ID

[Updated on: Thu, 12 May 2011 14:34]

Report message to a moderator

Re: xtext problem for definition terminal string [message #670248 is a reply to message #670057] Fri, 13 May 2011 08:10 Go to previous messageGo to next message
tian1qi  is currently offline tian1qi Friend
Messages: 21
Registered: May 2011
Junior Member
thank you alex, I added org.eclipse.xtext.junit dans denpendencies, but there is no difference when I genenred the grammar, did I miss something?
and about the blog, it's the same problem that I met, but I don't known where I have to add this class, I'm sorry if it's a question stupide,I'm a new in java...
Re: xtext problem for definition terminal string [message #670511 is a reply to message #670248] Sat, 14 May 2011 15:40 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

by adding the dependency tha class AbstractXtextTests becomes visible and can be used for junit tests for the grammar. Otherwise it has no influence on the behaviour of the language/generator.

Regarding your grammar, I will have a look at it next week.

Alex
Re: xtext problem for definition terminal string [message #670545 is a reply to message #670511] Sat, 14 May 2011 20:52 Go to previous messageGo to next message
tian1qi  is currently offline tian1qi Friend
Messages: 21
Registered: May 2011
Junior Member
Could I ask you another question alex? I created a new topic, but nobody answer me Sad
I have a presentation for my work this week, so I'm worried a lot about this Confused
my problem is:
I use the grammar to parser the file with extension .bdl, and when I import the directory,there are not only the extension .bdl but also many others, I would like only the extension .bdl appears, is there a way to load the file .bdl only?
thank you very much!
vivienne
Re: xtext problem for definition terminal string [message #670819 is a reply to message #670060] Sun, 15 May 2011 17:57 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I start to think that you really want no help. If I ask for a full grammar, I really want the full grammar. How do you expect me to help with a terminal rule problem, if you don't give me all their definitions. I don't know if you import the default terminals, what the hidden terminals are etc...

From an earlier snippet that is posted, I could imagine that one problem is the EStringNewID rule. It should rather be something like

EStringNewID hidden(WS): (ID|ANY_OTHER)+ ;

Your new ID is not an ID or a single other character but a sequence of them.

Alex
Re: xtext problem for definition terminal string [message #670910 is a reply to message #670819] Mon, 16 May 2011 07:33 Go to previous messageGo to next message
tian1qi  is currently offline tian1qi Friend
Messages: 21
Registered: May 2011
Junior Member
I'm rearly sorry, my grammar has almost 1000 lignes, that's why...
ok, I posted the grammar and a simple file .bdl with the error, thank you again alex
  • Attachment: grammar.txt
    (Size: 30.73KB, Downloaded 186 times)
  • Attachment: file_bdl.txt
    (Size: 1.28KB, Downloaded 172 times)
Re: xtext problem for definition terminal string [message #670932 is a reply to message #670910] Mon, 16 May 2011 09:18 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I have had a quick look at the grammar. You are aware that it is highly ambiguous and that without the backtracking options turned on, it is very likely that the model is instantiated incorrectly.

I find your current ID definition highly dangerous... you really want to allow white spaces in an ID??
The error you get in the sample model is caused by your ID-Definition. You allow dash/minus (-) as the first symbol of an ID but not later on, so how do you think the "ID" #UTA_MSG_STSGEN-MODEL-INTERFACE is to be accepted.
The minimal adaption to make more of the input being accepted is

//this rule is still no good idea as "-25" suddenly becomes an ID token
//do you really need "-" as the first character of an ID
terminal ID returns ecore::EString: ('a'..'z'|'A'..'Z'|'_'|'-'|':'|'#') ('a'..'z'|'A'..'Z'|'_'|':'|' '|'0'..'9'|'-'|"'")*;
EStringNewID returns ecore::EString: (ID|ANY_OTHER)+;

But again, a space in an ID will bring you only trouble. Further problems will be caused because single letters like "R", "D" are keywords in your grammar. Hence "Début" will not be accepted as an ID (or EStringNewID, as the first single D is not contained in the alternatives).

Getting the terminal and datatype rules straightened out will be quite an effort and it is much more than you can expect anyone in this forum to do for you. Here are some steps I find necessary.

-Remove the white space from the ID-terminal
-Split the WS-terminal in a SPACE and a OTHERWS terminal, so that spaces are not consumed along with tabs and new lines.
-make both white space terminals hidden by default (hidden(SPACE, OTHERWS)), but only hide tab/new-line white spaces in your EString datatype rules (regular space should be included in the alternatives)
--DatatypeRule hidden(OTHERWS): (WS|ID|ANYOTHER|...)+;
-go through the grammar and add all keywords ('R', 'D', '%' are also keywords) that should be allowed to the EString/NewID datatype rules

-write unit tests that check whether IDs and labels you expect to be accepted actually match the rules that should consume them.

Alex
Re: xtext problem for definition terminal string [message #671013 is a reply to message #670932] Mon, 16 May 2011 14:36 Go to previous message
tian1qi  is currently offline tian1qi Friend
Messages: 21
Registered: May 2011
Junior Member
thank you very much alex! Smile
It seems to work with my file BDL,now I have no problem with the keyword and string! Very Happy
But when I genere my grammar with the changment, thousands of warning appear at the console, I think it maybe: I defined twice all the keywords. I'm worried that it will destroy my grammar later...
warning(200): ../com.atosorigin.vigile.bdloc.dsl.ui/src-gen/com/atosorigin/vigile/bdloc/dsl/ui/contentassist/antlr/internal/InternalBDLoc.g:41499:1: Decision can match input such as "'MSQ'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../com.atosorigin.vigile.bdloc.dsl.ui/src-gen/com/atosorigin/vigile/bdloc/dsl/ui/contentassist/antlr/internal/InternalBDLoc.g:41499:1: Decision can match input such as "'CLA'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

Previous Topic:Recognising variable type, where multiple variables declared in one statement.
Next Topic:Generation : Could not find any exported element of type 'CompilationUnit' -> Slot 'compilationUn
Goto Forum:
  


Current Time: Thu Apr 25 01:49:12 GMT 2024

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

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

Back to the top