Input with multiple alternatives [message #1755945] |
Thu, 09 March 2017 13:16 |
Luiz Paulo Franz 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 #1755975 is a reply to message #1755947] |
Thu, 09 March 2017 17:49 |
Luiz Paulo Franz 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 #1755993 is a reply to message #1755987] |
Thu, 09 March 2017 20:17 |
Luiz Paulo Franz 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 #1756003 is a reply to message #1756001] |
Thu, 09 March 2017 21:27 |
|
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 #1756006 is a reply to message #1756005] |
Thu, 09 March 2017 22:12 |
|
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 |
Luiz Paulo Franz 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
|
|
|
Powered by
FUDForum. Page generated in 0.05726 seconds