Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » a problem in syntactic predicate
a problem in syntactic predicate [message #721197] Thu, 01 September 2011 07:18 Go to next message
lulu  is currently offline lulu Friend
Messages: 19
Registered: August 2011
Junior Member
Hi, All,

There has a problem while practice syntactic predicate.

xtext grammar like this:
----- begin -------
a:
=> e ';'
| e '.'
;

e:
=> '(' ID ')' ID //type cast
| '(' ID ')' //nest expression
| ID
;

terminal ID: ('a'..'z')+;
----------- end ----------

while run as eclipse application, it occur some mistake in .dsl file.


But after I add brace in syntactic predicate. grammar show as follow:
----- begin -------
a:
=> ( e ';' )
| e '.'
;

e:
=> ( '(' ID ')' ID ) //type cast
| '(' ID ')' //nest expression
| ID
;

terminal ID: ('a'..'z')+;
----------- end ----------

It is run correctly which can match follow pattern:
test.
(test).
(test)test.
test;
(test);
(test)test;

I did not find any detail description in syntactic predicate about Xtext.

Thanks.
Re: a problem in syntactic predicate [message #721202 is a reply to message #721197] Thu, 01 September 2011 07:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

what about http://www.eclipse.org/Xtext/documentation/2_0_0/020-grammar-language.php#antlr_errors

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: a problem in syntactic predicate [message #721216 is a reply to message #721202] Thu, 01 September 2011 07:54 Go to previous messageGo to next message
lulu  is currently offline lulu Friend
Messages: 19
Registered: August 2011
Junior Member
Thanks to Christian.

I already read this part before practice it.

I dont know why this problem occurs?
Re: a problem in syntactic predicate [message #721338 is a reply to message #721216] Thu, 01 September 2011 14:05 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
The documentation needs additional explanation about what a syntactic predicate is and how to use it. The current explanation is confusing. The grammar doesn't appear to match the language snippet. The grammar defines a 'then' key word but the sample code doesn't include the then. The explanation for choosing else basically says choose this 'else' not that 'else'. However, the grammar only has one else defined. Where does the other else come from and how does the syntactic predicate tell me which one to pick?
Re: a problem in syntactic predicate [message #721345 is a reply to message #721338] Thu, 01 September 2011 14:22 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the else is optional in the grammar, so the question is whether the else of the inner if or that of the outer if is to be matched. The syntactic predicate says, if you can match, do so immediately (and do not look for another branch of the tree, that could match as well). For that reason the inner if wins.

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: a problem in syntactic predicate [message #721443 is a reply to message #721345] Thu, 01 September 2011 19:08 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
What would the grammar look like if you wanted to match the outer if instead of the inner if.
Re: a problem in syntactic predicate [message #721521 is a reply to message #721338] Fri, 02 September 2011 01:25 Go to previous messageGo to next message
lulu  is currently offline lulu Friend
Messages: 19
Registered: August 2011
Junior Member
dpwegener wrote on Thu, 01 September 2011 10:05
The documentation needs additional explanation about what a syntactic predicate is and how to use it. The current explanation is confusing. The grammar doesn't appear to match the language snippet. The grammar defines a 'then' key word but the sample code doesn't include the then. The explanation for choosing else basically says choose this 'else' not that 'else'. However, the grammar only has one else defined. Where does the other else come from and how does the syntactic predicate tell me which one to pick?



I totally agree with this view.
I am confuse that whether the syntactic predicate is different from that in ANTLR?
And the grammar is from the ANTLR reference book.

Re: a problem in syntactic predicate [message #721522 is a reply to message #721345] Fri, 02 September 2011 01:30 Go to previous messageGo to next message
lulu  is currently offline lulu Friend
Messages: 19
Registered: August 2011
Junior Member
Alexander Nittka wrote on Thu, 01 September 2011 10:22
Hi,

the else is optional in the grammar, so the question is whether the else of the inner if or that of the outer if is to be matched. The syntactic predicate says, if you can match, do so immediately (and do not look for another branch of the tree, that could match as well). For that reason the inner if wins.

Alex



But in xtext 2.0.0: syntactic predicate can use in ambiguous situation.
Re: a problem in syntactic predicate [message #721564 is a reply to message #721443] Fri, 02 September 2011 06:34 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Quote:
What would the grammar look like if you wanted to match the outer if instead of the inner if.


I may be wrong, but I think that you cannot express that within the grammar. You would need to adapt the model instantiation yourself.

Alex
Re: a problem in syntactic predicate [message #721650 is a reply to message #721564] Fri, 02 September 2011 12:31 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
please file a bugzilla regarding the documentation improvements.
Re: a problem in syntactic predicate [message #721750 is a reply to message #721564] Fri, 02 September 2011 17:28 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
On 09/02/2011 01:34 AM, Alexander Nittka wrote:
> Quote:
>> What would the grammar look like if you wanted to match the outer if
>> instead of the inner if.
>
>
> I may be wrong, but I think that you cannot express that within the
> grammar. You would need to adapt the model instantiation yourself.
>
> Alex
That would seem to indicate that the syntactic predicate isn't needed.
If the grammar can only be interpreted in one way, why would you need to
add the =>? This is part of the reason that syntactic predicate is so
confusing.

I'm not an expert on writing a language and am trying to learn more how
using Xtext etc. In looking through the XBase grammar, I've seen
syntactic predicates being used. Not having a good understanding of the
concept makes it difficult to figure out what the grammar rules are.
Re: a problem in syntactic predicate [message #721881 is a reply to message #721750] Sat, 03 September 2011 10:34 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I did say that the grammar cannot enforce the outer else to be matched. But without syntactic predicates you cannot enforce that the inner else is to be matched either (which you now can), so there is a big difference in having or not having them.

Without syntactic predicates a grammar could be ambiguous and in some cases you had to enable backtracking which is bad if you want to have a performant parser. Syntactic predicates now provide a way to guide the parser without having to enable backtracking. It is useful for many situations that could not be handled previously.

Alex
Re: a problem in syntactic predicate [message #722457 is a reply to message #721197] Mon, 05 September 2011 20:12 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Lulu,

the reference documentation contains a section on syntactic predicates:
http://www.eclipse.org/Xtext/documentation/2_0_0/020-grammar-language.php#syntax

I'm afraid there is not more information available.
The predicate guards the element that is .. well .. predicated. That is,
if you use it for a group =>(e ';'), the parser will look for an e
followed by a ';', if you use it only for the =>e, the following ';'
will not be considered for the decision. Does that make sense to you?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 01.09.11 09:18, lulu wrote:
> Hi, All,
> There has a problem while practice syntactic predicate.
>
> xtext grammar like this:
> ----- begin -------
> a:
> => e ';' | e '.'
> ;
>
> e: => '(' ID ')' ID //type cast
> | '(' ID ')' //nest expression
> | ID
> ;
>
> terminal ID: ('a'..'z')+;
> ----------- end ----------
>
> while run as eclipse application, it occur some mistake in .dsl file.
>
>
> But after I add brace in syntactic predicate. grammar show as follow:
> ----- begin -------
> a:
> => ( e ';' )
> | e '.'
> ;
>
> e: => ( '(' ID ')' ID ) //type cast
> | '(' ID ')' //nest expression
> | ID
> ;
>
> terminal ID: ('a'..'z')+;
> ----------- end ----------
>
> It is run correctly which can match follow pattern:
> test.
> (test).
> (test)test.
> test;
> (test);
> (test)test;
>
> I did not find any detail description in syntactic predicate about Xtext.
>
> Thanks.
>
Re: a problem in syntactic predicate [message #722523 is a reply to message #722457] Tue, 06 September 2011 03:30 Go to previous message
lulu  is currently offline lulu Friend
Messages: 19
Registered: August 2011
Junior Member
Hi, Sebastian,

I understand.

Syntactic predicate in Xtext has some differences from that of ANTLR.

Thanks.

Lulu
Previous Topic:dsl conflict with Eclipse exist plugin
Next Topic:Exported names from other resources always in scope?
Goto Forum:
  


Current Time: Fri Apr 26 23:16:34 GMT 2024

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

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

Back to the top