Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext recursive statement(Xtext recursive statement)
Xtext recursive statement [message #1732064] Thu, 12 May 2016 11:25 Go to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
Hi,

I have a rule:
OpenDecl: (exp+=Expression (','? exp+=Expression)*);

and expression rule:

Expression:
LogicalOr
;
LogicalOr returns Expression:
BitwiseOr ({LogicalOr.left=current} '||' right=BitwiseOr)*
;
BitwiseOr returns Expression:
LogicalAnd ({BitwiseOr.left=current} '|' right=LogicalAnd)*
;
LogicalAnd returns Expression:
BitwiseAnd ({LogicalAnd.left=current} '&&' right=BitwiseAnd)*
;
BitwiseAnd returns Expression:
Equivalency ({BitwiseAnd.left=current} '&' right=Equivalency)*
;
Equivalency returns Expression:
Relational ({Equivalency.left=current} ('=='|'!='|'=') right=Relational)*
;
Relational returns Expression:
PlusMinus ({Relational.left=current} ('>='|'<='|'>'|'<') right=PlusMinus)*
;
PlusMinus returns Expression:
DivMult ({PlusMinus.left=current} ('+'|'-') right=DivMult)*
;
DivMult returns Expression:
LogicalNot ({DivMult.left=current} ('/'|'*') right=LogicalNot)*
;
LogicalNot returns Expression:
OnesComplement ({LogicalNot.left=current} '!' right=OnesComplement)*
;
OnesComplement returns Expression:
Exponentiation ({OnesComplement.left=current} ('~') right=Exponentiation)*
;
Exponentiation returns Expression:
Concatenation ({Exponentialtion.left=current} '^' right=Concatenation)*
;
Concatenation returns Expression:
Primary ({Concatenation.left=current} '##' right=Primary)*
;
Primary returns Expression:
NUMBER|STRING|ID
;

When I am using any text at beginning of the line it is not showing error.

index.php/fa/25883/0/

I understand that the rule OpenDecl is allowing to add text freely but how can I restrict it not allow the text without a keyword of any rule?

[Updated on: Mon, 16 May 2016 09:56]

Report message to a moderator

Re: Xtext recursive statement [message #1732065 is a reply to message #1732064] Thu, 12 May 2016 11:26 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
But I can have expressions like this:

a=b ,test=test1+test2 ...
Re: Xtext recursive statement [message #1732069 is a reply to message #1732065] Thu, 12 May 2016 12:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
hi i do not understand your question. have a look at your Primary rule.
it exactly allows this


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732071 is a reply to message #1732069] Thu, 12 May 2016 12:49 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
Yes. My Primary rule allows but, can I impose any condition to not allow ID but to allow ID = ID. I mean a line contains only ID (not expression) I need to show error.
Re: Xtext recursive statement [message #1732075 is a reply to message #1732071] Thu, 12 May 2016 12:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
is this a question on the parser? (the grammar)
or the validator (adding such constrains that go beyond the grammar)?
simply adding a check method to the validator class and checking if all OpenDecls expr are actually a Equivalency would do the job


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732078 is a reply to message #1732075] Thu, 12 May 2016 13:05 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
My question is related parser not validator.

Suppose a line contains :

abcdef //should throw an error

I need a rule that the text should be allowed if it is preceded by a keyword or itself an expression like abcdef=1.
Re: Xtext recursive statement [message #1732079 is a reply to message #1732078] Thu, 12 May 2016 13:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
then you need another

Equivalency2 returns Expression:
Relational ({Equivalency.left=current} ('=='|'!='|'=') right=Relational)+
;


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732081 is a reply to message #1732079] Thu, 12 May 2016 13:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
and use this one instead of

OpenDecl: (exp+=Equivalency2 (','? exp+=Equivalency2)*);


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732082 is a reply to message #1732081] Thu, 12 May 2016 13:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
p.s.:
but anyway: you dont have and should not check EVERYTHING in the grammar


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732107 is a reply to message #1732082] Thu, 12 May 2016 16:11 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
It's not working .
Re: Xtext recursive statement [message #1732108 is a reply to message #1732107] Thu, 12 May 2016 16:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
What do you mean by not working

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732110 is a reply to message #1732108] Thu, 12 May 2016 16:19 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
I have used
OpenDecl: (exp+=Equivalency2 (','? exp+=Equivalency2)*);

and

Equivalency2 returns Expression:
Relational ({Equivalency.left=current} ('=='|'!='|'=') right=Relational)+
;

It is throwing error. Maybe something going wrong with my grammar that's it is not working.

Re: Xtext recursive statement [message #1732111 is a reply to message #1732110] Thu, 12 May 2016 16:23 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
How to know which line causing error?

I added
parserGenerator = {
options = {
ignoreCase = true
}
debugGrammar = true
}
but no difference in error in console.

[Updated on: Thu, 12 May 2016 17:22]

Report message to a moderator

Re: Xtext recursive statement [message #1732112 is a reply to message #1732110] Thu, 12 May 2016 16:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
please share a complete grammar i can copy and paste

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732113 is a reply to message #1732112] Thu, 12 May 2016 16:30 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
I have attached in the previous message
Re: Xtext recursive statement [message #1732114 is a reply to message #1732113] Thu, 12 May 2016 16:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
the grammar was working before? reeally?

your grammar with all the optionality simply is ambigous. ia it an existing language you are building for? if not: get rid of the optional commas etc
and you have stuff in that is hard to check on parser level. thus doing the equivalency check in the validator would have been 1000000 times easier.

especially your primary is expremely bogus. nearly all stuff in it is ambigous.
it dont get why you always do the strange thing for (something.)

you can try to solve it with predicates. but i dont know if the resulting ast will be what you are looking fo

OpenDecl: (exp+=Equivalency2 (=>','? exp+=Equivalency2)*);


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732116 is a reply to message #1732114] Thu, 12 May 2016 16:56 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
I am building grammar for existing language which it allows so many things which is not possible in java

[Updated on: Thu, 12 May 2016 17:21]

Report message to a moderator

Re: Xtext recursive statement [message #1732117 is a reply to message #1732116] Thu, 12 May 2016 17:00 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
That attachment contains all the possible statements for the existing language. Can you please tell me Am I going in wrong direction?
Re: Xtext recursive statement [message #1732118 is a reply to message #1732117] Thu, 12 May 2016 17:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
sry i have not the time to digg that deep to get rid of all warnings.
is there any exisiting antlr grammar for jpl?

if i use
OpenDecl: (exp+=Expression (=>','? exp+=Expression)*);

the grammar compliles fine.
so what about using a validator ?!?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732119 is a reply to message #1732118] Thu, 12 May 2016 17:22 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
Thank you.
Re: Xtext recursive statement [message #1732121 is a reply to message #1732119] Thu, 12 May 2016 17:26 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
I didn't use validator. If I want to use validator I can written validation for a rule right? But how can I check a line which contains text
Re: Xtext recursive statement [message #1732123 is a reply to message #1732121] Thu, 12 May 2016 17:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
hi i dont understand this questions.

in the validator you validate the ast.

in your case you want to validate a OpenDecl.

thus you would have a

@Check
def void checkOpenDecl(OpenDecl decl) {
.... // validate if the given decl in correct here
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732135 is a reply to message #1732116] Thu, 12 May 2016 18:38 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6511
Registered: July 2009
Senior Member
Hi

If it is an existing language, there is almost certainly an existing
grammar which should not be too hard to translate to Xtext. Look for it
/ buy it.

Regards

Ed Willink

On 12/05/2016 17:56, RamaRao Nandamuri wrote:
> I am building grammar for existing language which it allows so many
> things which is not possible in java
Re: Xtext recursive statement [message #1732289 is a reply to message #1732123] Sun, 15 May 2016 04:35 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
Hi,

I am using validator to get the value entered for OpenDecl like
grammar:
OpenDecl: (openDecl+=Expression (','? openDecl+=Expression)*);

Validator Code:
@Check
def void checkOpenDecl(OpenDecl decl) {
println("OPen Declaration Test :::::::::::::::"+decl.openDecl)
}

the output I got:
OPen Declaration Test :::::::::::::::[com.prolifics.jpl.jPLEditor.impl.OneDeclImpl@1d03261 (number: null, jplString: null) (isEmpty: false, isArray: false, maxOccurs: null, isRange: false, range: null, hasSize: false, varsize: null, str: null, isArrayVar: false, hasExp: false, isString: false)]


I tried a lot but no luck. Could you please tell me how to get the value entered in editor?
Re: Xtext recursive statement [message #1732290 is a reply to message #1732289] Sun, 15 May 2016 06:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
Nodemodelutil will give you access to the nodes which you can ask for its text.
But as I said you want to inspect the ast by having a look at the open decl s expr parts


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext recursive statement [message #1732291 is a reply to message #1732290] Sun, 15 May 2016 07:19 Go to previous messageGo to next message
RamaRao Nandamuri is currently offline RamaRao NandamuriFriend
Messages: 120
Registered: April 2016
Senior Member
I tried this:

@Check
def void checkOpenDecl(OneDecl decl) {
val node = NodeModelUtils.findActualNodeFor(decl)
for (n : node.asTreeIterable) {
val ge = n.grammarElement
println("Grammar Element JPL ::::::::::")
}
}

for the grammar
OneDecl:{OneDecl} name=JPLID (
(isEmpty ?= '(' ')')? &
(isArray ?= '[' (maxOccurs+=NUMBER) ']')? &
(isRange ?= '[' (range+=RANGE) ']')? &
(hasSize ?= '(' (varsize+=NUMBER|jplId+=JPLID|str+=STRING) (',' (varsize+=NUMBER|jplId+=JPLID|str+=STRING))* ')')? &
(isArrayVar ?= '[' (jplId+=JPLID) ']')? &
(hasExp ?= '[' (exp+=Expression) ']')? &
(isString ?= '(' (str+=STRING) ')')?
)
;

But will it give keyword preceded by the above grammar?

Example: float a(10)

a(10) works based on above grammar rule. How can I check a(10) is preceded by any keyword or not?
Re: Xtext recursive statement [message #1732294 is a reply to message #1732291] Sun, 15 May 2016 07:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13194
Registered: July 2009
Senior Member
What is the grammar around that float thing. Btw you usually don't use the node model for such a check. All relevant information is in the ast if the grammar is properly crafted.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to write xtext grammar for if statement
Next Topic:name auto generation
Goto Forum:
  


Current Time: Mon Nov 18 14:36:28 GMT 2019

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

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

Back to the top