[antlr-interest] predicate, uh?: bug in c-grammar

Lloyd Dupont lloyd at nova-mind.com
Thu May 26 21:00:38 PDT 2005


found it!
for some obscure reason castExpr could be something else than a cast. expression such as sizof(), __alignof().... are recognized by castExp(??!!!)
why they put such production in castExpr is beyond my uderstanding, but at least it's solved.
(I now use a subrule like that:
protected strictCast: 
     (LPAREN)=> castExpr
     |
     ;
)

Anyway I would call that 'another bug in the c-grammar'
I think that should be fixed, other could fall for the same trap!

PS: not to denigrate the c-grammar which is a great job, and I guess hard to debug for lack of advanced grammar checking tool, just to warn future users: it's slightly bugged!

  ----- Original Message ----- 
  From: Lloyd Dupont 
  To: antlr-interest at antlr.org 
  Sent: Friday, May 27, 2005 10:19 AM
  Subject: [antlr-interest] predicate, uh?


  I have a simple grammar rule like that (inheriting from cgram)

  objcMethodDefinition  returns [String selName]
  {
   selName = "";
  }
   : ( PLUS | MINUS ) (castExpr)? 
    (
      ( ID COLON )=> 
       id0:ID COLON (castExpr)? ID { selName = id0.getText() + ":"; }
       ( 
        (id1:ID  { selName += id1.getText(); })? (COLON) (castExpr)? ID { selName += ":"; }
       ) *
     | id2:ID { selName = id2.getText(); }
    )
   
  note: there is no explicit end to this rule, because I reuse it for both declaration (ending by a ';') and definition (ending by '{').

  when I test it I get this parsing error (while evaluating the (ID COLON)=> !!!) (on something as simple as "- foo { ...."
  ANTLR Parsing Error: # 1 "":line 22:1896: unexpected token: { token name:LCURLY
  line 22:1896: unexpected token: {
          at ObjectiveCParser.postfixExpr(ObjectiveCParser.java:5876)
          at ObjectiveCParser.unaryExpr(ObjectiveCParser.java:5293)
          at ObjectiveCParser.castExpr(ObjectiveCParser.java:1548)
          at ObjectiveCParser.objcMethodDefinition(ObjectiveCParser.java:1129)
          at ObjectiveCParser.objcClassImplementation(ObjectiveCParser.java:1056)
          at ObjectiveCParser.externalDef(ObjectiveCParser.java:213)
          at ObjectiveCParser.externalList(ObjectiveCParser.java:1649)
          at ObjectiveCParser.translationUnit(ObjectiveCParser.java:1610)
          at Test.main(Test.java:40)

  ?!!!
  how come? 
  what did I do wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050527/abf362e0/attachment.html


More information about the antlr-interest mailing list