[antlr-interest] What is wrong with my if rule?

YINGAnnie yimm8369 at hotmail.com
Fri Apr 3 12:44:56 PDT 2009


 

Hi all,

 

Help me to look at what is wrong with my if rule:

 

 ifStatement
     :   IF parExpression stmt=statement (ELSE thenstmt=statement)?                      ;


 statement returns [String out]
 :   (blockStatement                          ->^(STATEMENT blockStatement)
     |   useNamespaceStatement                   ->^(STATEMENT useNamespaceStatement)
     |   namespaceStatement                      ->^(STATEMENT namespaceStatement)
     |   constantVarStatement                    ->^(STATEMENT constantVarStatement)
     |   tryStatement                            ->^(STATEMENT tryStatement)
     |   labelledStatement                       ->^(STATEMENT  labelledStatement  )
     |   switchStatement                         ->^(STATEMENT switchStatement)
     |   withStatement                           ->^(STATEMENT  withStatement )
     |   returnStatement                         ->^(STATEMENT returnStatement  )
     |   breakStatement                          ->^(STATEMENT breakStatement )
     |   continueStatement                       ->^(STATEMENT continueStatement )
     |   forStatement                            ->^(STATEMENT  forStatement )
     |   forInStatement                          ->^(STATEMENT forInStatement)
     |   doWhileStatement                        ->^(STATEMENT doWhileStatement )
     |   whileStatement                          ->^(STATEMENT  whileStatement)
     |   ifStatement                             ->^(STATEMENT ifStatement)
     |   emptyStatement                          ->^(STATEMENT emptyStatement )
     |   variableStatement                       ->^(STATEMENT variableStatement  )
     |   functionDeclaration                     ->^(STATEMENT functionDeclaration )
     |   expression semic                        ->^(STATEMENT expression semic )
     |   expressionNoIn semic                    ->^(STATEMENT expressionNoIn semic )   
     ;

 

Question1 :


When I use:
 if ( a==2) {
      b=1;
  }
  else {b=2;
 }
         
I got  line 9:39 mismatched character '{' expecting 'i' .
The reason for the that is the space between else and the {, if I delete the space ,the error would not show.But I dont know how to fix it.

 

Question 2:


And the other problem is "else if" can not pass, if I use 

 if ( a==2) {
     b=1;
                                        
    } 
  else if( a== 3) {
     b=2;
   }

 

I got line 10:32 mismatched input 'else if' expecting RCURLY
      line 10:48 no viable alternative at input '{'

 

I am lost here!

 

Thanks in advance.

 

Annie

_________________________________________________________________
MSN 表情魔法书,改变你的对话时代!
http://im.live.cn/emoticons/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090404/affdb1b0/attachment.html 


More information about the antlr-interest mailing list