[antlr-interest] Incompatible type in subrules with OR
Gary Miller
gary at sumwise.com
Mon Jul 25 16:16:32 PDT 2011
Hey Claudio,
Please try to remember to reply to the list and not directly to the person.
Unfortunately this list server doesn't add a reply_to in the header.
I'm guessing that you problem is one of cardinality.
The cardinality on the left and right should generally match.
I would go as far as saying that you might want to restructure your grammar
so that they always match (I'm not sure if this is actually possible
though).
So
r
: a c -> (A c)
| a b -> (A b)
;
is preferable to
r
: a (c | b) -> (A c? b?)
;
IMO.
I'm guessing your mistake is here
locationStep: edge condition* (repeat | shortestPath)?
-> ^(LOCATIONSTEP condition? repeat? shortestPath?);
as condition has a * on the left and a ? on the right.
Try
locationStep: edge condition* (repeat | shortestPath)?
-> ^(LOCATIONSTEP condition* repeat? shortestPath?);
And look for any other mismatches.
Regards
Gary
On Tue, Jul 26, 2011 at 12:23 AM, Claudio Martella <
claudio.martella at tis.bz.it> wrote:
> I applied (1) and it worked. I have one problem with this grammar
> though. I'm debugging it with ANTLRWorks and the generated Parse Tree is
> correct. The problem is that when I visualize the AST some things don't
> work. In particular the filterFunction internal node is not always
> present. Sometimes the filter node has a direct child "PREFIX(" and the
> token ')' is still present instead of being discarded. I don't
> understand how this can be possible as the Parse Tree is correct AND for
> certain examples the AST for filter is also correct.
>
> To replicate it try the query "claudio :: age [MAX(10)][MIN(3)] > age
> [country = EQUALS('italy')] > weight [MIN(3)] (*3) .DISTANCE('marco')"
>
> with this grammar:
> grammar RDFPath;
>
> options { output = AST; }
> tokens {
> QUERY = 'query';
> LOCATIONSTEP = 'locationstep';
> CONDITION = 'condition';
> FILTER = 'filter';
> FILTERFUNCTION = 'filterfunction';
> SUBQUERY = 'subquery';
> REPEAT = 'repeat';
> SHORTESTPATH = 'shortestpath';
> ENDNODEFUNCTION = 'endnodefunction';
> STARTNODE = 'startnode';
> EDGE = 'edge';
> }
>
> /* PARSER RULES */
>
> query: startNode '::' locationStep ('>' locationStep)* ('.'
> endNodeFunction)?
> -> ^(QUERY startNode locationStep+ endNodeFunction);
>
> locationStep: edge condition* (repeat | shortestPath)?
> -> ^(LOCATIONSTEP condition? repeat? shortestPath?);
>
> condition: '[' ( filter | subquery ) ']'
> -> ^(CONDITION filter? subquery?);
>
>
> filter: filterFunction
> -> ^(FILTER filterFunction);
>
> filterFunction: fn='EQUALS(' v=STRING ')' | fn='EQUALS(' v=INTVALUE ')'
> | fn='SUFFIX(' v=STRING ')' | fn='PREFIX(' v=STRING ')'
> | fn='MIN(' v=INTVALUE ')' | fn='MAX(' v=INTVALUE ')'
> -> ^(FILTERFUNCTION $fn $v);
>
> subquery: edge '=' filterFunction
> -> ^(SUBQUERY edge filterFunction);
>
> repeat: '(' v=INTVALUE ')'
> -> ^(REPEAT $v);
>
> shortestPath: '(*' v=INTVALUE ')'
> -> ^(SHORTESTPATH $v);
>
> endNodeFunction: fn='COUNT()' | fn='SUM()' | fn='AVG()'
> | fn='MIN()' | fn='MAX()' | fn='DISTANCE(' v=STRING ')'
> -> ^(ENDNODEFUNCTION $fn $v);
>
> startNode: v='*' | v=TEXTVALUE
> -> ^(STARTNODE $v);
>
> edge: v=TEXTVALUE
> -> ^(EDGE $v);
>
> /* LEXER RULES */
>
> TEXTVALUE: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')* ;
>
> INTVALUE: ('0'..'9')+ ;
>
> STRING : '\'' TEXTVALUE '\'' ;
>
> ID: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
>
> WS: (' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;};
>
>
>
> On 7/22/11 2:10 AM, Gary Miller wrote:
> > Try the following options.
> >
> > 1.
> > locationStep: edge condition? (repeat | shortestPath)? ('>'
> locationStep)?
> > -> ^(LOCATIONSTEP condition? repeat? shortestPath? locationStep?);
> >
> > condition: ( filter | subquery ) condition?
> > -> ^(CONDITION filter? subquery? condition?);
> >
> > or
> > 2.
> > locationStep
> > : edge condition? repeat? ('>' locationStep)? -> ^(LOCATIONSTEP
> > condition? shortestPath? locationStep?)
> > | edge condition? shortestPath? ('>' locationStep)? ->
> > ^(LOCATIONSTEP condition? shortestPath? locationStep?)
> > ;
> >
> > condition
> > : filter condition? -> ^(CONDITION filter condition?)
> > | subquery condition? -> ^(CONDITION subquery condition?)
> > ;
> >
> > Regards
> > Gary
> >
> >
> > On Thu, Jul 21, 2011 at 9:16 PM, Claudio Martella
> > <claudio.martella at tis.bz.it> wrote:
> >> Hello,
> >>
> >> I've this grammar: http://pastebin.com/dNzdGx8R but i get this error
> >> when I test it with AntlrWorks:
> >>
> >> [11:23:59] /Users/hammer/output/RDFPathParser.java:383: incompatible
> types
> >> [11:23:59] found : RDFPathParser.repeat_return
> >> [11:23:59] required: RDFPathParser.shortestPath_return
> >> [11:23:59] v=repeat();
> >> [11:23:59] ^
> >> [11:23:59] /Users/hammer/output/RDFPathParser.java:586: incompatible
> types
> >> [11:23:59] found : RDFPathParser.filter_return
> >> [11:23:59] required: RDFPathParser.subquery_return
> >> [11:23:59] v=filter();
> >> [11:23:59] ^
> >> [11:23:59] 2 errors
> >>
> >>
> >> Basically I think the problem is the assignment in the subrules with ORs
> >> in two statements:
> >>
> >> locationStep: edge condition? (v=repeat | v=shortestPath)? ('>'
> >> locationStep)?
> >> -> ^(LOCATIONSTEP condition $v locationStep);
> >>
> >> condition: ( v=filter | v=subquery ) condition?
> >> -> ^(CONDITION $v condition);
> >>
> >> How do I handle these situations where I have the two or more options in
> >> a subrule?
> >>
> >>
> >> Thanks
> >> Claudio
> >>
> >> --
> >> Claudio Martella
> >> Free Software & Open Technologies
> >> Analyst
> >>
> >> TIS innovation park
> >> Via Siemens 19 | Siemensstr. 19
> >> 39100 Bolzano | 39100 Bozen
> >> Tel. +39 0471 068 123
> >> Fax +39 0471 068 129
> >> claudio.martella at tis.bz.it http://www.tis.bz.it
> >>
> >> Short information regarding use of personal data. According to Section
> 13 of Italian Legislative Decree no. 196 of 30 June 2003, we inform you that
> we process your personal data in order to fulfil contractual and fiscal
> obligations and also to send you information regarding our services and
> events. Your personal data are processed with and without electronic means
> and by respecting data subjects' rights, fundamental freedoms and dignity,
> particularly with regard to confidentiality, personal identity and the right
> to personal data protection. At any time and without formalities you can
> write an e-mail to privacy at tis.bz.it in order to object the processing of
> your personal data for the purpose of sending advertising materials and also
> to exercise the right to access personal data and other rights referred to
> in Section 7 of Decree 196/2003. The data controller is TIS Techno
> Innovation Alto Adige, Siemens Street n. 19, Bolzano. You can find the
> complete information on the web si
> >> te www.tis.bz.it.
> >>
> >>
> >>
> >>
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >>
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
>
>
> --
> Claudio Martella
> Free Software & Open Technologies
> Analyst
>
> TIS innovation park
> Via Siemens 19 | Siemensstr. 19
> 39100 Bolzano | 39100 Bozen
> Tel. +39 0471 068 123
> Fax +39 0471 068 129
> claudio.martella at tis.bz.it http://www.tis.bz.it
>
> Short information regarding use of personal data. According to Section 13
> of Italian Legislative Decree no. 196 of 30 June 2003, we inform you that we
> process your personal data in order to fulfil contractual and fiscal
> obligations and also to send you information regarding our services and
> events. Your personal data are processed with and without electronic means
> and by respecting data subjects' rights, fundamental freedoms and dignity,
> particularly with regard to confidentiality, personal identity and the right
> to personal data protection. At any time and without formalities you can
> write an e-mail to privacy at tis.bz.it in order to object the processing of
> your personal data for the purpose of sending advertising materials and also
> to exercise the right to access personal data and other rights referred to
> in Section 7 of Decree 196/2003. The data controller is TIS Techno
> Innovation Alto Adige, Siemens Street n. 19, Bolzano. You can find the
> complete information on the web site www.tis.bz.it.
>
>
>
>
>
More information about the antlr-interest
mailing list