[antlr-interest] Incompatible type in subrules with OR

Claudio Martella claudio.martella at tis.bz.it
Tue Jul 26 04:07:15 PDT 2011


Yes, you're totally right.
I changed the definition of filterFunction explicitly repeating the ->
^(X xyz) and it works now.


Thanks you very much!



On 7/26/11 12:45 PM, Gary Miller wrote:
> Hey Claudio,
>
> It was no inconvenience, I was just hoping that others more
> experienced then me could also help.
>
> After type this email I think your problem is point (4), your
> interpretation of 
> Â  rule : v=a | v=b -> ^(X $v);
> I think this means
> Â  rule : a -> a | b -> ^(X b);
> You probably meant to write
> Â rule : a -> ^(X a) | b -> ^(X b);
>
> The rests of this email is probably just commentary.
> Regards
> Gary
>
> Your grammar looks quite odd to me in a number of ways.
> 1. I have found that it help me to split my lexer and parser. 
> Â  Â The result of this is that a lot of your parser rules as they
> stand would be invalid.
> Â  Â I think the main reason I do this is that I get easily confused
> by lexing.
> 2. I do have assignments in my token sections. 
>     i.e. 
> Â  Â  Â  Â  token { A = 'a'; }Â 
>     only virtual token definitions 
> Â  Â  Â  Â  token { A; }
> 3. I would try for a more generic function definition and deal with
> function validation later e.g. in a walker.
> Â  Â  eg.
> Â  Â  Â  Â function : name=STRING LPAREN (arg=STRING)* RPAREN ->
> ^(FUNC $name $arg)
> 4. Your OR look strange, as far as I know every OR (make not the one
> in bracket, but I'm not sure need a rewrite or AST production)
> Â  Â  I think the following is wrong
> Â  Â  Â  Â  rule : foo | bar | lalala -> ^(X xyz)
> Â  Â  This might mean (experts please help here)
> Â  Â  Â  Â  rule
> Â  Â  Â  Â  Â  : Â foo -> foo
> Â  Â  Â  Â  Â  | bar -> bar
> Â  Â  Â  Â  Â  | lalala -> ^(X xyz)
> Â  Â  Â  Â  Â  ;
> Â  Â  Â I think you probably wanted
> Â  Â  Â  Â  rule
> Â  Â  Â  Â  Â  : Â foo -> ^(X xyz)
> Â  Â  Â  Â  Â  | bar ->Â ^(X xyz)
> Â  Â  Â  Â  Â  | lalala -> ^(X xyz)
> Â  Â  Â  Â  Â  ;
>
> Hope this helped.
>
> On Tue, Jul 26, 2011 at 7:50 PM, Claudio Martella
> <claudio.martella at tis.bz.it <mailto:claudio.martella at tis.bz.it>> wrote:
>
>     Hi Gary,
>
>     sorry for the inconvenience about the direct email, realized about the
>     reply_to only after I clicked.
>     Actually I did fix that cardinality yesterday before your suggestion,
>     but the problem persists.
>     I also tried to restructure my grammar as you suggest but I'm still
>     finding the same trouble and sincerely I'm running out of options...
>
>     For example locationStep is now:
>
>     locationStep
>     Â  Â : Â  Â edge condition*
>     Â  Â  Â  Â -> ^(LOCATIONSTEP edge condition*)
>     Â  Â | Â  Â edge condition* repeat
>     Â  Â  Â  Â -> ^(LOCATIONSTEP edge condition* repeat)
>     Â  Â | Â  Â edge condition* shortestPath
>     Â  Â  Â  Â -> ^(LOCATIONSTEP edge condition* shortestPath);
>
>     To get rid of condition* I'd have to restructure everything with a
>     recursive definition of condition, but that doesn't feel like the
>     right
>     thing to do or a reason why things would start working.
>
>
>     My grammar in the end is very simple and I really don't know how to
>     proceed to fix this.
>
>     Any suggestion about what I should read?
>
>
>     On 7/26/11 1:16 AM, Gary Miller wrote:
>     > 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 <mailto:claudio.martella at tis.bz.it>
>     <mailto:claudio.martella at tis.bz.it
>     <mailto: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
>     <mailto:claudio.martella at tis.bz.it>
>     <mailto:claudio.martella at tis.bz.it
>     <mailto: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 <tel:%2B39%200471%20068%20123>
>     <tel:%2B39%200471%20068%20123>
>     >     >> Fax �+39 0471 068 129 <tel:%2B39%200471%20068%20129>
>     <tel:%2B39%200471%20068%20129>
>     > Â  Â  >> claudio.martella at tis.bz.it
>     <mailto:claudio.martella at tis.bz.it>
>     <mailto:claudio.martella at tis.bz.it
>     <mailto: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
>     <mailto:privacy at tis.bz.it>
>     > Â  Â  <mailto:privacy at tis.bz.it <mailto: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 <http://www.tis.bz.it>
>     <http://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 <tel:%2B39%200471%20068%20123>
>     <tel:%2B39%200471%20068%20123>
>     >     Fax �+39 0471 068 129 <tel:%2B39%200471%20068%20129>
>     <tel:%2B39%200471%20068%20129>
>     > Â  Â  claudio.martella at tis.bz.it
>     <mailto:claudio.martella at tis.bz.it>
>     <mailto:claudio.martella at tis.bz.it
>     <mailto: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
>     <mailto:privacy at tis.bz.it>
>     > Â  Â  <mailto:privacy at tis.bz.it <mailto: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 <http://www.tis.bz.it>
>     <http://www.tis.bz.it>.
>     >
>     >
>     >
>     >
>     >
>
>
>     --
>     Claudio Martella
>     Free Software & Open Technologies
>     Analyst
>
>     TIS innovation park
>     Via Siemens 19 | Siemensstr. 19
>     39100 Bolzano | 39100 Bozen
>     Tel. +39 0471 068 123 <tel:%2B39%200471%20068%20123>
>     Fax  +39 0471 068 129 <tel:%2B39%200471%20068%20129>
>     claudio.martella at tis.bz.it <mailto: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
>     <mailto: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 <http://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
>
>


-- 
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