Home » Modeling » TMF (Xtext) » extending Xbase expression syntax and possible ambiguities
extending Xbase expression syntax and possible ambiguities [message #759137] |
Sat, 26 November 2011 12:36  |
Eclipse User |
|
|
|
Hi
In my DSL I've extended the XEpression syntax with statements such as, say,
environment=[Environment] left=(XExpression) relation=RelationSymbol
right=(XExpression)
where RelationSymbol is a datatype rule as follows:
RelationSymbol:
'::' | ':' | '<:' | ':>' | '<<' | '>>' |
'<|' | '|>' | '<-' | '->'
;
however, this will conflict Xbase syntax for instance for static access;
in particular, if I have something like
var MyClass s
G |- s :: s
there's a parse error (which I could avoid by writing)
var MyClass s
G |- (s) :: s
but simply cannot parse
var MyClass s
G |- s <- s
or
var MyClass s
G |- s -> s
any suggestion, please?
thanks in advance
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
|
|
| | | |
Re: extending Xbase expression syntax and possible ambiguities [message #759383 is a reply to message #759203] |
Mon, 28 November 2011 09:07   |
Eclipse User |
|
|
|
On 11/27/2011 04:55 PM, Meinte Boersma wrote:
> Since it's Sunday afternoon and I'm too lazy to plug your grammar into
no problem, you had asked for the grammar ;)
> an Eclipse, I'll just trigger on "backtracking is switched on": is there
> a specific reason to do that? Backtracking disables any reporting of
> ANTLR warnings/errors, but it doesn't mean your grammar is unambiguous -
> far from it, probably. You might want to switch if off again and run the
> generated InternalXtypesParser.g file through ANTLR Works to try and
> iron out the ambiguities without having to resort to backtracking.
backtracking is on due to
RuleConclusionElement:
RuleParameter | ExpressionInConclusion
;
RuleParameter:
parameter=FullJvmFormalParameter
;
ExpressionInConclusion:
expression=XExpression
;
to deal with (FullJvmFormalParameter | XExpression)
probably I'll use a keyword to distinguish between parameter and
expression...
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
|
|
| | | |
Re: extending Xbase expression syntax and possible ambiguities [message #759937 is a reply to message #759601] |
Wed, 30 November 2011 10:46  |
Eclipse User |
|
|
|
On 11/29/2011 11:24 AM, Meinte Boersma wrote:
> Your grammar has left-recursion at the following rules (or so
> Xtext/ANTLR tells me): XExpressionInsideBlock, JudgmentSymbol,
> RuleConclusionElement. The thing is that something like calling the
> xbase::XExpression rule is really a bit like Pandora's box: once it's
> open, it's hard to close. You get a lot of stuff for free, but you also
> get a lot of parser rules (which are tried) for free and you have to
> deal with the ensuing left-recursion.
>
> I'd suggest to left-factor the grammar: it's an agitation in the
> buttocks alright, but fixing all kinds of grammar problems you might
> have after that is so much easier and you really can't rely all that
> much on backtracking without a very good test suite checking whether the
> parser does what it's supposed to do. Left-factoring means that you have
> to find out how a certain parser rule might call itself, probably with
> some other calls inbetween, and re-writing that rule in such a way that
> it will always consume a token before trying to match something else
> (and performing a tree rewrite if it does match something else).
Hi
I then refactored my grammar using predicates (at the end the most
important part), after removing backtracking.
I had to give using '::' as a relation symbol since it would be between
two XExpressions, and as you said "calling the
> xbase::XExpression rule is really a bit like Pandora's box" ;)
I had also to give up on '->' but for the moment I'll live with that too :)
thanks
Lore
XExpressionInsideBlock returns xbase::XExpression:
RuleInvocation |
XVariableDeclaration | XExpression;
RuleInvocation:
=>environment=[Environment] jugmentSymbol=JudgmentSymbol
left=XExpression
relationSymbol=RelationSymbol
right=XExpression
;
Environment: name=ID;
JudgmentSymbol:
'||-' | '|-' | '||~' | '|~' | '||=' | '|=' | '||>' | '|>'
;
RelationSymbol:
':' | '<:' | ':>' | '<<' | '>>' |
'<|' | '|>' | '<-' | '-->' | '<~' | '~>';
RuleConclusionElement:
=>(RuleParameter) | ExpressionInConclusion
;
RuleParameter:
parameter=FullJvmFormalParameter
;
ExpressionInConclusion:
expression=XExpression
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
|
|
|
Goto Forum:
Current Time: Wed Jul 23 07:41:43 EDT 2025
Powered by FUDForum. Page generated in 0.06606 seconds
|