*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 438fa59..00cc6c9 100644 (file)
@@ -29,7 +29,6 @@ import org.eclipse.ui.texteditor.MarkerUtilities;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 import java.util.Hashtable;
-import java.util.Enumeration;
 import java.util.ArrayList;
 import java.io.StringReader;
 import java.io.*;
@@ -60,9 +59,6 @@ public final class PHPParser extends PHPParserSuperclass {
   private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
   static PHPOutlineInfo outlineInfo;
 
-  public static MethodDeclaration currentFunction;
-  private static boolean assigning;
-
   /** The error level of the current ParseException. */
   private static int errorLevel = ERROR;
   /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
@@ -71,6 +67,8 @@ public final class PHPParser extends PHPParserSuperclass {
   private static int errorStart = -1;
   private static int errorEnd = -1;
   private static PHPDocument phpDocument;
+
+  private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
   /**
    * The point where html starts.
    * It will be used by the token manager to create HTMLCode objects
@@ -123,8 +121,9 @@ public final class PHPParser extends PHPParserSuperclass {
   }
 
   public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
-    currentSegment = new PHPDocument(parent);
-    outlineInfo = new PHPOutlineInfo(parent);
+    phpDocument = new PHPDocument(parent,"_root".toCharArray());
+    currentSegment = phpDocument;
+    outlineInfo = new PHPOutlineInfo(parent, currentSegment);
     final StringReader stream = new StringReader(s);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
@@ -133,10 +132,11 @@ public final class PHPParser extends PHPParserSuperclass {
     init();
     try {
       parse();
-      phpDocument = new PHPDocument(null);
       phpDocument.nodes = new AstNode[nodes.length];
       System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
-      PHPeclipsePlugin.log(1,phpDocument.toString());
+      if (PHPeclipsePlugin.DEBUG) {
+        PHPeclipsePlugin.log(1,phpDocument.toString());
+      }
     } catch (ParseException e) {
       processParseException(e);
     }
@@ -152,7 +152,7 @@ public final class PHPParser extends PHPParserSuperclass {
     if (errorMessage == null) {
       PHPeclipsePlugin.log(e);
       errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
-      errorStart = jj_input_stream.getPosition();
+      errorStart = SimpleCharStream.getPosition();
       errorEnd   = errorStart + 1;
     }
     setMarker(e);
@@ -168,8 +168,8 @@ public final class PHPParser extends PHPParserSuperclass {
       if (errorStart == -1) {
         setMarker(fileToParse,
                   errorMessage,
-                  jj_input_stream.tokenBegin,
-                  jj_input_stream.tokenBegin + e.currentToken.image.length(),
+                  SimpleCharStream.tokenBegin,
+                  SimpleCharStream.tokenBegin + e.currentToken.image.length(),
                   errorLevel,
                   "Line " + e.currentToken.beginLine);
       } else {
@@ -187,31 +187,6 @@ public final class PHPParser extends PHPParserSuperclass {
     }
   }
 
-  /**
-   * Create markers according to the external parser output
-   */
-  private static void createMarkers(final String output, final IFile file) throws CoreException {
-    // delete all markers
-    file.deleteMarkers(IMarker.PROBLEM, false, 0);
-
-    int indx = 0;
-    int brIndx;
-    boolean flag = true;
-    while ((brIndx = output.indexOf("<br />", indx)) != -1) {
-      // newer php error output (tested with 4.2.3)
-      scanLine(output, file, indx, brIndx);
-      indx = brIndx + 6;
-      flag = false;
-    }
-    if (flag) {
-      while ((brIndx = output.indexOf("<br>", indx)) != -1) {
-        // older php error output (tested with 4.2.3)
-        scanLine(output, file, indx, brIndx);
-        indx = brIndx + 4;
-      }
-    }
-  }
-
   private static void scanLine(final String output,
                                final IFile file,
                                final int indx,
@@ -301,6 +276,25 @@ public final class PHPParser extends PHPParserSuperclass {
     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
   }
 
+  /**
+   * Create a new task.
+   */
+  public static final void createNewTask() {
+    final int currentPosition = SimpleCharStream.getPosition();
+    final String  todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
+                                                                  SimpleCharStream.currentBuffer.indexOf("\n",
+                                                                                                         currentPosition)-1);
+    try {
+      setMarker(fileToParse,
+                "todo : " + todo,
+                SimpleCharStream.getBeginLine(),
+                TASK,
+                "Line "+SimpleCharStream.getBeginLine());
+    } catch (CoreException e) {
+      PHPeclipsePlugin.log(e);
+    }
+  }
+
   private static final void parse() throws ParseException {
          phpFile();
   }
@@ -341,34 +335,30 @@ PARSER_END(PHPParser)
 <PHPPARSING> SPECIAL_TOKEN :
 {
   "//" : IN_SINGLE_LINE_COMMENT
-|
-  "#"  : IN_SINGLE_LINE_COMMENT
-|
-  <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
-|
-  "/*" : IN_MULTI_LINE_COMMENT
+| "#"  : IN_SINGLE_LINE_COMMENT
+| <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
+| "/*" : IN_MULTI_LINE_COMMENT
 }
 
 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
 {
   <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
+| "?>" : DEFAULT
 }
 
-<IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
+<IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
 {
-  <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
+ "todo" {PHPParser.createNewTask();}
 }
 
-<IN_FORMAL_COMMENT>
-SPECIAL_TOKEN :
+<IN_FORMAL_COMMENT> SPECIAL_TOKEN :
 {
-  <FORMAL_COMMENT: "*/" > : PHPPARSING
+  "*/" : PHPPARSING
 }
 
-<IN_MULTI_LINE_COMMENT>
-SPECIAL_TOKEN :
+<IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
 {
-  <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
+  "*/" : PHPPARSING
 }
 
 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
@@ -466,8 +456,8 @@ MORE :
 {
   <OR_OR              : "||">
 | <AND_AND            : "&&">
-| <INCR               : "++">
-| <DECR               : "--">
+| <PLUS_PLUS          : "++">
+| <MINUS_MINUS        : "--">
 | <PLUS               : "+">
 | <MINUS              : "-">
 | <STAR               : "*">
@@ -605,7 +595,7 @@ MORE :
 
 <PHPPARSING> TOKEN :
 {
-  < DOLLAR_ID: <DOLLAR> <IDENTIFIER>  >
+  <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
 }
 
 void phpFile() :
@@ -613,7 +603,7 @@ void phpFile() :
 {
   try {
     (PhpBlock())*
-    <EOF>
+    {PHPParser.createNewHTMLCode();}
   } catch (TokenMgrError e) {
     PHPeclipsePlugin.log(e);
     errorStart   = SimpleCharStream.getPosition();
@@ -631,18 +621,20 @@ void phpFile() :
  */
 void PhpBlock() :
 {
-  final int start = jj_input_stream.getPosition();
+  final int start = SimpleCharStream.getPosition();
+  final PHPEchoBlock phpEchoBlock;
 }
 {
-  phpEchoBlock()
+  phpEchoBlock = phpEchoBlock()
+  {pushOnAstNodes(phpEchoBlock);}
 |
-  [ <PHPSTARTLONG>
+  [   <PHPSTARTLONG>
     | <PHPSTARTSHORT>
     {try {
       setMarker(fileToParse,
                 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
                 start,
-                jj_input_stream.getPosition(),
+                SimpleCharStream.getPosition(),
                 INFO,
                 "Line " + token.beginLine);
     } catch (CoreException e) {
@@ -655,9 +647,9 @@ void PhpBlock() :
   } catch (ParseException e) {
     errorMessage = "'?>' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
 }
 
@@ -687,41 +679,46 @@ ClassDeclaration ClassDeclaration() :
   final Token className;
   Token superclassName = null;
   final int pos;
+  char[] classNameImage = SYNTAX_ERROR_CHAR;
+  char[] superclassNameImage = null;
 }
 {
   <CLASS>
+  {pos = SimpleCharStream.getPosition();}
   try {
-    {pos = jj_input_stream.getPosition();}
     className = <IDENTIFIER>
+    {classNameImage = className.image.toCharArray();}
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
   [
     <EXTENDS>
     try {
       superclassName = <IDENTIFIER>
+      {superclassNameImage = superclassName.image.toCharArray();}
     } catch (ParseException e) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
-      throw e;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
+      processParseException(e);
+      superclassNameImage = SYNTAX_ERROR_CHAR;
     }
   ]
   {
-    if (superclassName == null) {
+    if (superclassNameImage == null) {
       classDeclaration = new ClassDeclaration(currentSegment,
-                                              className.image.toCharArray(),
+                                              classNameImage,
                                               pos,
                                               0);
     } else {
       classDeclaration = new ClassDeclaration(currentSegment,
-                                              className.image.toCharArray(),
-                                              superclassName.image.toCharArray(),
+                                              classNameImage,
+                                              superclassNameImage,
                                               pos,
                                               0);
     }
@@ -769,7 +766,7 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
 }
 {
   method = MethodDeclaration() {classDeclaration.addMethod(method);}
-| field = FieldDeclaration()   {classDeclaration.addVariable(field);}
+| field = FieldDeclaration()   {classDeclaration.addField(field);}
 }
 
 /**
@@ -785,12 +782,10 @@ FieldDeclaration FieldDeclaration() :
 {
   <VAR> variableDeclaration = VariableDeclarator()
   {arrayList.add(variableDeclaration);
-   outlineInfo.addVariable(new String(variableDeclaration.name));
-   currentSegment.add(variableDeclaration);}
+   outlineInfo.addVariable(new String(variableDeclaration.name));}
   ( <COMMA> variableDeclaration = VariableDeclarator()
       {arrayList.add(variableDeclaration);
-       outlineInfo.addVariable(new String(variableDeclaration.name));
-       currentSegment.add(variableDeclaration);}
+       outlineInfo.addVariable(new String(variableDeclaration.name));}
   )*
   try {
     <SEMICOLON>
@@ -799,21 +794,22 @@ FieldDeclaration FieldDeclaration() :
     errorLevel   = ERROR;
     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd     = SimpleCharStream.getPosition() + 1;
-    throw e;
+    processParseException(e);
   }
 
   {list = new VariableDeclaration[arrayList.size()];
    arrayList.toArray(list);
    return new FieldDeclaration(list,
                                pos,
-                               SimpleCharStream.getPosition());}
+                               SimpleCharStream.getPosition(),
+                               currentSegment);}
 }
 
 VariableDeclaration VariableDeclarator() :
 {
   final String varName;
   Expression initializer = null;
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
 }
 {
   varName = VariableDeclaratorId()
@@ -824,8 +820,8 @@ VariableDeclaration VariableDeclarator() :
     } catch (ParseException e) {
       errorMessage = "Literal expression expected in variable initializer";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
       throw e;
     }
   ]
@@ -834,7 +830,7 @@ VariableDeclaration VariableDeclarator() :
     return new VariableDeclaration(currentSegment,
                                   varName.toCharArray(),
                                   pos,
-                                  jj_input_stream.getPosition());
+                                  SimpleCharStream.getPosition());
   }
     return new VariableDeclaration(currentSegment,
                                     varName.toCharArray(),
@@ -850,31 +846,39 @@ VariableDeclaration VariableDeclarator() :
 String VariableDeclaratorId() :
 {
   String expr;
-  Expression expression;
+  Expression expression = null;
   final StringBuffer buff = new StringBuffer();
   final int pos = SimpleCharStream.getPosition();
   ConstantIdentifier ex;
 }
 {
   try {
-    expr = Variable()   {buff.append(expr);}
+    expr = Variable()
     ( LOOKAHEAD(2)
       {ex = new ConstantIdentifier(expr.toCharArray(),
                                    pos,
                                    SimpleCharStream.getPosition());}
       expression = VariableSuffix(ex)
-      {buff.append(expression.toStringExpression());}
     )*
-    {return buff.toString();}
+    {
+     if (expression == null) {
+       return expr;
+     }
+     return expression.toStringExpression();
+    }
   } catch (ParseException e) {
     errorMessage = "'$' expected for variable identifier";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
 
+/**
+ * Return a variablename without the $.
+ * @return a variable name
+ */
 String Variable():
 {
   final StringBuffer buff;
@@ -885,13 +889,13 @@ String Variable():
 {
   token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
   {
-    if (expression == null && !assigning) {
+    if (expression == null) {
       return token.image.substring(1);
     }
     buff = new StringBuffer(token.image);
-    buff.append('{');
+    buff.append("{");
     buff.append(expression.toStringExpression());
-    buff.append('}');
+    buff.append("}");
     return buff.toString();
   }
 |
@@ -899,6 +903,10 @@ String Variable():
   {return expr;}
 }
 
+/**
+ * A Variable name (without the $)
+ * @return a variable name String
+ */
 String VariableName():
 {
   final StringBuffer buff;
@@ -908,9 +916,9 @@ String VariableName():
 }
 {
   <LBRACE> expression = Expression() <RBRACE>
-  {buff = new StringBuffer('{');
+  {buff = new StringBuffer("{");
    buff.append(expression.toStringExpression());
-   buff.append('}');
+   buff.append("}");
    return buff.toString();}
 |
   token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
@@ -919,15 +927,15 @@ String VariableName():
       return token.image;
     }
     buff = new StringBuffer(token.image);
-    buff.append('{');
+    buff.append("{");
     buff.append(expression.toStringExpression());
-    buff.append('}');
+    buff.append("}");
     return buff.toString();
   }
 |
   <DOLLAR> expr = VariableName()
   {
-    buff = new StringBuffer('$');
+    buff = new StringBuffer("$");
     buff.append(expr);
     return buff.toString();
   }
@@ -1006,6 +1014,7 @@ MethodDeclaration MethodDeclaration() :
 {
   final MethodDeclaration functionDeclaration;
   final Block block;
+  final OutlineableWithChildren seg = currentSegment;
 }
 {
   <FUNCTION>
@@ -1016,26 +1025,15 @@ MethodDeclaration MethodDeclaration() :
     if (errorMessage != null)  throw e;
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
-  {
-    if (currentSegment != null) {
-      currentSegment.add(functionDeclaration);
-      currentSegment = functionDeclaration;
-    }
-    currentFunction = functionDeclaration;
-  }
+  {currentSegment = functionDeclaration;}
   block = Block()
-  {
-    functionDeclaration.statements = block.statements;
-    currentFunction = null;
-    if (currentSegment != null) {
-      currentSegment = (OutlineableWithChildren) currentSegment.getParent();
-    }
-    return functionDeclaration;
-  }
+  {functionDeclaration.statements = block.statements;
+   currentSegment = seg;
+   return functionDeclaration;}
 }
 
 /**
@@ -1049,16 +1047,27 @@ MethodDeclaration MethodDeclarator() :
   Token reference = null;
   final Hashtable formalParameters;
   final int pos = SimpleCharStream.getPosition();
+  char[] identifierChar = SYNTAX_ERROR_CHAR;
 }
 {
-  [reference = <BIT_AND>] identifier = <IDENTIFIER>
+  [reference = <BIT_AND>]
+  try {
+    identifier = <IDENTIFIER>
+    {identifierChar = identifier.image.toCharArray();}
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
+    errorLevel   = ERROR;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
+  }
   formalParameters = FormalParameters()
   {return new MethodDeclaration(currentSegment,
-                                 identifier.image.toCharArray(),
-                                 formalParameters,
-                                 reference != null,
-                                 pos,
-                                 SimpleCharStream.getPosition());}
+                                identifierChar,
+                                formalParameters,
+                                reference != null,
+                                pos,
+                                SimpleCharStream.getPosition());}
 }
 
 /**
@@ -1076,9 +1085,9 @@ Hashtable FormalParameters() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
             [ var = FormalParameter()
               {parameters.put(new String(var.name),var);}
@@ -1092,9 +1101,9 @@ Hashtable FormalParameters() :
   } catch (ParseException e) {
     errorMessage = "')' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
  {return parameters;}
 }
@@ -1121,32 +1130,23 @@ ConstantIdentifier Type() :
 {final int pos;}
 {
   <STRING>             {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.STRING,
-                                                      pos,pos-6);}
+                        return new ConstantIdentifier(Types.STRING,pos,pos-6);}
 | <BOOL>               {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.BOOL,
-                                                      pos,pos-4);}
+                        return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
 | <BOOLEAN>            {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.BOOLEAN,
-                                                      pos,pos-7);}
+                        return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
 | <REAL>               {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.REAL,
-                                                      pos,pos-4);}
+                        return new ConstantIdentifier(Types.REAL,pos,pos-4);}
 | <DOUBLE>             {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.DOUBLE,
-                                                      pos,pos-5);}
+                        return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
 | <FLOAT>              {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.FLOAT,
-                                                      pos,pos-5);}
+                        return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
 | <INT>                {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.INT,
-                                                      pos,pos-3);}
+                        return new ConstantIdentifier(Types.INT,pos,pos-3);}
 | <INTEGER>            {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.INTEGER,
-                                                      pos,pos-7);}
+                        return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
 | <OBJECT>             {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.OBJECT,
-                                                      pos,pos-6);}
+                        return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
 }
 
 Expression Expression() :
@@ -1168,7 +1168,7 @@ Expression Expression() :
 VarAssignation varAssignation() :
 {
   String varName;
-  final Expression expression;
+  final Expression initializer;
   final int assignOperator;
   final int pos = SimpleCharStream.getPosition();
 }
@@ -1176,19 +1176,19 @@ VarAssignation varAssignation() :
   varName = VariableDeclaratorId()
   assignOperator = AssignmentOperator()
     try {
-      expression = Expression()
+      initializer = Expression()
     } catch (ParseException e) {
       if (errorMessage != null) {
         throw e;
       }
       errorMessage = "expression expected";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
       throw e;
     }
     {return new VarAssignation(varName.toCharArray(),
-                               expression,
+                               initializer,
                                assignOperator,
                                pos,
                                SimpleCharStream.getPosition());}
@@ -1335,8 +1335,8 @@ Expression EqualityExpression() :
     }
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {
@@ -1409,8 +1409,8 @@ Expression MultiplicativeExpression() :
     if (errorMessage != null) throw e;
     errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   (
@@ -1480,8 +1480,8 @@ final int operator;
   final int pos = SimpleCharStream.getPosition();
 }
 {
-  (  <INCR> {operator = OperatorIds.PLUS_PLUS;}
-   | <DECR> {operator = OperatorIds.MINUS_MINUS;})
+  (  <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
+   | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
    expr = PrimaryExpression()
   {return new PrefixedUnaryExpression(expr,operator,pos);}
 }
@@ -1503,8 +1503,8 @@ Expression UnaryExpressionNotPlusMinus() :
   } catch (ParseException e) {
     errorMessage = "')' expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return expr;}
@@ -1532,8 +1532,8 @@ Expression PostfixExpression() :
 }
 {
   expr = PrimaryExpression()
-  [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
-  | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
+  [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
+  | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
   {
     if (operator == -1) {
       return expr;
@@ -1567,6 +1567,11 @@ Expression PrimaryExpression() :
   {return expr;}
 }
 
+/**
+ * An array declarator.
+ * array(vars)
+ * @return an array
+ */
 ArrayInitializer ArrayDeclarator() :
 {
   final ArrayVariableDeclaration[] vars;
@@ -1591,9 +1596,10 @@ Expression PrimaryPrefix() :
 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
                                                                      OperatorIds.NEW,
                                                                      pos);}
-| var = VariableDeclaratorId()  {return new ConstantIdentifier(var.toCharArray(),
-                                                               pos,
-                                                               SimpleCharStream.getPosition());}
+| var = VariableDeclaratorId()  {return new VariableDeclaration(currentSegment,
+                                                                var.toCharArray(),
+                                                                pos,
+                                                                SimpleCharStream.getPosition());}
 }
 
 PrefixedUnaryExpression classInstantiation() :
@@ -1654,8 +1660,8 @@ AbstractSuffixExpression VariableSuffix(Expression prefix) :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new ClassAccess(prefix,
@@ -1668,8 +1674,8 @@ AbstractSuffixExpression VariableSuffix(Expression prefix) :
   } catch (ParseException e) {
     errorMessage = "']' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
@@ -1706,8 +1712,8 @@ Expression[] args = null;
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
@@ -1733,8 +1739,8 @@ final ArrayList list = new ArrayList();
       } catch (ParseException e) {
         errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
         errorLevel   = ERROR;
-        errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-        errorEnd     = jj_input_stream.getPosition() + 1;
+        errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+        errorEnd     = SimpleCharStream.getPosition() + 1;
         throw e;
       }
    )*
@@ -1758,11 +1764,11 @@ Statement StatementNoBreak() :
   try {
     <SEMICOLON>
   } catch (ParseException e) {
-    if (e.currentToken.next.kind != 4) {
+    if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
       throw e;
     }
   }
@@ -1777,8 +1783,8 @@ Statement StatementNoBreak() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return statement;}
@@ -1826,17 +1832,18 @@ HTMLBlock htmlBlock() :
   try {
     (<PHPSTARTLONG> | <PHPSTARTSHORT>)
   } catch (ParseException e) {
-    errorMessage = "End of file unexpected, '<?php' expected";
+    errorMessage = "unexpected end of file , '<?php' expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition();
-    errorEnd     = jj_input_stream.getPosition();
+    errorStart   = SimpleCharStream.getPosition();
+    errorEnd     = SimpleCharStream.getPosition();
     throw e;
   }
   {
-  nbNodes = nodePtr-startIndex - 1;
+  nbNodes    = nodePtr - startIndex;
   blockNodes = new AstNode[nbNodes];
   System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
-  return new HTMLBlock(nodes);}
+  nodePtr = startIndex;
+  return new HTMLBlock(blockNodes);}
 }
 
 /**
@@ -1846,7 +1853,7 @@ InclusionStatement IncludeStatement() :
 {
   final Expression expr;
   final int keyword;
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
   final InclusionStatement inclusionStatement;
 }
 {
@@ -1862,8 +1869,8 @@ InclusionStatement IncludeStatement() :
     }
     errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {inclusionStatement = new InclusionStatement(currentSegment,
@@ -1877,8 +1884,8 @@ InclusionStatement IncludeStatement() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return inclusionStatement;}
@@ -1907,8 +1914,8 @@ ListExpression ListExpression() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   [
@@ -1922,8 +1929,8 @@ ListExpression ListExpression() :
     } catch (ParseException e) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
       errorLevel   = ERROR;
-      errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd     = jj_input_stream.getPosition() + 1;
+      errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd     = SimpleCharStream.getPosition() + 1;
       throw e;
     }
     expr = VariableDeclaratorId()
@@ -1934,8 +1941,8 @@ ListExpression ListExpression() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   [ <ASSIGN> expression = Expression()
@@ -1972,24 +1979,23 @@ EchoStatement EchoStatement() :
   )*
   try {
     <SEMICOLON>
-    {
-    Expression[] exprs = new Expression[expressions.size()];
-    expressions.toArray(exprs);
-    return new EchoStatement(exprs,pos);}
   } catch (ParseException e) {
     if (e.currentToken.next.kind != 4) {
       errorMessage = "';' expected after 'echo' statement";
       errorLevel   = ERROR;
-      errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd     = jj_input_stream.getPosition() + 1;
+      errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd     = SimpleCharStream.getPosition() + 1;
       throw e;
     }
   }
+  {Expression[] exprs = new Expression[expressions.size()];
+   expressions.toArray(exprs);
+   return new EchoStatement(exprs,pos);}
 }
 
 GlobalStatement GlobalStatement() :
 {
-   final int pos = jj_input_stream.getPosition();
+   final int pos = SimpleCharStream.getPosition();
    String expr;
    ArrayList vars = new ArrayList();
    GlobalStatement global;
@@ -2016,8 +2022,8 @@ GlobalStatement GlobalStatement() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2042,8 +2048,8 @@ StaticStatement StaticStatement() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2078,8 +2084,8 @@ Block Block() :
   } catch (ParseException e) {
     errorMessage = "'{' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   ( statement = BlockStatement() {list.add(statement);}
@@ -2089,8 +2095,8 @@ Block Block() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {
@@ -2104,9 +2110,21 @@ Statement BlockStatement() :
   final Statement statement;
 }
 {
-  statement = Statement()         {return statement;}
+  try {
+  statement = Statement()         {if (phpDocument == currentSegment) pushOnAstNodes(statement);
+                                   return statement;}
+  } catch (ParseException e) {
+    if (errorMessage != null) throw e;
+    errorMessage = "statement expected";
+    errorLevel   = ERROR;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    throw e;
+  }
 | statement = ClassDeclaration()  {return statement;}
-| statement = MethodDeclaration() {return statement;}
+| statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
+                                   currentSegment.add((MethodDeclaration) statement);
+                                   return statement;}
 }
 
 /**
@@ -2119,7 +2137,8 @@ Statement BlockStatementNoBreak() :
 {
   statement = StatementNoBreak()  {return statement;}
 | statement = ClassDeclaration()  {return statement;}
-| statement = MethodDeclaration() {return statement;}
+| statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
+                                   return statement;}
 }
 
 VariableDeclaration[] LocalVariableDeclaration() :
@@ -2150,7 +2169,7 @@ VariableDeclaration LocalVariableDeclarator() :
     return new VariableDeclaration(currentSegment,
                                   varName.toCharArray(),
                                   pos,
-                                  jj_input_stream.getPosition());
+                                  SimpleCharStream.getPosition());
    }
     return new VariableDeclaration(currentSegment,
                                     varName.toCharArray(),
@@ -2169,7 +2188,7 @@ EmptyStatement EmptyStatement() :
    return new EmptyStatement(pos-1,pos);}
 }
 
-Statement StatementExpression() :
+Expression StatementExpression() :
 {
   Expression expr,expr2;
   int operator;
@@ -2178,10 +2197,10 @@ Statement StatementExpression() :
   expr = PreIncDecExpression() {return expr;}
 |
   expr = PrimaryExpression()
-  [ <INCR> {return new PostfixedUnaryExpression(expr,
+  [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
                                                 OperatorIds.PLUS_PLUS,
                                                 SimpleCharStream.getPosition());}
-  | <DECR> {return new PostfixedUnaryExpression(expr,
+  | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
                                                 OperatorIds.MINUS_MINUS,
                                                 SimpleCharStream.getPosition());}
   | operator = AssignmentOperator() expr2 = Expression()
@@ -2203,8 +2222,8 @@ SwitchStatement SwitchStatement() :
   } catch (ParseException e) {
     errorMessage = "'(' expected after 'switch'";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2215,8 +2234,8 @@ SwitchStatement SwitchStatement() :
     }
     errorMessage = "expression expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2224,8 +2243,8 @@ SwitchStatement SwitchStatement() :
   } catch (ParseException e) {
     errorMessage = "')' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
@@ -2249,8 +2268,8 @@ AbstractCase[] switchStatementBrace() :
   } catch (ParseException e) {
     errorMessage = "'}' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2282,8 +2301,8 @@ AbstractCase[] switchStatementColon(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "'endswitch' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2295,8 +2314,8 @@ AbstractCase[] switchStatementColon(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endswitch' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2340,8 +2359,8 @@ Expression SwitchLabel() :
     if (errorMessage != null) throw e;
     errorMessage = "expression expected after 'case' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2350,8 +2369,8 @@ Expression SwitchLabel() :
   } catch (ParseException e) {
     errorMessage = "':' expected after case expression";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 |
@@ -2362,8 +2381,8 @@ Expression SwitchLabel() :
   } catch (ParseException e) {
     errorMessage = "':' expected after 'default' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2380,8 +2399,8 @@ Break BreakStatement() :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'break' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new Break(expression, start, SimpleCharStream.getPosition());}
@@ -2389,7 +2408,7 @@ Break BreakStatement() :
 
 IfStatement IfStatement() :
 {
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
   Expression condition;
   IfStatement ifStatement;
 }
@@ -2409,21 +2428,21 @@ Expression Condition(final String keyword) :
   } catch (ParseException e) {
     errorMessage = "'(' expected after " + keyword + " keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
     errorEnd   = errorStart +1;
     processParseException(e);
   }
   condition = Expression()
   try {
      <RPAREN>
-     {return condition;}
   } catch (ParseException e) {
     errorMessage = "')' expected after " + keyword + " keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
+  {return condition;}
 }
 
 IfStatement IfStatement0(Expression condition, final int start,final int end) :
@@ -2463,8 +2482,8 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
   } catch (ParseException e) {
     errorMessage = "'endif' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2472,8 +2491,8 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endif' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
     {
@@ -2491,10 +2510,10 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
       stmts.toArray(statementsArray);
       return new IfStatement(condition,
                              new Block(statementsArray,pos,endStatements),
-                              elseIfs,
-                              elseStatement,
-                              pos,
-                              SimpleCharStream.getPosition());
+                             elseIfs,
+                             elseStatement,
+                             pos,
+                             SimpleCharStream.getPosition());
     }
     }
 
@@ -2513,8 +2532,8 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
       }
       errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
       throw e;
     }
   ]
@@ -2612,8 +2631,8 @@ Statement WhileStatement0(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "'endwhile' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2625,8 +2644,8 @@ Statement WhileStatement0(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endwhile' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 |
@@ -2648,8 +2667,8 @@ DoStatement DoStatement() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2668,8 +2687,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "'(' expected after 'foreach' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2677,8 +2696,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "variable expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2686,8 +2705,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "'as' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2695,8 +2714,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "variable expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2704,8 +2723,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "')' expected after 'foreach' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2714,8 +2733,8 @@ ForeachStatement ForeachStatement() :
     if (errorMessage != null) throw e;
     errorMessage = "statement expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new ForeachStatement(expression,
@@ -2730,9 +2749,9 @@ ForStatement ForStatement() :
 {
 final Token token;
 final int pos = SimpleCharStream.getPosition();
-Statement[] initializations = null;
+Expression[] initializations = null;
 Expression condition = null;
-Statement[] increments = null;
+Expression[] increments = null;
 Statement action;
 final ArrayList list = new ArrayList();
 final int startBlock, endBlock;
@@ -2744,8 +2763,8 @@ final int startBlock, endBlock;
   } catch (ParseException e) {
     errorMessage = "'(' expected after 'for' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
      [ initializations = ForInit() ] <SEMICOLON>
@@ -2776,8 +2795,8 @@ final int startBlock, endBlock;
       } catch (ParseException e) {
         errorMessage = "'endfor' expected";
         errorLevel   = ERROR;
-        errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-        errorEnd   = jj_input_stream.getPosition() + 1;
+        errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+        errorEnd   = SimpleCharStream.getPosition() + 1;
         throw e;
       }
       try {
@@ -2789,38 +2808,38 @@ final int startBlock, endBlock;
       } catch (ParseException e) {
         errorMessage = "';' expected after 'endfor' keyword";
         errorLevel   = ERROR;
-        errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-        errorEnd   = jj_input_stream.getPosition() + 1;
+        errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+        errorEnd   = SimpleCharStream.getPosition() + 1;
         throw e;
       }
     )
 }
 
-Statement[] ForInit() :
+Expression[] ForInit() :
 {
-  Statement[] statements;
+  Expression[] exprs;
 }
 {
   LOOKAHEAD(LocalVariableDeclaration())
-  statements = LocalVariableDeclaration()
-  {return statements;}
+  exprs = LocalVariableDeclaration()
+  {return exprs;}
 |
-  statements = StatementExpressionList()
-  {return statements;}
+  exprs = StatementExpressionList()
+  {return exprs;}
 }
 
-Statement[] StatementExpressionList() :
+Expression[] StatementExpressionList() :
 {
   final ArrayList list = new ArrayList();
-  Statement expr;
+  Expression expr;
 }
 {
   expr = StatementExpression()   {list.add(expr);}
   (<COMMA> StatementExpression() {list.add(expr);})*
   {
-  Statement[] stmtsArray = new Statement[list.size()];
-  list.toArray(stmtsArray);
-  return stmtsArray;}
+  Expression[] exprsArray = new Expression[list.size()];
+  list.toArray(exprsArray);
+  return exprsArray;}
 }
 
 Continue ContinueStatement() :
@@ -2836,8 +2855,8 @@ Continue ContinueStatement() :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'continue' statement";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2855,8 +2874,8 @@ ReturnStatement ReturnStatement() :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'return' statement";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
\ No newline at end of file