Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Input with multiple alternatives
Input with multiple alternatives [message #1755945] Thu, 09 March 2017 13:16 Go to next message
Luiz Paulo Franz is currently offline Luiz Paulo FranzFriend
Messages: 19
Registered: November 2016
Junior Member
Hello guys.

I have the following problem in my grammar:

This rule overlaps the terminal rule ID, native from Xtext.
terminal FREESTRING:  (('\\')?('a'..'z'|'A'..'Z'|'0'..'9'|','))*;

As a result, my log shows:

Decision can match input such as "RULE_FREESTRING" using multiple alternatives: 1, 2

And now I need to use the ID rule in another rules, so then, the parser can't recognize the input as a ID, as follows:
Env: 'ENV' name=ID ':' value=NL '.';

I've tried to use syntatic predicates, but it does not work:
Env: ('ENV' => name=ID) ':' value=NL '.';

How can I solve this problem?

Thanks in advance!

[Updated on: Thu, 09 March 2017 17:39]

Report message to a moderator

Re: Input with multiple alternatives [message #1755947 is a reply to message #1755945] Thu, 09 March 2017 13:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Hi,

you might have a look at the concepts of
- terminal fragments
- datatype rules
- validation

can you please share a minimal complete grammar + sample model


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Thu, 09 March 2017 13:48]

Report message to a moderator

Re: Input with multiple alternatives [message #1755975 is a reply to message #1755947] Thu, 09 March 2017 17:49 Go to previous messageGo to next message
Luiz Paulo Franz is currently offline Luiz Paulo FranzFriend
Messages: 19
Registered: November 2016
Junior Member
Hi, I'll share my entire grammar:


And a sample is:
The system SHALL save all the data;
ENV size: 16Gb.
ENV maxFiles: 32.


So, the problem is in the declaration of these "ENV" variables, the name of these variables is not recognized as ID, and I think that this occurs becose of the rule FREESTRING, wich overlaps the ID rule.

Thanks.

[Updated on: Thu, 09 March 2017 21:43]

Report message to a moderator

Re: Input with multiple alternatives [message #1755982 is a reply to message #1755975] Thu, 09 March 2017 19:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
well if i write minimal i do that with a reason Sad

and what you try to do is the very hardest thing to do in xtext.

and there a lot very strange concepts in your grammar.
what separates a String primitive from the next one?

Requirements:
	requirements+=Requirement+;

Requirement:
	(root+=Sentence)+ ';' ;
	
Sentence:
	(root+=StringValue)+ & '.'?;

terminal FREESTRING:  (('\\')?('a'..'z'|'A'..'Z'|'0'..'9'|','))*;

NL hidden(WS): FREESTRING ( FREESTRING)*;

StringValue:value=NL;


this problem is there even if you generalize FREESTRING and ID to a common superrule e.g. by loosenin ID

for me that looks very hard to solve without a custom lexer that is more intelligent and knows what is a FREESTRING and what is a ID


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1755987 is a reply to message #1755982] Thu, 09 March 2017 19:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
=> I'd first use ID only and solve the grammar problem
And then have a look at the Lexing problem


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1755993 is a reply to message #1755987] Thu, 09 March 2017 20:17 Go to previous messageGo to next message
Luiz Paulo Franz is currently offline Luiz Paulo FranzFriend
Messages: 19
Registered: November 2016
Junior Member
Hi, thanks for answer.

Yes, it's a very strange grammar, and I'm just implementing it, I did not created this language. All of this freedom in this grammar has complicated my work many times. Answering your question, what separates a primitive String from the next one is some key word (like SHALL), just it, so I have parts in Natural Language inside of this language (Relax Language).

Is a strange concept, but the language is in this way. And this is the way how I could get do it, I don't know if is the better one.

So, in this case, predicates will not work?
Re: Input with multiple alternatives [message #1755994 is a reply to message #1755993] Thu, 09 March 2017 20:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
No I mean

Bla bla bla

One sentence or three sentences


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1755995 is a reply to message #1755994] Thu, 09 March 2017 20:29 Go to previous messageGo to next message
Luiz Paulo Franz is currently offline Luiz Paulo FranzFriend
Messages: 19
Registered: November 2016
Junior Member
Bla bla bla will be trated as one sentence.
Re: Input with multiple alternatives [message #1755996 is a reply to message #1755995] Thu, 09 March 2017 20:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
So what separates two sentences?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1755998 is a reply to message #1755996] Thu, 09 March 2017 20:53 Go to previous messageGo to next message
Luiz Paulo Franz is currently offline Luiz Paulo FranzFriend
Messages: 19
Registered: November 2016
Junior Member
The dot charactere "."

Sentence:
	(root+=General)+ & '.'?;
Re: Input with multiple alternatives [message #1755999 is a reply to message #1755998] Thu, 09 March 2017 20:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Why the &

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1756000 is a reply to message #1755999] Thu, 09 March 2017 20:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
And why is the dot optional

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1756001 is a reply to message #1756000] Thu, 09 March 2017 21:10 Go to previous messageGo to next message
Luiz Paulo Franz is currently offline Luiz Paulo FranzFriend
Messages: 19
Registered: November 2016
Junior Member
The & charactere was added, because without it, an error occurs:

5962 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems running workflow br.edu.unipampa.lesa.relaxEditor.GenerateRelax:
[ERROR]: GeneratorException: (Element: -UNKNOWN-; Reported by: XtextGenerator)

...

Caused by: java.io.FileNotFoundException: /home/paulo/workspaces/dsl/br.edu.unipampa.lesa.relaxEditor/../br.edu.unipampa.lesa.relaxEditor/src-gen/br/edu/unipampa/lesa/relaxEditor/parser/antlr/internal/InternalRelaxLexer.java (Arquivo ou diretório não encontrado)


I do not know why it happend.

And dot is optional, because one requirement may contain just one sentence.
Re: Input with multiple alternatives [message #1756003 is a reply to message #1756001] Thu, 09 March 2017 21:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
The system SHALL save all the data;

how should that be parseable?

after the Primitive there must be an until ?


Requirements:
	(requirements+=Requirement ';')+;
	
	Properties:
	property=Env|Mon|Dep|Rel
;

Env: ('ENV' => name=FREESTRING) ':' value=NL '.';
Mon: ('MON' => name=FREESTRING) ':' value=NL '.';
Rel: 'REL:' mon=[Mon]'-'env=[Env] '.';
Dep: 'DEP:' NL '.';

Requirement:
	(root+=General ('.' root+=General)* '.'?)  (properties+=Properties)*;
	
//declaramos tipos ainda nao existentes
terminal BOOLEAN returns ecore::EBoolean:'true'|'false';
//a primeira parte eh o escape
terminal FREESTRING:  (('\\')?('a'..'z'|'A'..'Z'|'0'..'9'|','))*;

//Natural Language, trechos que serao em LN
NL hidden(WS): FREESTRING ( FREESTRING)*;

//Essa eh a regra mae da gramatica, ja tratando a recursividade a esquerda 
General:
	rest = Rest =>({UntilOperator.left=current}('UNTIL'|'until') right=General)*;

//aqui se encontram as demais regras da gramatica
Rest:
	rule = Primitive|ShallOperator|MayOperator|EventuallyOperator|BeforeOperator|AfterOperator|InOperator|AsCloseOperator|AsOperator
;
// tipos primitivos, como boleanos (previstos na gramatica original) e os trechos em LN
Primitive:
	BooleanValue | StringValue
;
//novamente os operadores primitivos
BooleanValue:value=BOOLEAN;
StringValue:value=NL;

//aqui sao tratados todos os operandos (exceto o UNTIL) 
ShallOperator:
	('SHALL'|'shall') elements=General;

MayOperator:
	("MAY"|'may') action1=General ('OR' 'MAY'|'or' 'may') action2=General;

EventuallyOperator:
	('EVENTUALLY'|'eventually') element=General;

BeforeOperator:
	('BEFORE'|'before') event=NL;// other=General;

AfterOperator:
	('AFTER'|'after') event=NL;// other=General;

InOperator:
	('IN'|'in') t=NL; //other=General;
	
//Frquencia ou Quantidade f or q
AsCloseOperator:
	('AS' 'CLOSE' 'AS' 'POSSIBLE' 'TO'|'as' 'close' 'as' 'possible' 'to') ForQ=NL //other=General 
;
//quebramos todos os operadores AS
AsOperator:
	AsEarlyOperator|AsLateOperator|AsManyOperator|AsFewOperator;

AsEarlyOperator:
	('AS' 'EARLY' 'AS' 'POSSIBLE'|'as' 'early' 'as' 'possible') value=General;
AsLateOperator:
	('AS' 'LATE' 'AS' 'POSSIBLE'|'as' 'late' 'as' 'possible') value=General;
AsManyOperator:
	('AS' 'MANY'|'as' 'many') (element=NL)? ('AS' 'POSSIBLE'|'as' 'possible') value=General;
AsFewOperator:
	('AS' 'FEW'|'as' 'few') (element=NL)? ('AS' 'POSSIBLE'|'as' 'possible') value=General;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1756004 is a reply to message #1756003] Thu, 09 March 2017 21:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
Which again. The question

What goes in which sentence


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1756005 is a reply to message #1756004] Thu, 09 March 2017 21:40 Go to previous messageGo to next message
Luiz Paulo Franz is currently offline Luiz Paulo FranzFriend
Messages: 19
Registered: November 2016
Junior Member
Ok, Christian thanks for your time, this is a strange grammar, and I really don't know how to implement all os these strange things in Xtext.

If you want to see the original grammar, here is https://www.eclipse.org/forums/index.php?t=getfile&id=27544&

Thanks anyway.
Re: Input with multiple alternatives [message #1756006 is a reply to message #1756005] Thu, 09 March 2017 22:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
thus this original grammar have a name?

maybe you can try something like this

Requirements:
(requirements+=Requirement ';')+ (properties+=Properties)*;

Properties:
property=Env|Mon|Dep|Rel
;

Env: ('ENV' => name=FREESTRING) ':' value=NL '.';
Mon: ('MON' => name=FREESTRING) ':' value=NL '.';
Rel: 'REL:' mon=[Mon]'-'env=[Env] '.';
Dep: 'DEP:' x=NL '.';

Requirement:
(root+=General ('.' root+=General)* '.'?) ;
//declaramos tipos ainda nao existentes
terminal BOOLEAN returns ecore::EBoolean:'true'|'false';
//a primeira parte eh o escape

//Natural Language, trechos que serao em LN
NL hidden(WS): FREESTRING+;

//Essa eh a regra mae da gramatica, ja tratando a recursividade a esquerda
General:
rest = Rest =>({UntilOperator.left=current}('UNTIL'|'until') right=Rest)*;

//aqui se encontram as demais regras da gramatica
Rest:
(=>primitives+=Primitive* (shall=ShallOperator|may=MayOperator)?)
;
// tipos primitivos, como boleanos (previstos na gramatica original) e os trechos em LN
Primitive:
BooleanValue | StringValue
;
//novamente os operadores primitivos
BooleanValue:value=BOOLEAN;
StringValue:value=FREESTRING;

terminal FREESTRING:
(('\\')? ('a'..'z' | 'A'..'Z' | '0'..'9' | ','))*;

//aqui sao tratados todos os operandos (exceto o UNTIL)
ShallOperator:
=>('SHALL'|'shall') elements=General;

MayOperator:
=>("MAY"|'may') action1=General ('OR' 'MAY'|'or' 'may') action2=General;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Input with multiple alternatives [message #1756007 is a reply to message #1756006] Thu, 09 March 2017 22:22 Go to previous message
Luiz Paulo Franz is currently offline Luiz Paulo FranzFriend
Messages: 19
Registered: November 2016
Junior Member
Thanks, I'll try it.

This grammar defines the Relax Language, wich is a language for requirements specification for Self-Adaptive Systems, so the grammars and all of this, is not my domain area. It is a new language, without tool supporting, the authors just have defined the grammar and semantics. It is an academic work yet.

[Updated on: Thu, 09 March 2017 22:44]

Report message to a moderator

Previous Topic:Generate a final product for my DSL
Next Topic:Overloaded method determination
Goto Forum:
  


Current Time: Fri Dec 06 18:14:13 GMT 2024

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

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

Back to the top