* Added browser like links (Ctrl+Mouseclick on identifier; same as F3 shortcut)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Parser.java
1 /***********************************************************************************************************************************
2  * Copyright (c) 2002 www.phpeclipse.de All rights reserved. This program and the accompanying material are made available under the
3  * terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4  * http://www.eclipse.org/legal/cpl-v10.html
5  * 
6  * Contributors: www.phpeclipse.de
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
9
10 import java.util.ArrayList;
11
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
16 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
17 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
19 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
21 import net.sourceforge.phpdt.internal.compiler.util.Util;
22 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
23 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
24 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
25 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
31 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
32 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
43
44 import org.eclipse.core.resources.IFile;
45 import org.eclipse.core.resources.IProject;
46 import org.eclipse.core.resources.IResource;
47 import org.eclipse.core.runtime.IPath;
48
49 public class Parser //extends PHPParserSuperclass
50     implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
51   //internal data for the automat
52   protected final static int StackIncrement = 255;
53
54   protected int stateStackTop;
55
56   protected int[] stack = new int[StackIncrement];
57
58   public int firstToken; // handle for multiple parsing goals
59
60   public int lastAct; //handle for multiple parsing goals
61
62   protected RecoveredElement currentElement;
63
64   public static boolean VERBOSE_RECOVERY = false;
65
66   protected boolean diet = false; //tells the scanner to jump over some
67
68   // parts of the code/expressions like
69   // method bodies
70   //scanner token
71   public Scanner scanner;
72
73   private ArrayList phpList;
74
75   private int currentPHPString;
76
77   private boolean phpEnd;
78
79   // private static HashMap keywordMap = null;
80   private String str;
81
82   // current character
83   //  char ch;
84   // current token
85   int token;
86
87   // row counter for syntax errors:
88   //int rowCount;
89   // column counter for syntax errors:
90   //int columnCount;
91   //int chIndx;
92   //
93   //    // current identifier
94   //    String identifier;
95   Long longNumber;
96
97   Double doubleNumber;
98
99   private String stringValue;
100
101   /** Contains the current expression. */
102   // private StringBuffer expression;
103   //private boolean phpMode;
104   protected int modifiers;
105
106   protected int modifiersSourceStart;
107
108   //  protected IdentifierIndexManager indexManager;
109
110   protected Parser(ProblemReporter problemReporter) {
111     this.problemReporter = problemReporter;
112     this.options = problemReporter.options;
113     this.currentPHPString = 0;
114     //          PHPParserSuperclass.fileToParse = fileToParse;
115     this.phpList = null;
116     //    this.indexManager = null;
117     this.str = "";
118     this.token = TokenNameEOF;
119     //    this.chIndx = 0;
120     //    this.rowCount = 1;
121     //    this.columnCount = 0;
122     this.phpEnd = false;
123     //   getNextToken();
124     this.initializeScanner();
125   }
126
127   public void setFileToParse(IFile fileToParse) {
128     this.currentPHPString = 0;
129     //    PHPParserSuperclass.fileToParse = fileToParse;
130     this.phpList = null;
131     //    this.indexManager = null;
132     this.str = "";
133     this.token = TokenNameEOF;
134     this.phpEnd = false;
135     this.initializeScanner();
136   }
137
138   /**
139    * ClassDeclaration Constructor.
140    * 
141    * @param s
142    * @param sess
143    *          Description of Parameter
144    * @see
145    */
146   public Parser(IFile fileToParse) {
147     //    if (keywordMap == null) {
148     //      keywordMap = new HashMap();
149     //      for (int i = 0; i < PHP_KEYWORS.length; i++) {
150     //        keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
151     //      }
152     //    }
153     this.currentPHPString = 0;
154     //    PHPParserSuperclass.fileToParse = fileToParse;
155     this.phpList = null;
156     this.includesList = null;
157     this.str = "";
158     this.token = TokenNameEOF;
159     //    this.chIndx = 0;
160     //    this.rowCount = 1;
161     //    this.columnCount = 0;
162     this.phpEnd = false;
163     //   getNextToken();
164     this.initializeScanner();
165   }
166
167   public void initializeScanner() {
168     this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
169         .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
170         this.options.taskTags/* taskTags */, 
171         this.options.taskPriorites/* taskPriorities */,
172         true/*isTaskCaseSensitive*/);
173   }
174
175   /**
176    * Create marker for the parse error
177    */
178   //  private void setMarker(String message, int charStart, int charEnd, int
179   // errorLevel) {
180   //    setMarker(fileToParse, message, charStart, charEnd, errorLevel);
181   //  }
182   /**
183    * This method will throw the SyntaxError. It will add the good lines and columns to the Error
184    * 
185    * @param error
186    *          the error message
187    * @throws SyntaxError
188    *           the error raised
189    */
190   private void throwSyntaxError(String error) {
191     int problemStartPosition = scanner.getCurrentTokenStartPosition();
192     int problemEndPosition = scanner.getCurrentTokenEndPosition();
193     throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
194   }
195
196   /**
197    * This method will throw the SyntaxError. It will add the good lines and columns to the Error
198    * 
199    * @param error
200    *          the error message
201    * @throws SyntaxError
202    *           the error raised
203    */
204   //  private void throwSyntaxError(String error, int startRow) {
205   //    throw new SyntaxError(startRow, 0, " ", error);
206   //  }
207   private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
208     problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
209         compilationUnit.compilationResult);
210     throw new SyntaxError(1, 0, " ", error);
211   }
212
213   private void reportSyntaxError(String error) {
214     int problemStartPosition = scanner.getCurrentTokenStartPosition();
215     int problemEndPosition = scanner.getCurrentTokenEndPosition();
216     reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
217   }
218   
219   private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
220     problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
221         compilationUnit.compilationResult);
222   }
223
224   private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
225     problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
226         compilationUnit.compilationResult);
227   }
228
229   /**
230    * gets the next token from input
231    */
232   private void getNextToken() {
233     try {
234       token = scanner.getNextToken();
235       if (Scanner.DEBUG) {
236         int currentEndPosition = scanner.getCurrentTokenEndPosition();
237         int currentStartPosition = scanner.getCurrentTokenStartPosition();
238         System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
239         System.out.println(scanner.toStringAction(token));
240       }
241     } catch (InvalidInputException e) {
242       token = TokenNameERROR;
243       String detailedMessage = e.getMessage();
244
245       if (detailedMessage == Scanner.UNTERMINATED_STRING) {
246         throwSyntaxError("Unterminated string.");
247       } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
248         throwSyntaxError("Unterminated commment.");
249       }
250     }
251     return;
252   }
253
254   public void init(String s) {
255     this.str = s;
256     this.token = TokenNameEOF;
257     //    this.chIndx = 0;
258     //    this.rowCount = 1;
259     //    this.columnCount = 0;
260     this.phpEnd = false;
261     //    this.phpMode = false;
262     /* scanner initialization */
263     scanner.setSource(s.toCharArray());
264     scanner.setPHPMode(false);
265   }
266
267   protected void initialize(boolean phpMode) {
268     initialize(phpMode, null);
269   }
270
271   protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
272     compilationUnit = null;
273     referenceContext = null;
274     includesList = new ArrayList();
275     //    this.indexManager = indexManager;
276     this.str = "";
277     this.token = TokenNameEOF;
278     //    this.chIndx = 0;
279     //    this.rowCount = 1;
280     //    this.columnCount = 0;
281     this.phpEnd = false;
282     //    this.phpMode = phpMode;
283     scanner.setPHPMode(phpMode);
284   }
285
286   /**
287    * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt; &lt;/body&gt;'
288    */
289   public void parse(String s) {
290     init(s);
291     parse();
292   }
293
294   /**
295    * Parses a string with php tags i.e. '&lt;body&gt; &lt;?php phpinfo() ?&gt; &lt;/body&gt;'
296    */
297   protected void parse() {
298     getNextToken();
299     do {
300       try {
301         if (token != TokenNameEOF && token != TokenNameERROR) {
302           statementList();
303         }
304         if (token != TokenNameEOF) {
305           if (token == TokenNameERROR) {
306             throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
307           }
308           if (token == TokenNameRPAREN) {
309             throwSyntaxError("Too many closing ')'; end-of-file not reached.");
310           }
311           if (token == TokenNameRBRACE) {
312             throwSyntaxError("Too many closing '}'; end-of-file not reached.");
313           }
314           if (token == TokenNameRBRACKET) {
315             throwSyntaxError("Too many closing ']'; end-of-file not reached.");
316           }
317           if (token == TokenNameLPAREN) {
318             throwSyntaxError("Read character '('; end-of-file not reached.");
319           }
320           if (token == TokenNameLBRACE) {
321             throwSyntaxError("Read character '{';  end-of-file not reached.");
322           }
323           if (token == TokenNameLBRACKET) {
324             throwSyntaxError("Read character '[';  end-of-file not reached.");
325           }
326           throwSyntaxError("End-of-file not reached.");
327         }
328         break;
329       } catch (SyntaxError sytaxErr1) {
330         // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
331         // ERROR);
332         //        setMarker(sytaxErr1.getMessage(),
333         // scanner.getCurrentTokenStartPosition(),
334         // scanner.getCurrentTokenEndPosition(), ERROR);
335         try {
336           // if an error occured,
337           // try to find keywords 'class' or 'function'
338           // to parse the rest of the string
339           while (token != TokenNameEOF && token != TokenNameERROR) {
340             if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
341               break;
342             }
343             getNextToken();
344           }
345           if (token == TokenNameEOF || token == TokenNameERROR) {
346             break;
347           }
348         } catch (SyntaxError sytaxErr2) {
349           //    setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
350           // ERROR);
351           //          setMarker(sytaxErr2.getMessage(),
352           // scanner.getCurrentTokenStartPosition(),
353           // scanner.getCurrentTokenEndPosition(), ERROR);
354           break;
355         }
356       }
357     } while (true);
358
359     endParse(0);
360   }
361
362   protected CompilationUnitDeclaration endParse(int act) {
363
364     this.lastAct = act;
365
366     if (currentElement != null) {
367       currentElement.topElement().updateParseTree();
368       if (VERBOSE_RECOVERY) {
369         System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
370         System.out.println("--------------------------"); //$NON-NLS-1$
371         System.out.println(compilationUnit);
372         System.out.println("----------------------------------"); //$NON-NLS-1$
373       }
374     } else {
375       if (diet & VERBOSE_RECOVERY) {
376         System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
377         System.out.println("--------------------------"); //$NON-NLS-1$
378         System.out.println(compilationUnit);
379         System.out.println("----------------------------------"); //$NON-NLS-1$
380       }
381     }
382     if (scanner.recordLineSeparator) {
383       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
384     }
385     if (scanner.taskTags != null) {
386       for (int i = 0; i < scanner.foundTaskCount; i++) {
387         problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
388             scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
389             scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
390       }
391     }
392     compilationUnit.imports = new ImportReference[includesList.size()];
393     for (int i = 0; i < includesList.size(); i++) {
394       compilationUnit.imports[i] = (ImportReference) includesList.get(i);
395     }
396     return compilationUnit;
397   }
398
399   //  public PHPOutlineInfo parseInfo(Object parent, String s) {
400   //    PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
401   //    // Stack stack = new Stack();
402   //    // stack.push(outlineInfo.getDeclarations());
403   //    this.str = s;
404   //    this.token = TokenNameEOF;
405   //    // this.chIndx = 0;
406   //    // this.rowCount = 1;
407   //    // this.columnCount = 0;
408   //    this.phpEnd = false;
409   //    this.phpMode = false;
410   //    scanner.setSource(s.toCharArray());
411   //    scanner.setPHPMode(false);
412   //    
413   //    getNextToken();
414   //    parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
415   //    
416   //    return outlineInfo;
417   //  }
418   private boolean isVariable() {
419     return token == TokenNameVariable; //  || token == TokenNamethis;
420   }
421
422   //  private void parseDeclarations(PHPOutlineInfo outlineInfo,
423   //      OutlineableWithChildren current, boolean goBack) {
424   //    char[] ident;
425   //    // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
426   //    PHPSegmentWithChildren temp;
427   //    int counter = 0;
428   //    IPreferenceStore store =
429   // PHPeclipsePlugin.getDefault().getPreferenceStore();
430   //    try {
431   //      while (token != TokenNameEOF && token != TokenNameERROR) {
432   //        if (token == TokenNameVariable) {
433   //          ident = scanner.getCurrentIdentifierSource();
434   //          outlineInfo.addVariable(new String(ident));
435   //          getNextToken();
436   //        } else if (token == TokenNamevar) {
437   //          getNextToken();
438   //          if (token == TokenNameVariable
439   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
440   //            ident = scanner.getCurrentIdentifierSource();
441   //            //substring(1) added because PHPVarDeclaration doesn't
442   //            // need the $ anymore
443   //            String variableName = new String(ident).substring(1);
444   //            outlineInfo.addVariable(variableName);
445   //            getNextToken();
446   //            if (token != TokenNameSEMICOLON) {
447   //              getNextToken();
448   //              ident = scanner.getCurrentTokenSource();
449   //              if (token > TokenNameKEYWORD) {
450   //                current.add(new PHPVarDeclaration(current, variableName,
451   //                // chIndx - ident.length,
452   //                    scanner.getCurrentTokenStartPosition(), new String(ident)));
453   //              } else {
454   //                switch (token) {
455   //                  case TokenNameVariable :
456   //                  case TokenNamethis :
457   //                    current.add(new PHPVarDeclaration(current, variableName,
458   //                    // chIndx -
459   //                        // ident.length,
460   //                        scanner.getCurrentTokenStartPosition(), new String(
461   //                            ident)));
462   //                    break;
463   //                  case TokenNameIdentifier :
464   //                    current.add(new PHPVarDeclaration(current, variableName,
465   //                    // chIndx -
466   //                        // ident.length,
467   //                        scanner.getCurrentTokenStartPosition(), new String(
468   //                            ident)));
469   //                    break;
470   //                  case TokenNameDoubleLiteral :
471   //                    current.add(new PHPVarDeclaration(current, variableName
472   //                        + doubleNumber,
473   //                    // chIndx -
474   //                        // ident.length,
475   //                        scanner.getCurrentTokenStartPosition(), new String(
476   //                            ident)));
477   //                    break;
478   //                  case TokenNameIntegerLiteral :
479   //                    current.add(new PHPVarDeclaration(current, variableName,
480   //                    // chIndx -
481   //                        // ident.length,
482   //                        scanner.getCurrentTokenStartPosition(), new String(
483   //                            ident)));
484   //                    break;
485   //                  case TokenNameStringInterpolated :
486   //                  case TokenNameStringLiteral :
487   //                    current.add(new PHPVarDeclaration(current, variableName,
488   //                    // chIndx -
489   //                        // ident.length,
490   //                        scanner.getCurrentTokenStartPosition(), new String(
491   //                            ident)));
492   //                    break;
493   //                  case TokenNameStringConstant :
494   //                    current.add(new PHPVarDeclaration(current, variableName,
495   //                    // chIndx -
496   //                        // ident.length,
497   //                        scanner.getCurrentTokenStartPosition(), new String(
498   //                            ident)));
499   //                    break;
500   //                  default :
501   //                    current.add(new PHPVarDeclaration(current, variableName,
502   //                    // chIndx -
503   //                        // ident.length
504   //                        scanner.getCurrentTokenStartPosition()));
505   //                    break;
506   //                }
507   //              }
508   //            } else {
509   //              ident = scanner.getCurrentIdentifierSource();
510   //              current.add(new PHPVarDeclaration(current, variableName,
511   //              // chIndx - ident.length
512   //                  scanner.getCurrentTokenStartPosition()));
513   //            }
514   //          }
515   //        } else if (token == TokenNamefunction) {
516   //          getNextToken();
517   //          if (token == TokenNameAND) {
518   //            getNextToken();
519   //          }
520   //          if (token == TokenNameIdentifier
521   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
522   //            ident = scanner.getCurrentIdentifierSource();
523   //            outlineInfo.addVariable(new String(ident));
524   //            temp = new PHPFunctionDeclaration(current, new String(ident),
525   //            // chIndx - ident.length
526   //                scanner.getCurrentTokenStartPosition());
527   //            current.add(temp);
528   //            getNextToken();
529   //            parseDeclarations(outlineInfo, temp, true);
530   //          }
531   //        } else if (token == TokenNameclass) {
532   //          getNextToken();
533   //          if (token == TokenNameIdentifier
534   //              && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
535   //            ident = scanner.getCurrentIdentifierSource();
536   //            outlineInfo.addVariable(new String(ident));
537   //            temp = new PHPClassDeclaration(current, new String(ident),
538   //            // chIndx - ident.len
539   //                scanner.getCurrentTokenStartPosition());
540   //            current.add(temp);
541   //            // stack.push(temp);
542   //            getNextToken();
543   //            //skip tokens for classname, extends and others until
544   //            // we have the opening '{'
545   //            while (token != TokenNameLBRACE && token != TokenNameEOF
546   //                && token != TokenNameERROR) {
547   //              getNextToken();
548   //            }
549   //            parseDeclarations(outlineInfo, temp, true);
550   //            // stack.pop();
551   //          }
552   //        } else if ((token == TokenNameLBRACE)
553   //            || (token == TokenNameDOLLAR_LBRACE)) {
554   //          getNextToken();
555   //          counter++;
556   //        } else if (token == TokenNameRBRACE) {
557   //          getNextToken();
558   //          --counter;
559   //          if (counter == 0 && goBack) {
560   //            return;
561   //          }
562   //        } else if (token == TokenNamerequire || token == TokenNamerequire_once
563   //            || token == TokenNameinclude || token == TokenNameinclude_once) {
564   //          ident = scanner.getCurrentTokenSource();
565   //          getNextToken();
566   //          int startPosition = scanner.getCurrentTokenStartPosition();
567   //          expr();
568   //          char[] expr = scanner.getCurrentTokenSource(startPosition);
569   //          outlineInfo.addVariable(new String(ident));
570   //          current.add(new PHPReqIncDeclaration(current, new String(ident),
571   //          // chIndx - ident.length,
572   //              startPosition, new String(expr)));
573   //          getNextToken();
574   //        } else {
575   //          getNextToken();
576   //        }
577   //      }
578   //    } catch (SyntaxError sytaxErr) {
579   //      // try {
580   //      // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
581   //      // setMarker(sytaxErr.getMessage(),
582   //      // scanner.getCurrentTokenStartPosition(),
583   //      // scanner.getCurrentTokenEndPosition(), ERROR);
584   //      // } catch (CoreException e) {
585   //      // }
586   //    }
587   //  }
588   private void statementList() {
589     do {
590       statement(TokenNameEOF);
591       if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
592           || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
593           || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
594           || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
595         return;
596       }
597     } while (true);
598   }
599
600   private void functionBody(MethodDeclaration methodDecl) {
601     // '{' [statement-list] '}'
602     if (token == TokenNameLBRACE) {
603       getNextToken();
604     } else {
605       throwSyntaxError("'{' expected in compound-statement.");
606     }
607     if (token != TokenNameRBRACE) {
608       statementList();
609     }
610     if (token == TokenNameRBRACE) {
611       methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
612       getNextToken();
613     } else {
614       throwSyntaxError("'}' expected in compound-statement.");
615     }
616   }
617
618   private Statement statement(int previousToken) {
619     Statement statement = null;
620     Expression expression;
621     int sourceStart = scanner.getCurrentTokenStartPosition();
622     if (token == TokenNameif) {
623       getNextToken();
624       if (token == TokenNameLPAREN) {
625         getNextToken();
626       } else {
627         throwSyntaxError("'(' expected after 'if' keyword.");
628       }
629       expression = expr();
630       if (token == TokenNameRPAREN) {
631         getNextToken();
632       } else {
633         throwSyntaxError("')' expected after 'if' condition.");
634       }
635       ifStatement();
636       return new IfStatement(expression, statement, sourceStart, scanner.getCurrentTokenEndPosition());
637     } else if (token == TokenNameswitch) {
638       getNextToken();
639       if (token == TokenNameLPAREN) {
640         getNextToken();
641       } else {
642         throwSyntaxError("'(' expected after 'switch' keyword.");
643       }
644       expr();
645       if (token == TokenNameRPAREN) {
646         getNextToken();
647       } else {
648         throwSyntaxError("')' expected after 'switch' condition.");
649       }
650       switchStatement();
651       return statement;
652     } else if (token == TokenNamefor) {
653       getNextToken();
654       if (token == TokenNameLPAREN) {
655         getNextToken();
656       } else {
657         throwSyntaxError("'(' expected after 'for' keyword.");
658       }
659       if (token == TokenNameSEMICOLON) {
660         getNextToken();
661       } else {
662         expressionList();
663         if (token == TokenNameSEMICOLON) {
664           getNextToken();
665         } else {
666           throwSyntaxError("';' expected after 'for'.");
667         }
668       }
669       if (token == TokenNameSEMICOLON) {
670         getNextToken();
671       } else {
672         expressionList();
673         if (token == TokenNameSEMICOLON) {
674           getNextToken();
675         } else {
676           throwSyntaxError("';' expected after 'for'.");
677         }
678       }
679       if (token == TokenNameRPAREN) {
680         getNextToken();
681       } else {
682         expressionList();
683         if (token == TokenNameRPAREN) {
684           getNextToken();
685         } else {
686           throwSyntaxError("')' expected after 'for'.");
687         }
688       }
689       forStatement();
690       return statement;
691     } else if (token == TokenNamewhile) {
692       getNextToken();
693       if (token == TokenNameLPAREN) {
694         getNextToken();
695       } else {
696         throwSyntaxError("'(' expected after 'while' keyword.");
697       }
698       expr();
699       if (token == TokenNameRPAREN) {
700         getNextToken();
701       } else {
702         throwSyntaxError("')' expected after 'while' condition.");
703       }
704       whileStatement();
705       return statement;
706     } else if (token == TokenNamedo) {
707       getNextToken();
708       if (token == TokenNameLBRACE) {
709         getNextToken();
710         if (token != TokenNameRBRACE) {
711           statementList();
712         }
713         if (token == TokenNameRBRACE) {
714           getNextToken();
715         } else {
716           throwSyntaxError("'}' expected after 'do' keyword.");
717         }
718       } else {
719         statement(TokenNameEOF);
720       }
721       if (token == TokenNamewhile) {
722         getNextToken();
723         if (token == TokenNameLPAREN) {
724           getNextToken();
725         } else {
726           throwSyntaxError("'(' expected after 'while' keyword.");
727         }
728         expr();
729         if (token == TokenNameRPAREN) {
730           getNextToken();
731         } else {
732           throwSyntaxError("')' expected after 'while' condition.");
733         }
734       } else {
735         throwSyntaxError("'while' expected after 'do' keyword.");
736       }
737       if (token == TokenNameSEMICOLON) {
738         getNextToken();
739       } else {
740         if (token != TokenNameINLINE_HTML) {
741           throwSyntaxError("';' expected after do-while statement.");
742         }
743         getNextToken();
744       }
745       return statement;
746     } else if (token == TokenNameforeach) {
747       getNextToken();
748       if (token == TokenNameLPAREN) {
749         getNextToken();
750       } else {
751         throwSyntaxError("'(' expected after 'foreach' keyword.");
752       }
753       expr();
754       if (token == TokenNameas) {
755         getNextToken();
756       } else {
757         throwSyntaxError("'as' expected after 'foreach' exxpression.");
758       }
759       //      variable();
760       foreach_variable();
761       foreach_optional_arg();
762       if (token == TokenNameEQUAL_GREATER) {
763         getNextToken();
764         variable();
765       }
766       if (token == TokenNameRPAREN) {
767         getNextToken();
768       } else {
769         throwSyntaxError("')' expected after 'foreach' expression.");
770       }
771       foreachStatement();
772       return statement;
773     } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
774       getNextToken();
775       if (token != TokenNameSEMICOLON) {
776         expr();
777       }
778       if (token == TokenNameSEMICOLON) {
779         getNextToken();
780       } else {
781         if (token != TokenNameINLINE_HTML) {
782           throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
783         }
784         getNextToken();
785       }
786       return statement;
787     } else if (token == TokenNameecho) {
788       getNextToken();
789       expressionList();
790       if (token == TokenNameSEMICOLON) {
791         getNextToken();
792       } else {
793         if (token != TokenNameINLINE_HTML) {
794           throwSyntaxError("';' expected after 'echo' statement.");
795         }
796         getNextToken();
797       }
798       return statement;
799     } else if (token == TokenNameINLINE_HTML) {
800       getNextToken();
801       return statement;
802       //    } else if (token == TokenNameprint) {
803       //      getNextToken();
804       //      expression();
805       //      if (token == TokenNameSEMICOLON) {
806       //        getNextToken();
807       //      } else {
808       //        if (token != TokenNameStopPHP) {
809       //          throwSyntaxError("';' expected after 'print' statement.");
810       //        }
811       //        getNextToken();
812       //      }
813       //      return;
814     } else if (token == TokenNameglobal) {
815       getNextToken();
816       global_var_list();
817       if (token == TokenNameSEMICOLON) {
818         getNextToken();
819       } else {
820         if (token != TokenNameINLINE_HTML) {
821           throwSyntaxError("';' expected after 'global' statement.");
822         }
823         getNextToken();
824       }
825       return statement;
826     } else if (token == TokenNamestatic) {
827       getNextToken();
828       static_var_list();
829       if (token == TokenNameSEMICOLON) {
830         getNextToken();
831       } else {
832         if (token != TokenNameINLINE_HTML) {
833           throwSyntaxError("';' expected after 'static' statement.");
834         }
835         getNextToken();
836       }
837       return statement;
838     } else if (token == TokenNameunset) {
839       getNextToken();
840       if (token == TokenNameLPAREN) {
841         getNextToken();
842       } else {
843         throwSyntaxError("'(' expected after 'unset' statement.");
844       }
845       unset_variables();
846       if (token == TokenNameRPAREN) {
847         getNextToken();
848       } else {
849         throwSyntaxError("')' expected after 'unset' statement.");
850       }
851       if (token == TokenNameSEMICOLON) {
852         getNextToken();
853       } else {
854         if (token != TokenNameINLINE_HTML) {
855           throwSyntaxError("';' expected after 'unset' statement.");
856         }
857         getNextToken();
858       }
859       return statement;
860     } else if (token == TokenNamefunction) {
861       MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
862       methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
863       methodDecl.modifiers = AccDefault;
864       getNextToken();
865       functionDefinition(methodDecl);
866       return statement;
867     } else if (token == TokenNamedeclare) {
868       //T_DECLARE '(' declare_list ')' declare_statement
869       getNextToken();
870       if (token != TokenNameLPAREN) {
871         throwSyntaxError("'(' expected in 'declare' statement.");
872       }
873       getNextToken();
874       declare_list();
875       if (token != TokenNameRPAREN) {
876         throwSyntaxError("')' expected in 'declare' statement.");
877       }
878       getNextToken();
879       declare_statement();
880       return statement;
881     } else if (token == TokenNametry) {
882       getNextToken();
883       if (token != TokenNameLBRACE) {
884         throwSyntaxError("'{' expected in 'try' statement.");
885       }
886       getNextToken();
887       statementList();
888       if (token != TokenNameRBRACE) {
889         throwSyntaxError("'}' expected in 'try' statement.");
890       }
891       getNextToken();
892       return statement;
893     } else if (token == TokenNamecatch) {
894       getNextToken();
895       if (token != TokenNameLPAREN) {
896         throwSyntaxError("'(' expected in 'catch' statement.");
897       }
898       getNextToken();
899       fully_qualified_class_name();
900       if (token != TokenNameVariable) {
901         throwSyntaxError("Variable expected in 'catch' statement.");
902       }
903       getNextToken();
904       if (token != TokenNameRPAREN) {
905         throwSyntaxError("')' expected in 'catch' statement.");
906       }
907       getNextToken();
908       if (token != TokenNameLBRACE) {
909         throwSyntaxError("'{' expected in 'catch' statement.");
910       }
911       getNextToken();
912       if (token != TokenNameRBRACE) {
913         statementList();
914         if (token != TokenNameRBRACE) {
915           throwSyntaxError("'}' expected in 'catch' statement.");
916         }
917       }
918       getNextToken();
919       additional_catches();
920       return statement;
921     } else if (token == TokenNamethrow) {
922       getNextToken();
923       expr();
924       if (token == TokenNameSEMICOLON) {
925         getNextToken();
926       } else {
927         throwSyntaxError("';' expected after 'throw' exxpression.");
928       }
929       return statement;
930     } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
931       TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
932       typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
933       typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
934       typeDecl.name = new char[] { ' ' };
935       // default super class
936       typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
937       compilationUnit.types.add(typeDecl);
938       try {
939         pushOnAstStack(typeDecl);
940         unticked_class_declaration_statement(typeDecl);
941         //        classBody(typeDecl);
942       } finally {
943         astPtr--;
944         astLengthPtr--;
945       }
946       return statement;
947       //      } else {
948       //        throwSyntaxError("Unexpected keyword '" + keyword + "'");
949     } else if (token == TokenNameLBRACE) {
950       getNextToken();
951       if (token != TokenNameRBRACE) {
952         statementList();
953       }
954       if (token == TokenNameRBRACE) {
955         getNextToken();
956         return statement;
957       } else {
958         throwSyntaxError("'}' expected.");
959       }
960     } else {
961       if (token != TokenNameSEMICOLON) {
962         expr();
963       }
964       if (token == TokenNameSEMICOLON) {
965         getNextToken();
966         return statement;
967       } else {
968         if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
969           throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
970         }
971         getNextToken();
972       }
973     }
974     // may be null
975     return statement;
976   }
977
978   private void declare_statement() {
979     //  statement
980     //| ':' inner_statement_list T_ENDDECLARE ';'
981     //;
982     if (token == TokenNameCOLON) {
983       getNextToken();
984       // TODO: implement inner_statement_list();
985       statementList();
986       if (token != TokenNameenddeclare) {
987         throwSyntaxError("'enddeclare' expected in 'declare' statement.");
988       }
989       getNextToken();
990       if (token != TokenNameSEMICOLON) {
991         throwSyntaxError("';' expected after 'enddeclare' keyword.");
992       }
993       getNextToken();
994     } else {
995       statement(TokenNameRPAREN);
996     }
997   }
998
999   private void declare_list() {
1000     //  T_STRING '=' static_scalar
1001     //| declare_list ',' T_STRING '=' static_scalar
1002     while (true) {
1003       if (token != TokenNameIdentifier) {
1004         throwSyntaxError("Identifier expected in 'declare' list.");
1005       }
1006       getNextToken();
1007       if (token != TokenNameEQUAL) {
1008         throwSyntaxError("'=' expected in 'declare' list.");
1009       }
1010       getNextToken();
1011       static_scalar();
1012       if (token != TokenNameCOMMA) {
1013         break;
1014       }
1015       getNextToken();
1016     }
1017   }
1018
1019   private void additional_catches() {
1020     while (token == TokenNamecatch) {
1021       getNextToken();
1022       if (token != TokenNameLPAREN) {
1023         throwSyntaxError("'(' expected in 'catch' statement.");
1024       }
1025       getNextToken();
1026       fully_qualified_class_name();
1027       if (token != TokenNameVariable) {
1028         throwSyntaxError("Variable expected in 'catch' statement.");
1029       }
1030       getNextToken();
1031       if (token != TokenNameRPAREN) {
1032         throwSyntaxError("')' expected in 'catch' statement.");
1033       }
1034       getNextToken();
1035       if (token != TokenNameLBRACE) {
1036         throwSyntaxError("'{' expected in 'catch' statement.");
1037       }
1038       getNextToken();
1039       if (token != TokenNameRBRACE) {
1040         statementList();
1041       }
1042       if (token != TokenNameRBRACE) {
1043         throwSyntaxError("'}' expected in 'catch' statement.");
1044       }
1045       getNextToken();
1046     }
1047   }
1048
1049   private void foreach_variable() {
1050     //  w_variable
1051     //| '&' w_variable
1052     if (token == TokenNameAND) {
1053       getNextToken();
1054     }
1055     w_variable();
1056   }
1057
1058   private void foreach_optional_arg() {
1059     //  /* empty */
1060     //| T_DOUBLE_ARROW foreach_variable
1061     if (token == TokenNameEQUAL_GREATER) {
1062       getNextToken();
1063       foreach_variable();
1064     }
1065   }
1066
1067   private void global_var_list() {
1068     //  global_var_list:
1069     //  global_var_list ',' global_var
1070     //| global_var
1071     while (true) {
1072       global_var();
1073       if (token != TokenNameCOMMA) {
1074         break;
1075       }
1076       getNextToken();
1077     }
1078   }
1079
1080   private void global_var() {
1081     //global_var:
1082     //  T_VARIABLE
1083     //| '$' r_variable
1084     //| '$' '{' expr '}'
1085     if (token == TokenNameVariable) {
1086       getNextToken();
1087     } else if (token == TokenNameDOLLAR) {
1088       getNextToken();
1089       if (token == TokenNameLPAREN) {
1090         getNextToken();
1091         expr();
1092         if (token != TokenNameLPAREN) {
1093           throwSyntaxError("')' expected in global variable.");
1094         }
1095         getNextToken();
1096       } else {
1097         r_variable();
1098       }
1099     }
1100   }
1101
1102   private void static_var_list() {
1103     //static_var_list:
1104     //  static_var_list ',' T_VARIABLE
1105     //| static_var_list ',' T_VARIABLE '=' static_scalar
1106     //| T_VARIABLE
1107     //| T_VARIABLE '=' static_scalar
1108     while (true) {
1109       if (token == TokenNameVariable) {
1110         getNextToken();
1111         if (token == TokenNameEQUAL) {
1112           getNextToken();
1113           static_scalar();
1114         }
1115         if (token != TokenNameCOMMA) {
1116           break;
1117         }
1118         getNextToken();
1119       } else {
1120         break;
1121       }
1122     }
1123   }
1124
1125   private void unset_variables() {
1126     //    unset_variables:
1127     //                  unset_variable
1128     //          | unset_variables ',' unset_variable
1129     //    unset_variable:
1130     //                  variable
1131     while (true) {
1132       variable();
1133       if (token != TokenNameCOMMA) {
1134         break;
1135       }
1136       getNextToken();
1137     }
1138   }
1139
1140   private final void initializeModifiers() {
1141     this.modifiers = 0;
1142     this.modifiersSourceStart = -1;
1143   }
1144
1145   private final void checkAndSetModifiers(int flag) {
1146     this.modifiers |= flag;
1147     if (this.modifiersSourceStart < 0)
1148       this.modifiersSourceStart = this.scanner.startPosition;
1149   }
1150
1151   private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1152     initializeModifiers();
1153     if (token == TokenNameinterface) {
1154       //      interface_entry T_STRING
1155       //                interface_extends_list
1156       //                '{' class_statement_list '}'
1157       checkAndSetModifiers(AccInterface);
1158       getNextToken();
1159       typeDecl.modifiers = this.modifiers;
1160       typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1161       typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1162       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1163         typeDecl.name = scanner.getCurrentIdentifierSource();
1164         if (token > TokenNameKEYWORD) {
1165           problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1166               scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1167           //          throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1168           //              typeDecl.sourceStart, typeDecl.sourceEnd);
1169         }
1170         getNextToken();
1171         interface_extends_list();
1172       } else {
1173         typeDecl.name = new char[] { ' ' };
1174         throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1175         return;
1176       }
1177     } else {
1178       //      class_entry_type T_STRING extends_from
1179       //                implements_list
1180       //                '{' class_statement_list'}'
1181       class_entry_type();
1182       typeDecl.modifiers = this.modifiers;
1183       typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1184       typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1185       //identifier
1186       //identifier 'extends' identifier
1187       if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1188         typeDecl.name = scanner.getCurrentIdentifierSource();
1189         if (token > TokenNameKEYWORD) {
1190           problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1191               scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1192           //          throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1193           //              typeDecl.sourceStart, typeDecl.sourceEnd);
1194         }
1195         getNextToken();
1196         //    extends_from:
1197         //              /* empty */
1198         //      | T_EXTENDS fully_qualified_class_name
1199         if (token == TokenNameextends) {
1200           interface_extends_list();
1201           //          getNextToken();
1202           //          if (token != TokenNameIdentifier) {
1203           //            throwSyntaxError("Class name expected after keyword
1204           // 'extends'.",
1205           //                scanner.getCurrentTokenStartPosition(), scanner
1206           //                    .getCurrentTokenEndPosition());
1207           //          }
1208         }
1209         implements_list();
1210       } else {
1211         typeDecl.name = new char[] { ' ' };
1212         throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1213         return;
1214       }
1215     }
1216     //  '{' class_statement_list '}'
1217     if (token == TokenNameLBRACE) {
1218       getNextToken();
1219       if (token != TokenNameRBRACE) {
1220         ArrayList list = new ArrayList();
1221         class_statement_list(list);
1222         typeDecl.fields = new FieldDeclaration[list.size()];
1223         for (int i = 0; i < list.size(); i++) {
1224           typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1225         }
1226       }
1227       if (token == TokenNameRBRACE) {
1228         typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1229         getNextToken();
1230       } else {
1231         throwSyntaxError("'}' expected at end of class body.");
1232       }
1233     } else {
1234       throwSyntaxError("'{' expected at start of class body.");
1235     }
1236   }
1237
1238   private void class_entry_type() {
1239     //  T_CLASS
1240     //  | T_ABSTRACT T_CLASS
1241     //  | T_FINAL T_CLASS
1242     if (token == TokenNameclass) {
1243       getNextToken();
1244     } else if (token == TokenNameabstract) {
1245       checkAndSetModifiers(AccAbstract);
1246       getNextToken();
1247       if (token != TokenNameclass) {
1248         throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1249       }
1250       getNextToken();
1251     } else if (token == TokenNamefinal) {
1252       checkAndSetModifiers(AccFinal);
1253       getNextToken();
1254       if (token != TokenNameclass) {
1255         throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1256       }
1257       getNextToken();
1258     } else {
1259       throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1260     }
1261   }
1262
1263   private void interface_extends_list() {
1264     //  /* empty */
1265     //  | T_EXTENDS interface_list
1266     if (token == TokenNameextends) {
1267       getNextToken();
1268       interface_list();
1269     }
1270   }
1271
1272   private void implements_list() {
1273     //  /* empty */
1274     //  | T_IMPLEMENTS interface_list
1275     if (token == TokenNameimplements) {
1276       getNextToken();
1277       interface_list();
1278     }
1279   }
1280
1281   private void interface_list() {
1282     //  interface_list:
1283     //  fully_qualified_class_name
1284     //| interface_list ',' fully_qualified_class_name
1285     do {
1286       if (token == TokenNameIdentifier) {
1287         getNextToken();
1288       } else {
1289         throwSyntaxError("Interface name expected after keyword 'implements'.");
1290       }
1291       if (token != TokenNameCOMMA) {
1292         return;
1293       }
1294       getNextToken();
1295     } while (true);
1296   }
1297
1298   //  private void classBody(TypeDeclaration typeDecl) {
1299   //    //'{' [class-element-list] '}'
1300   //    if (token == TokenNameLBRACE) {
1301   //      getNextToken();
1302   //      if (token != TokenNameRBRACE) {
1303   //        class_statement_list();
1304   //      }
1305   //      if (token == TokenNameRBRACE) {
1306   //        typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1307   //        getNextToken();
1308   //      } else {
1309   //        throwSyntaxError("'}' expected at end of class body.");
1310   //      }
1311   //    } else {
1312   //      throwSyntaxError("'{' expected at start of class body.");
1313   //    }
1314   //  }
1315   private void class_statement_list(ArrayList list) {
1316     do {
1317       class_statement(list);
1318     } while (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1319         || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1320         || token == TokenNameconst);
1321   }
1322
1323   private void class_statement(ArrayList list) {
1324     //    class_statement:
1325     //          variable_modifiers class_variable_declaration ';'
1326     //  | class_constant_declaration ';'
1327     //  | method_modifiers T_FUNCTION is_reference T_STRING
1328     //    '(' parameter_list ')' method_body
1329     initializeModifiers();
1330     int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1331
1332     if (token == TokenNamevar) {
1333       checkAndSetModifiers(AccPublic);
1334       problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1335           referenceContext, compilationUnit.compilationResult);
1336       getNextToken();
1337       class_variable_declaration(declarationSourceStart, list);
1338     } else if (token == TokenNameconst) {
1339       checkAndSetModifiers(AccFinal | AccPublic);
1340       class_constant_declaration(declarationSourceStart, list);
1341       if (token != TokenNameSEMICOLON) {
1342         throwSyntaxError("';' expected after class const declaration.");
1343       }
1344       getNextToken();
1345     } else {
1346       boolean hasModifiers = member_modifiers();
1347       if (token == TokenNamefunction) {
1348         if (!hasModifiers) {
1349           checkAndSetModifiers(AccPublic);
1350         }
1351         MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1352         methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1353         methodDecl.modifiers = this.modifiers;
1354         getNextToken();
1355         functionDefinition(methodDecl);
1356       } else {
1357         if (!hasModifiers) {
1358           throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1359         }
1360         class_variable_declaration(declarationSourceStart, list);
1361       }
1362     }
1363   }
1364
1365   private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1366     //  class_constant_declaration ',' T_STRING '=' static_scalar
1367     //  | T_CONST T_STRING '=' static_scalar
1368     if (token != TokenNameconst) {
1369       throwSyntaxError("'const' keyword expected in class declaration.");
1370     } else {
1371       getNextToken();
1372     }
1373     while (true) {
1374       if (token != TokenNameIdentifier) {
1375         throwSyntaxError("Identifier expected in class const declaration.");
1376       }
1377       FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1378           .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1379       fieldDeclaration.modifiers = this.modifiers;
1380       fieldDeclaration.declarationSourceStart = declarationSourceStart;
1381       fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1382       fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1383       //        fieldDeclaration.type
1384       list.add(fieldDeclaration);
1385       getNextToken();
1386       if (token != TokenNameEQUAL) {
1387         throwSyntaxError("'=' expected in class const declaration.");
1388       }
1389       getNextToken();
1390       static_scalar();
1391       if (token != TokenNameCOMMA) {
1392         break; // while(true)-loop
1393       }
1394       getNextToken();
1395     }
1396   }
1397
1398   //  private void variable_modifiers() {
1399   //    // variable_modifiers:
1400   //    // non_empty_member_modifiers
1401   //    //| T_VAR
1402   //    initializeModifiers();
1403   //    if (token == TokenNamevar) {
1404   //      checkAndSetModifiers(AccPublic);
1405   //      reportSyntaxError(
1406   //          "Keyword 'var' is deprecated. Please use 'public' 'private' or
1407   // 'protected'
1408   // modifier for field declarations.",
1409   //          scanner.getCurrentTokenStartPosition(), scanner
1410   //              .getCurrentTokenEndPosition());
1411   //      getNextToken();
1412   //    } else {
1413   //      if (!member_modifiers()) {
1414   //        throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1415   // field declarations.");
1416   //      }
1417   //    }
1418   //  }
1419   //  private void method_modifiers() {
1420   //    //method_modifiers:
1421   //    // /* empty */
1422   //    //| non_empty_member_modifiers
1423   //    initializeModifiers();
1424   //    if (!member_modifiers()) {
1425   //      checkAndSetModifiers(AccPublic);
1426   //    }
1427   //  }
1428   private boolean member_modifiers() {
1429     //  T_PUBLIC
1430     //| T_PROTECTED
1431     //| T_PRIVATE
1432     //| T_STATIC
1433     //| T_ABSTRACT
1434     //| T_FINAL
1435     boolean foundToken = false;
1436     while (true) {
1437       if (token == TokenNamepublic) {
1438         checkAndSetModifiers(AccPublic);
1439         getNextToken();
1440         foundToken = true;
1441       } else if (token == TokenNameprotected) {
1442         checkAndSetModifiers(AccProtected);
1443         getNextToken();
1444         foundToken = true;
1445       } else if (token == TokenNameprivate) {
1446         checkAndSetModifiers(AccPrivate);
1447         getNextToken();
1448         foundToken = true;
1449       } else if (token == TokenNamestatic) {
1450         checkAndSetModifiers(AccStatic);
1451         getNextToken();
1452         foundToken = true;
1453       } else if (token == TokenNameabstract) {
1454         checkAndSetModifiers(AccAbstract);
1455         getNextToken();
1456         foundToken = true;
1457       } else if (token == TokenNamefinal) {
1458         checkAndSetModifiers(AccFinal);
1459         getNextToken();
1460         foundToken = true;
1461       } else {
1462         break;
1463       }
1464     }
1465     return foundToken;
1466   }
1467
1468   private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1469     //    class_variable_declaration:
1470     //          class_variable_declaration ',' T_VARIABLE
1471     //  | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1472     //  | T_VARIABLE
1473     //  | T_VARIABLE '=' static_scalar
1474     char[] classVariable;
1475     do {
1476       if (token == TokenNameVariable) {
1477         classVariable = scanner.getCurrentIdentifierSource();
1478         //  indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1479         FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1480             .getCurrentTokenEndPosition());
1481         fieldDeclaration.modifiers = this.modifiers;
1482         fieldDeclaration.declarationSourceStart = declarationSourceStart;
1483         fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1484         fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1485         //        fieldDeclaration.type
1486         list.add(fieldDeclaration);
1487         getNextToken();
1488         if (token == TokenNameEQUAL) {
1489           getNextToken();
1490           static_scalar();
1491         }
1492       } else {
1493         //        if (token == TokenNamethis) {
1494         //          throwSyntaxError("'$this' not allowed after keyword 'public'
1495         // 'protected' 'private' 'var'.");
1496         //        }
1497         throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1498       }
1499       if (token != TokenNameCOMMA) {
1500         break;
1501       }
1502       getNextToken();
1503     } while (true);
1504     if (token != TokenNameSEMICOLON) {
1505       throwSyntaxError("';' expected after field declaration.");
1506     }
1507     getNextToken();
1508   }
1509
1510   private void functionDefinition(MethodDeclaration methodDecl) {
1511     boolean isAbstract = false;
1512     if (astPtr == 0) {
1513       compilationUnit.types.add(methodDecl);
1514     } else {
1515       ASTNode node = astStack[astPtr];
1516       if (node instanceof TypeDeclaration) {
1517         TypeDeclaration typeDecl = ((TypeDeclaration) node);
1518         if (typeDecl.methods == null) {
1519           typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1520         } else {
1521           AbstractMethodDeclaration[] newMethods;
1522           System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 1,
1523               typeDecl.methods.length);
1524           newMethods[0] = methodDecl;
1525           typeDecl.methods = newMethods;
1526         }
1527         if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1528           isAbstract = true;
1529         } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1530           isAbstract = true;
1531         }
1532       }
1533     }
1534     functionDeclarator(methodDecl);
1535     if (token == TokenNameSEMICOLON) {
1536       if (!isAbstract) {
1537         throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1538       }
1539       getNextToken();
1540       return;
1541     }
1542     functionBody(methodDecl);
1543   }
1544
1545   private void functionDeclarator(MethodDeclaration methodDecl) {
1546     //identifier '(' [parameter-list] ')'
1547     if (token == TokenNameAND) {
1548       getNextToken();
1549     }
1550     methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1551     methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1552     if (Scanner.isIdentifierOrKeyword(token)) {
1553       methodDecl.selector = scanner.getCurrentIdentifierSource();
1554       if (token > TokenNameKEYWORD) {
1555         problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1556             scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1557         //        reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
1558         //          scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1559       }
1560       getNextToken();
1561       if (token == TokenNameLPAREN) {
1562         getNextToken();
1563       } else {
1564         throwSyntaxError("'(' expected in function declaration.");
1565       }
1566       if (token != TokenNameRPAREN) {
1567         parameter_list();
1568       }
1569       if (token != TokenNameRPAREN) {
1570         throwSyntaxError("')' expected in function declaration.");
1571       } else {
1572         methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1573         getNextToken();
1574       }
1575     } else {
1576       methodDecl.selector = "<undefined>".toCharArray();
1577       throwSyntaxError("Function name expected after keyword 'function'.");
1578     }
1579   }
1580
1581   //
1582   private void parameter_list() {
1583     //  non_empty_parameter_list
1584     //  | /* empty */
1585     non_empty_parameter_list(true);
1586   }
1587
1588   private void non_empty_parameter_list(boolean empty_allowed) {
1589     //  optional_class_type T_VARIABLE
1590     //  | optional_class_type '&' T_VARIABLE
1591     //  | optional_class_type '&' T_VARIABLE '=' static_scalar
1592     //  | optional_class_type T_VARIABLE '=' static_scalar
1593     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1594     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1595     //  | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1596     // static_scalar
1597     //  | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1598     // static_scalar
1599     if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1600       while (true) {
1601         if (token == TokenNameIdentifier) {
1602           getNextToken();
1603         }
1604         if (token == TokenNameAND) {
1605           getNextToken();
1606         }
1607         if (token == TokenNameVariable) {
1608           getNextToken();
1609           if (token == TokenNameEQUAL) {
1610             getNextToken();
1611             static_scalar();
1612           }
1613         } else {
1614           throwSyntaxError("Variable expected in parameter list.");
1615         }
1616         if (token != TokenNameCOMMA) {
1617           break;
1618         }
1619         getNextToken();
1620       }
1621       return;
1622     }
1623     if (!empty_allowed) {
1624       throwSyntaxError("Identifier expected in parameter list.");
1625     }
1626   }
1627
1628   private void optional_class_type() {
1629     //  /* empty */
1630     //| T_STRING
1631   }
1632
1633   private void parameterDeclaration() {
1634     //variable
1635     //variable-reference
1636     if (token == TokenNameAND) {
1637       getNextToken();
1638       if (isVariable()) {
1639         getNextToken();
1640       } else {
1641         throwSyntaxError("Variable expected after reference operator '&'.");
1642       }
1643     }
1644     //variable '=' constant
1645     if (token == TokenNameVariable) {
1646       getNextToken();
1647       if (token == TokenNameEQUAL) {
1648         getNextToken();
1649         static_scalar();
1650       }
1651       return;
1652     }
1653     //    if (token == TokenNamethis) {
1654     //      throwSyntaxError("Reserved word '$this' not allowed in parameter
1655     // declaration.");
1656     //    }
1657   }
1658
1659   private void labeledStatementList() {
1660     if (token != TokenNamecase && token != TokenNamedefault) {
1661       throwSyntaxError("'case' or 'default' expected.");
1662     }
1663     do {
1664       if (token == TokenNamecase) {
1665         getNextToken();
1666         expr(); //constant();
1667         if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1668           getNextToken();
1669           if (token == TokenNamecase || token == TokenNamedefault) {
1670             // empty case statement ?
1671             continue;
1672           }
1673           statementList();
1674         }
1675         //        else if (token == TokenNameSEMICOLON) {
1676         //          setMarker(
1677         //            "':' expected after 'case' keyword (Found token: " +
1678         // scanner.toStringAction(token) + ")",
1679         //            scanner.getCurrentTokenStartPosition(),
1680         //            scanner.getCurrentTokenEndPosition(),
1681         //            INFO);
1682         //          getNextToken();
1683         //          if (token == TokenNamecase) { // empty case statement ?
1684         //            continue;
1685         //          }
1686         //          statementList();
1687         //        }
1688         else {
1689           throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1690         }
1691       } else { // TokenNamedefault
1692         getNextToken();
1693         if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1694           getNextToken();
1695           if (token == TokenNameRBRACE) {
1696             // empty default case
1697             break;
1698           }
1699           if (token != TokenNamecase) {
1700             statementList();
1701           }
1702         } else {
1703           throwSyntaxError("':' character expected after 'default'.");
1704         }
1705       }
1706     } while (token == TokenNamecase || token == TokenNamedefault);
1707   }
1708
1709   //  public void labeledStatement() {
1710   //    if (token == TokenNamecase) {
1711   //      getNextToken();
1712   //      constant();
1713   //      if (token == TokenNameDDOT) {
1714   //        getNextToken();
1715   //        statement();
1716   //      } else {
1717   //        throwSyntaxError("':' character after 'case' constant expected.");
1718   //      }
1719   //      return;
1720   //    } else if (token == TokenNamedefault) {
1721   //      getNextToken();
1722   //      if (token == TokenNameDDOT) {
1723   //        getNextToken();
1724   //        statement();
1725   //      } else {
1726   //        throwSyntaxError("':' character after 'default' expected.");
1727   //      }
1728   //      return;
1729   //    }
1730   //  }
1731   //  public void expressionStatement() {
1732   //  }
1733   //  private void inclusionStatement() {
1734   //  }
1735   //  public void compoundStatement() {
1736   //  }
1737   //  public void selectionStatement() {
1738   //  }
1739   //
1740   //  public void iterationStatement() {
1741   //  }
1742   //
1743   //  public void jumpStatement() {
1744   //  }
1745   //
1746   //  public void outputStatement() {
1747   //  }
1748   //
1749   //  public void scopeStatement() {
1750   //  }
1751   //
1752   //  public void flowStatement() {
1753   //  }
1754   //
1755   //  public void definitionStatement() {
1756   //  }
1757   private void ifStatement() {
1758     // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
1759     if (token == TokenNameCOLON) {
1760       getNextToken();
1761       if (token != TokenNameendif) {
1762         statementList();
1763         switch (token) {
1764         case TokenNameelse:
1765           getNextToken();
1766           if (token == TokenNameCOLON) {
1767             getNextToken();
1768             if (token != TokenNameendif) {
1769               statementList();
1770             }
1771           } else {
1772             if (token == TokenNameif) { //'else if'
1773               getNextToken();
1774               elseifStatementList();
1775             } else {
1776               throwSyntaxError("':' expected after 'else'.");
1777             }
1778           }
1779           break;
1780         case TokenNameelseif:
1781           getNextToken();
1782           elseifStatementList();
1783           break;
1784         }
1785       }
1786       if (token != TokenNameendif) {
1787         throwSyntaxError("'endif' expected.");
1788       }
1789       getNextToken();
1790       if (token != TokenNameSEMICOLON) {
1791         throwSyntaxError("';' expected after if-statement.");
1792       }
1793       getNextToken();
1794     } else {
1795       // statement [else-statement]
1796       statement(TokenNameEOF);
1797       if (token == TokenNameelseif) {
1798         getNextToken();
1799         if (token == TokenNameLPAREN) {
1800           getNextToken();
1801         } else {
1802           throwSyntaxError("'(' expected after 'elseif' keyword.");
1803         }
1804         expr();
1805         if (token == TokenNameRPAREN) {
1806           getNextToken();
1807         } else {
1808           throwSyntaxError("')' expected after 'elseif' condition.");
1809         }
1810         ifStatement();
1811       } else if (token == TokenNameelse) {
1812         getNextToken();
1813         statement(TokenNameEOF);
1814       }
1815     }
1816   }
1817
1818   private void elseifStatementList() {
1819     do {
1820       elseifStatement();
1821       switch (token) {
1822       case TokenNameelse:
1823         getNextToken();
1824         if (token == TokenNameCOLON) {
1825           getNextToken();
1826           if (token != TokenNameendif) {
1827             statementList();
1828           }
1829           return;
1830         } else {
1831           if (token == TokenNameif) { //'else if'
1832             getNextToken();
1833           } else {
1834             throwSyntaxError("':' expected after 'else'.");
1835           }
1836         }
1837         break;
1838       case TokenNameelseif:
1839         getNextToken();
1840         break;
1841       default:
1842         return;
1843       }
1844     } while (true);
1845   }
1846
1847   private void elseifStatement() {
1848     if (token == TokenNameLPAREN) {
1849       getNextToken();
1850       expr();
1851       if (token != TokenNameRPAREN) {
1852         throwSyntaxError("')' expected in else-if-statement.");
1853       }
1854       getNextToken();
1855       if (token != TokenNameCOLON) {
1856         throwSyntaxError("':' expected in else-if-statement.");
1857       }
1858       getNextToken();
1859       if (token != TokenNameendif) {
1860         statementList();
1861       }
1862     }
1863   }
1864
1865   private void switchStatement() {
1866     if (token == TokenNameCOLON) {
1867       // ':' [labeled-statement-list] 'endswitch' ';'
1868       getNextToken();
1869       labeledStatementList();
1870       if (token != TokenNameendswitch) {
1871         throwSyntaxError("'endswitch' expected.");
1872       }
1873       getNextToken();
1874       if (token != TokenNameSEMICOLON) {
1875         throwSyntaxError("';' expected after switch-statement.");
1876       }
1877       getNextToken();
1878     } else {
1879       // '{' [labeled-statement-list] '}'
1880       if (token != TokenNameLBRACE) {
1881         throwSyntaxError("'{' expected in switch statement.");
1882       }
1883       getNextToken();
1884       if (token != TokenNameRBRACE) {
1885         labeledStatementList();
1886       }
1887       if (token != TokenNameRBRACE) {
1888         throwSyntaxError("'}' expected in switch statement.");
1889       }
1890       getNextToken();
1891     }
1892   }
1893
1894   private void forStatement() {
1895     if (token == TokenNameCOLON) {
1896       getNextToken();
1897       statementList();
1898       if (token != TokenNameendfor) {
1899         throwSyntaxError("'endfor' expected.");
1900       }
1901       getNextToken();
1902       if (token != TokenNameSEMICOLON) {
1903         throwSyntaxError("';' expected after for-statement.");
1904       }
1905       getNextToken();
1906     } else {
1907       statement(TokenNameEOF);
1908     }
1909   }
1910
1911   private void whileStatement() {
1912     // ':' statement-list 'endwhile' ';'
1913     if (token == TokenNameCOLON) {
1914       getNextToken();
1915       statementList();
1916       if (token != TokenNameendwhile) {
1917         throwSyntaxError("'endwhile' expected.");
1918       }
1919       getNextToken();
1920       if (token != TokenNameSEMICOLON) {
1921         throwSyntaxError("';' expected after while-statement.");
1922       }
1923       getNextToken();
1924     } else {
1925       statement(TokenNameEOF);
1926     }
1927   }
1928
1929   private void foreachStatement() {
1930     if (token == TokenNameCOLON) {
1931       getNextToken();
1932       statementList();
1933       if (token != TokenNameendforeach) {
1934         throwSyntaxError("'endforeach' expected.");
1935       }
1936       getNextToken();
1937       if (token != TokenNameSEMICOLON) {
1938         throwSyntaxError("';' expected after foreach-statement.");
1939       }
1940       getNextToken();
1941     } else {
1942       statement(TokenNameEOF);
1943     }
1944   }
1945
1946   //  private void exitStatus() {
1947   //    if (token == TokenNameLPAREN) {
1948   //      getNextToken();
1949   //    } else {
1950   //      throwSyntaxError("'(' expected in 'exit-status'.");
1951   //    }
1952   //    if (token != TokenNameRPAREN) {
1953   //      expression();
1954   //    }
1955   //    if (token == TokenNameRPAREN) {
1956   //      getNextToken();
1957   //    } else {
1958   //      throwSyntaxError("')' expected after 'exit-status'.");
1959   //    }
1960   //  }
1961   private void expressionList() {
1962     do {
1963       expr();
1964       if (token == TokenNameCOMMA) {
1965         getNextToken();
1966       } else {
1967         break;
1968       }
1969     } while (true);
1970   }
1971
1972   private Expression expr() {
1973     //  r_variable
1974     //  | expr_without_variable
1975     //    if (token!=TokenNameEOF) {
1976     if (Scanner.TRACE) {
1977       System.out.println("TRACE: expr()");
1978     }
1979     return expr_without_variable(true);
1980     //    }
1981   }
1982
1983   private Expression expr_without_variable(boolean only_variable) {
1984     int exprSourceStart = scanner.getCurrentTokenStartPosition();
1985     int exprSourceEnd = scanner.getCurrentTokenEndPosition();
1986     Expression expression = new Expression();
1987     expression.sourceStart = exprSourceStart;
1988     // default, may be overwritten
1989     expression.sourceEnd = exprSourceEnd;
1990     //          internal_functions_in_yacc
1991     //  | T_CLONE expr
1992     //  | T_PRINT expr
1993     //  | '(' expr ')'
1994     //  | '@' expr
1995     //  | '+' expr
1996     //  | '-' expr
1997     //  | '!' expr
1998     //  | '~' expr
1999     //  | T_INC rw_variable
2000     //  | T_DEC rw_variable
2001     //  | T_INT_CAST expr
2002     //  | T_DOUBLE_CAST expr
2003     //  | T_STRING_CAST expr
2004     //  | T_ARRAY_CAST expr
2005     //  | T_OBJECT_CAST expr
2006     //  | T_BOOL_CAST expr
2007     //  | T_UNSET_CAST expr
2008     //  | T_EXIT exit_expr
2009     //  | scalar
2010     //  | T_ARRAY '(' array_pair_list ')'
2011     //  | '`' encaps_list '`'
2012     //  | T_LIST '(' assignment_list ')' '=' expr
2013     //  | T_NEW class_name_reference ctor_arguments
2014     //  | variable '=' expr
2015     //  | variable '=' '&' variable
2016     //  | variable '=' '&' T_NEW class_name_reference ctor_arguments
2017     //  | variable T_PLUS_EQUAL expr
2018     //  | variable T_MINUS_EQUAL expr
2019     //  | variable T_MUL_EQUAL expr
2020     //  | variable T_DIV_EQUAL expr
2021     //  | variable T_CONCAT_EQUAL expr
2022     //  | variable T_MOD_EQUAL expr
2023     //  | variable T_AND_EQUAL expr
2024     //  | variable T_OR_EQUAL expr
2025     //  | variable T_XOR_EQUAL expr
2026     //  | variable T_SL_EQUAL expr
2027     //  | variable T_SR_EQUAL expr
2028     //  | rw_variable T_INC
2029     //  | rw_variable T_DEC
2030     //  | expr T_BOOLEAN_OR expr
2031     //  | expr T_BOOLEAN_AND expr
2032     //  | expr T_LOGICAL_OR expr
2033     //  | expr T_LOGICAL_AND expr
2034     //  | expr T_LOGICAL_XOR expr
2035     //  | expr '|' expr
2036     //  | expr '&' expr
2037     //  | expr '^' expr
2038     //  | expr '.' expr
2039     //  | expr '+' expr
2040     //  | expr '-' expr
2041     //  | expr '*' expr
2042     //  | expr '/' expr
2043     //  | expr '%' expr
2044     //  | expr T_SL expr
2045     //  | expr T_SR expr
2046     //  | expr T_IS_IDENTICAL expr
2047     //  | expr T_IS_NOT_IDENTICAL expr
2048     //  | expr T_IS_EQUAL expr
2049     //  | expr T_IS_NOT_EQUAL expr
2050     //  | expr '<' expr
2051     //  | expr T_IS_SMALLER_OR_EQUAL expr
2052     //  | expr '>' expr
2053     //  | expr T_IS_GREATER_OR_EQUAL expr
2054     //  | expr T_INSTANCEOF class_name_reference
2055     //  | expr '?' expr ':' expr
2056     if (Scanner.TRACE) {
2057       System.out.println("TRACE: expr_without_variable() PART 1");
2058     }
2059     switch (token) {
2060     case TokenNameisset:
2061     case TokenNameempty:
2062     case TokenNameeval:
2063     case TokenNameinclude:
2064     case TokenNameinclude_once:
2065     case TokenNamerequire:
2066     case TokenNamerequire_once:
2067       internal_functions_in_yacc();
2068       break;
2069     //          | '(' expr ')'
2070     case TokenNameLPAREN:
2071       getNextToken();
2072       expr();
2073       if (token == TokenNameRPAREN) {
2074         getNextToken();
2075       } else {
2076         throwSyntaxError("')' expected in expression.");
2077       }
2078       break;
2079     //    | T_CLONE expr
2080     //    | T_PRINT expr
2081     //    | '@' expr
2082     //    | '+' expr
2083     //    | '-' expr
2084     //    | '!' expr
2085     //    | '~' expr
2086     //    | T_INT_CAST expr
2087     //  | T_DOUBLE_CAST expr
2088     //  | T_STRING_CAST expr
2089     //  | T_ARRAY_CAST expr
2090     //  | T_OBJECT_CAST expr
2091     //  | T_BOOL_CAST expr
2092     //  | T_UNSET_CAST expr
2093     case TokenNameclone:
2094     case TokenNameprint:
2095     case TokenNameAT:
2096     case TokenNamePLUS:
2097     case TokenNameMINUS:
2098     case TokenNameNOT:
2099     case TokenNameTWIDDLE:
2100     case TokenNameintCAST:
2101     case TokenNamedoubleCAST:
2102     case TokenNamestringCAST:
2103     case TokenNamearrayCAST:
2104     case TokenNameobjectCAST:
2105     case TokenNameboolCAST:
2106     case TokenNameunsetCAST:
2107       getNextToken();
2108       expr();
2109       break;
2110     case TokenNameexit:
2111       getNextToken();
2112       exit_expr();
2113       break;
2114     //  scalar:
2115     //  T_STRING
2116     //| T_STRING_VARNAME
2117     //| class_constant
2118     //| T_START_HEREDOC encaps_list T_END_HEREDOC
2119     //          | '`' encaps_list '`'
2120     //  | common_scalar
2121     //  | '`' encaps_list '`'
2122     case TokenNameEncapsedString0:
2123       scanner.encapsedStringStack.push(new Character('`'));
2124       getNextToken();
2125       try {
2126         if (token == TokenNameEncapsedString0) {
2127         } else {
2128           encaps_list();
2129           if (token != TokenNameEncapsedString0) {
2130             throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2131           }
2132         }
2133       } finally {
2134         scanner.encapsedStringStack.pop();
2135         getNextToken();
2136       }
2137       break;
2138     //      | '\'' encaps_list '\''
2139     case TokenNameEncapsedString1:
2140       scanner.encapsedStringStack.push(new Character('\''));
2141       getNextToken();
2142       try {
2143         exprSourceStart = scanner.getCurrentTokenStartPosition();
2144         if (token == TokenNameEncapsedString1) {
2145           expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2146               .getCurrentTokenEndPosition());
2147         } else {
2148           encaps_list();
2149           if (token != TokenNameEncapsedString1) {
2150             throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2151           } else {
2152             expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2153                 .getCurrentTokenEndPosition());
2154           }
2155         }
2156       } finally {
2157         scanner.encapsedStringStack.pop();
2158         getNextToken();
2159       }
2160       break;
2161     //| '"' encaps_list '"'
2162     case TokenNameEncapsedString2:
2163       scanner.encapsedStringStack.push(new Character('"'));
2164       getNextToken();
2165       try {
2166         exprSourceStart = scanner.getCurrentTokenStartPosition();
2167         if (token == TokenNameEncapsedString2) {
2168           expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2169               .getCurrentTokenEndPosition());
2170         } else {
2171           encaps_list();
2172           if (token != TokenNameEncapsedString2) {
2173             throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2174           } else {
2175             expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2176                 .getCurrentTokenEndPosition());
2177           }
2178         }
2179       } finally {
2180         scanner.encapsedStringStack.pop();
2181         getNextToken();
2182       }
2183       break;
2184     case TokenNameStringDoubleQuote:
2185       expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2186           .getCurrentTokenEndPosition());
2187       common_scalar();
2188       break;
2189     case TokenNameStringSingleQuote:
2190       expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2191           .getCurrentTokenEndPosition());
2192       common_scalar();
2193       break;
2194     case TokenNameIntegerLiteral:
2195     case TokenNameDoubleLiteral:
2196     case TokenNameStringInterpolated:
2197     case TokenNameFILE:
2198     case TokenNameLINE:
2199     case TokenNameCLASS_C:
2200     case TokenNameMETHOD_C:
2201     case TokenNameFUNC_C:
2202       common_scalar();
2203       break;
2204     case TokenNameHEREDOC:
2205       getNextToken();
2206       break;
2207     case TokenNamearray:
2208       //    T_ARRAY '(' array_pair_list ')'
2209       getNextToken();
2210       if (token == TokenNameLPAREN) {
2211         getNextToken();
2212         if (token == TokenNameRPAREN) {
2213           getNextToken();
2214           break;
2215         }
2216         array_pair_list();
2217         if (token != TokenNameRPAREN) {
2218           throwSyntaxError("')' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2219         }
2220         getNextToken();
2221       } else {
2222         throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2223       }
2224       break;
2225     case TokenNamelist:
2226       //    | T_LIST '(' assignment_list ')' '=' expr
2227       getNextToken();
2228       if (token == TokenNameLPAREN) {
2229         getNextToken();
2230         assignment_list();
2231         if (token != TokenNameRPAREN) {
2232           throwSyntaxError("')' expected after 'list' keyword.");
2233         }
2234         getNextToken();
2235         if (token != TokenNameEQUAL) {
2236           throwSyntaxError("'=' expected after 'list' keyword.");
2237         }
2238         getNextToken();
2239         expr();
2240       } else {
2241         throwSyntaxError("'(' expected after 'list' keyword.");
2242       }
2243       break;
2244     case TokenNamenew:
2245       //        | T_NEW class_name_reference ctor_arguments
2246       getNextToken();
2247       class_name_reference();
2248       ctor_arguments();
2249       break;
2250     //          | T_INC rw_variable
2251     //          | T_DEC rw_variable
2252     case TokenNamePLUS_PLUS:
2253     case TokenNameMINUS_MINUS:
2254       getNextToken();
2255       rw_variable();
2256       break;
2257     //  | variable '=' expr
2258     //  | variable '=' '&' variable
2259     //  | variable '=' '&' T_NEW class_name_reference ctor_arguments
2260     //  | variable T_PLUS_EQUAL expr
2261     //  | variable T_MINUS_EQUAL expr
2262     //  | variable T_MUL_EQUAL expr
2263     //  | variable T_DIV_EQUAL expr
2264     //  | variable T_CONCAT_EQUAL expr
2265     //  | variable T_MOD_EQUAL expr
2266     //  | variable T_AND_EQUAL expr
2267     //  | variable T_OR_EQUAL expr
2268     //  | variable T_XOR_EQUAL expr
2269     //  | variable T_SL_EQUAL expr
2270     //  | variable T_SR_EQUAL expr
2271     //  | rw_variable T_INC
2272     //  | rw_variable T_DEC
2273     case TokenNameIdentifier:
2274     case TokenNameVariable:
2275     case TokenNameDOLLAR:
2276       variable();
2277       switch (token) {
2278       case TokenNameEQUAL:
2279         getNextToken();
2280         if (token == TokenNameAND) {
2281           getNextToken();
2282           if (token == TokenNamenew) {
2283             // | variable '=' '&' T_NEW class_name_reference
2284             // ctor_arguments
2285             getNextToken();
2286             class_name_reference();
2287             ctor_arguments();
2288           } else {
2289             variable();
2290           }
2291         } else {
2292           expr();
2293         }
2294         break;
2295       case TokenNamePLUS_EQUAL:
2296       case TokenNameMINUS_EQUAL:
2297       case TokenNameMULTIPLY_EQUAL:
2298       case TokenNameDIVIDE_EQUAL:
2299       case TokenNameDOT_EQUAL:
2300       case TokenNameREMAINDER_EQUAL:
2301       case TokenNameAND_EQUAL:
2302       case TokenNameOR_EQUAL:
2303       case TokenNameXOR_EQUAL:
2304       case TokenNameRIGHT_SHIFT_EQUAL:
2305       case TokenNameLEFT_SHIFT_EQUAL:
2306         getNextToken();
2307         expr();
2308         break;
2309       case TokenNamePLUS_PLUS:
2310       case TokenNameMINUS_MINUS:
2311         getNextToken();
2312         break;
2313       default:
2314         if (!only_variable) {
2315           throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2316         }
2317       }
2318       break;
2319     default:
2320       if (token != TokenNameINLINE_HTML) {
2321         if (token > TokenNameKEYWORD) {
2322           getNextToken();
2323           break;
2324         } else {
2325           throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2326         }
2327       }
2328       return expression;
2329     }
2330     if (Scanner.TRACE) {
2331       System.out.println("TRACE: expr_without_variable() PART 2");
2332     }
2333     //  | expr T_BOOLEAN_OR expr
2334     //  | expr T_BOOLEAN_AND expr
2335     //  | expr T_LOGICAL_OR expr
2336     //  | expr T_LOGICAL_AND expr
2337     //  | expr T_LOGICAL_XOR expr
2338     //  | expr '|' expr
2339     //  | expr '&' expr
2340     //  | expr '^' expr
2341     //  | expr '.' expr
2342     //  | expr '+' expr
2343     //  | expr '-' expr
2344     //  | expr '*' expr
2345     //  | expr '/' expr
2346     //  | expr '%' expr
2347     //  | expr T_SL expr
2348     //  | expr T_SR expr
2349     //  | expr T_IS_IDENTICAL expr
2350     //  | expr T_IS_NOT_IDENTICAL expr
2351     //  | expr T_IS_EQUAL expr
2352     //  | expr T_IS_NOT_EQUAL expr
2353     //  | expr '<' expr
2354     //  | expr T_IS_SMALLER_OR_EQUAL expr
2355     //  | expr '>' expr
2356     //  | expr T_IS_GREATER_OR_EQUAL expr
2357     while (true) {
2358       switch (token) {
2359       case TokenNameOR_OR:
2360         getNextToken();
2361         expression = new OR_OR_Expression(expression, expr(), token);
2362         break;
2363       case TokenNameAND_AND:
2364         getNextToken();
2365         expression = new AND_AND_Expression(expression, expr(), token);
2366         break;
2367       case TokenNameEQUAL_EQUAL:
2368         getNextToken();
2369         expression = new EqualExpression(expression, expr(), token);
2370         break;
2371       case TokenNameand:
2372       case TokenNameor:
2373       case TokenNamexor:
2374       case TokenNameAND:
2375       case TokenNameOR:
2376       case TokenNameXOR:
2377       case TokenNameDOT:
2378       case TokenNamePLUS:
2379       case TokenNameMINUS:
2380       case TokenNameMULTIPLY:
2381       case TokenNameDIVIDE:
2382       case TokenNameREMAINDER:
2383       case TokenNameLEFT_SHIFT:
2384       case TokenNameRIGHT_SHIFT:
2385       case TokenNameEQUAL_EQUAL_EQUAL:
2386       case TokenNameNOT_EQUAL_EQUAL:
2387       case TokenNameNOT_EQUAL:
2388       case TokenNameLESS:
2389       case TokenNameLESS_EQUAL:
2390       case TokenNameGREATER:
2391       case TokenNameGREATER_EQUAL:
2392         getNextToken();
2393         expression = new BinaryExpression(expression, expr(), token);
2394         break;
2395       //  | expr T_INSTANCEOF class_name_reference
2396       //        | expr '?' expr ':' expr
2397       case TokenNameinstanceof:
2398         getNextToken();
2399         class_name_reference();
2400         // TODO use InstanceofExpression
2401         expression = new Expression();
2402         expression.sourceStart = exprSourceStart;
2403         expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2404         break;
2405       case TokenNameQUESTION:
2406         getNextToken();
2407         Expression valueIfTrue = expr();
2408         if (token != TokenNameCOLON) {
2409           throwSyntaxError("':' expected in conditional expression.");
2410         }
2411         getNextToken();
2412         Expression valueIfFalse = expr();
2413
2414         expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2415         break;
2416       default:
2417         return expression;
2418       }
2419     }
2420   }
2421
2422   private void class_name_reference() {
2423     //  class_name_reference:
2424     //  T_STRING
2425     //| dynamic_class_name_reference
2426     if (Scanner.TRACE) {
2427       System.out.println("TRACE: class_name_reference()");
2428     }
2429     if (token == TokenNameIdentifier) {
2430       getNextToken();
2431     } else {
2432       dynamic_class_name_reference();
2433     }
2434   }
2435
2436   private void dynamic_class_name_reference() {
2437     //dynamic_class_name_reference:
2438     //  base_variable T_OBJECT_OPERATOR object_property
2439     // dynamic_class_name_variable_properties
2440     //| base_variable
2441     if (Scanner.TRACE) {
2442       System.out.println("TRACE: dynamic_class_name_reference()");
2443     }
2444     base_variable();
2445     if (token == TokenNameMINUS_GREATER) {
2446       getNextToken();
2447       object_property();
2448       dynamic_class_name_variable_properties();
2449     }
2450   }
2451
2452   private void dynamic_class_name_variable_properties() {
2453     //  dynamic_class_name_variable_properties:
2454     //                  dynamic_class_name_variable_properties
2455     // dynamic_class_name_variable_property
2456     //          | /* empty */
2457     if (Scanner.TRACE) {
2458       System.out.println("TRACE: dynamic_class_name_variable_properties()");
2459     }
2460     while (token == TokenNameMINUS_GREATER) {
2461       dynamic_class_name_variable_property();
2462     }
2463   }
2464
2465   private void dynamic_class_name_variable_property() {
2466     //  dynamic_class_name_variable_property:
2467     //  T_OBJECT_OPERATOR object_property
2468     if (Scanner.TRACE) {
2469       System.out.println("TRACE: dynamic_class_name_variable_property()");
2470     }
2471     if (token == TokenNameMINUS_GREATER) {
2472       getNextToken();
2473       object_property();
2474     }
2475   }
2476
2477   private void ctor_arguments() {
2478     //  ctor_arguments:
2479     //  /* empty */
2480     //| '(' function_call_parameter_list ')'
2481     if (token == TokenNameLPAREN) {
2482       getNextToken();
2483       if (token == TokenNameRPAREN) {
2484         getNextToken();
2485         return;
2486       }
2487       non_empty_function_call_parameter_list();
2488       if (token != TokenNameRPAREN) {
2489         throwSyntaxError("')' expected in ctor_arguments.");
2490       }
2491       getNextToken();
2492     }
2493   }
2494
2495   private void assignment_list() {
2496     //  assignment_list:
2497     //  assignment_list ',' assignment_list_element
2498     //| assignment_list_element
2499     while (true) {
2500       assignment_list_element();
2501       if (token != TokenNameCOMMA) {
2502         break;
2503       }
2504       getNextToken();
2505     }
2506   }
2507
2508   private void assignment_list_element() {
2509     //assignment_list_element:
2510     //  variable
2511     //| T_LIST '(' assignment_list ')'
2512     //| /* empty */
2513     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2514       variable();
2515     } else {
2516       if (token == TokenNamelist) {
2517         getNextToken();
2518         if (token == TokenNameLPAREN) {
2519           getNextToken();
2520           assignment_list();
2521           if (token != TokenNameRPAREN) {
2522             throwSyntaxError("')' expected after 'list' keyword.");
2523           }
2524           getNextToken();
2525         } else {
2526           throwSyntaxError("'(' expected after 'list' keyword.");
2527         }
2528       }
2529     }
2530   }
2531
2532   private void array_pair_list() {
2533     //  array_pair_list:
2534     //  /* empty */
2535     //| non_empty_array_pair_list possible_comma
2536     non_empty_array_pair_list();
2537     if (token == TokenNameCOMMA) {
2538       getNextToken();
2539     }
2540   }
2541
2542   private void non_empty_array_pair_list() {
2543     //non_empty_array_pair_list:
2544     //  non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2545     //| non_empty_array_pair_list ',' expr
2546     //| expr T_DOUBLE_ARROW expr
2547     //| expr
2548     //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2549     //| non_empty_array_pair_list ',' '&' w_variable
2550     //| expr T_DOUBLE_ARROW '&' w_variable
2551     //| '&' w_variable
2552     while (true) {
2553       if (token == TokenNameAND) {
2554         getNextToken();
2555         variable();
2556       } else {
2557         expr();
2558         if (token == TokenNameAND) {
2559           getNextToken();
2560           variable();
2561         } else if (token == TokenNameEQUAL_GREATER) {
2562           getNextToken();
2563           if (token == TokenNameAND) {
2564             getNextToken();
2565             variable();
2566           } else {
2567             expr();
2568           }
2569         }
2570       }
2571       if (token != TokenNameCOMMA) {
2572         return;
2573       }
2574       getNextToken();
2575       if (token == TokenNameRPAREN) {
2576         return;
2577       }
2578     }
2579   }
2580
2581   //  private void variableList() {
2582   //    do {
2583   //      variable();
2584   //      if (token == TokenNameCOMMA) {
2585   //        getNextToken();
2586   //      } else {
2587   //        break;
2588   //      }
2589   //    } while (true);
2590   //  }
2591   private void variable_without_objects() {
2592     //  variable_without_objects:
2593     //                  reference_variable
2594     //          | simple_indirect_reference reference_variable
2595     if (Scanner.TRACE) {
2596       System.out.println("TRACE: variable_without_objects()");
2597     }
2598     while (token == TokenNameDOLLAR) {
2599       getNextToken();
2600     }
2601     reference_variable();
2602   }
2603
2604   private void function_call() {
2605     //  function_call:
2606     //  T_STRING '(' function_call_parameter_list ')'
2607     //| class_constant '(' function_call_parameter_list ')'
2608     //| static_member '(' function_call_parameter_list ')'
2609     //| variable_without_objects '(' function_call_parameter_list ')'
2610     char[] defineName = null;
2611     char[] ident = null;
2612     int startPos = 0;
2613     int endPos = 0;
2614     if (Scanner.TRACE) {
2615       System.out.println("TRACE: function_call()");
2616     }
2617     if (token == TokenNameIdentifier) {
2618       ident = scanner.getCurrentIdentifierSource();
2619       defineName = ident;
2620       startPos = scanner.getCurrentTokenStartPosition();
2621       endPos = scanner.getCurrentTokenEndPosition();
2622       getNextToken();
2623       switch (token) {
2624       case TokenNamePAAMAYIM_NEKUDOTAYIM:
2625         // static member:
2626         defineName = null;
2627         getNextToken();
2628         if (token == TokenNameIdentifier) {
2629           // class _constant
2630           getNextToken();
2631         } else {
2632           //        static member:
2633           variable_without_objects();
2634         }
2635         break;
2636       }
2637     } else {
2638       variable_without_objects();
2639     }
2640     if (token != TokenNameLPAREN) {
2641       if (defineName != null) {
2642         // does this identifier contain only uppercase characters?
2643         if (defineName.length == 3) {
2644           if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2645             defineName = null;
2646           }
2647         } else if (defineName.length == 4) {
2648           if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
2649             defineName = null;
2650           } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
2651             defineName = null;
2652           }
2653         } else if (defineName.length == 5) {
2654           if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
2655             defineName = null;
2656           }
2657         }
2658         if (defineName != null) {
2659           for (int i = 0; i < defineName.length; i++) {
2660             if (Character.isLowerCase(defineName[i])) {
2661               problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
2662               break;
2663             }
2664           }
2665         }
2666       }
2667       // TODO is this ok ?
2668       return;
2669       //      throwSyntaxError("'(' expected in function call.");
2670     }
2671     getNextToken();
2672     if (token == TokenNameRPAREN) {
2673       getNextToken();
2674       return;
2675     }
2676     non_empty_function_call_parameter_list();
2677     if (token != TokenNameRPAREN) {
2678       String functionName;
2679       if (ident == null) {
2680         functionName = new String(" ");
2681       } else {
2682         functionName = new String(ident);
2683       }
2684       throwSyntaxError("')' expected in function call (" + functionName + ").");
2685     }
2686     getNextToken();
2687   }
2688
2689   //  private void function_call_parameter_list() {
2690   //    function_call_parameter_list:
2691   //            non_empty_function_call_parameter_list { $$ = $1; }
2692   //    | /* empty */
2693   //  }
2694   private void non_empty_function_call_parameter_list() {
2695     //non_empty_function_call_parameter_list:
2696     //          expr_without_variable
2697     //  | variable
2698     //  | '&' w_variable
2699     //  | non_empty_function_call_parameter_list ',' expr_without_variable
2700     //  | non_empty_function_call_parameter_list ',' variable
2701     //  | non_empty_function_call_parameter_list ',' '&' w_variable
2702     if (Scanner.TRACE) {
2703       System.out.println("TRACE: non_empty_function_call_parameter_list()");
2704     }
2705     while (true) {
2706       if (token == TokenNameAND) {
2707         getNextToken();
2708         w_variable();
2709       } else {
2710         //        if (token == TokenNameIdentifier || token ==
2711         // TokenNameVariable
2712         //            || token == TokenNameDOLLAR) {
2713         //          variable();
2714         //        } else {
2715         expr_without_variable(true);
2716         //        }
2717       }
2718       if (token != TokenNameCOMMA) {
2719         break;
2720       }
2721       getNextToken();
2722     }
2723   }
2724
2725   private void fully_qualified_class_name() {
2726     if (token == TokenNameIdentifier) {
2727       getNextToken();
2728     } else {
2729       throwSyntaxError("Class name expected.");
2730     }
2731   }
2732
2733   private void static_member() {
2734     //  static_member:
2735     //  fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2736     // variable_without_objects
2737     if (Scanner.TRACE) {
2738       System.out.println("TRACE: static_member()");
2739     }
2740     fully_qualified_class_name();
2741     if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2742       throwSyntaxError("'::' expected after class name (static_member).");
2743     }
2744     getNextToken();
2745     variable_without_objects();
2746   }
2747
2748   private void base_variable_with_function_calls() {
2749     //  base_variable_with_function_calls:
2750     //  base_variable
2751     //| function_call
2752     boolean functionCall = false;
2753     if (Scanner.TRACE) {
2754       System.out.println("TRACE: base_variable_with_function_calls()");
2755     }
2756     //    if (token == TokenNameIdentifier) {
2757     //      functionCall = true;
2758     //    } else if (token == TokenNameVariable) {
2759     //      int tempToken = token;
2760     //      int tempPosition = scanner.currentPosition;
2761     //      getNextToken();
2762     //      if (token == TokenNameLPAREN) {
2763     //        functionCall = true;
2764     //      }
2765     //      token = tempToken;
2766     //      scanner.currentPosition = tempPosition;
2767     //      scanner.phpMode = true;
2768     //    }
2769     //    if (functionCall) {
2770     function_call();
2771     //    } else {
2772     //      base_variable();
2773     //    }
2774   }
2775
2776   private void base_variable() {
2777     //  base_variable:
2778     //                  reference_variable
2779     //          | simple_indirect_reference reference_variable
2780     //          | static_member
2781     if (Scanner.TRACE) {
2782       System.out.println("TRACE: base_variable()");
2783     }
2784     if (token == TokenNameIdentifier) {
2785       static_member();
2786     } else {
2787       while (token == TokenNameDOLLAR) {
2788         getNextToken();
2789       }
2790       reference_variable();
2791     }
2792   }
2793
2794   //  private void simple_indirect_reference() {
2795   //    // simple_indirect_reference:
2796   //    // '$'
2797   //    //| simple_indirect_reference '$'
2798   //  }
2799   private void reference_variable() {
2800     //  reference_variable:
2801     //                  reference_variable '[' dim_offset ']'
2802     //          | reference_variable '{' expr '}'
2803     //          | compound_variable
2804     if (Scanner.TRACE) {
2805       System.out.println("TRACE: reference_variable()");
2806     }
2807     compound_variable();
2808     while (true) {
2809       if (token == TokenNameLBRACE) {
2810         getNextToken();
2811         expr();
2812         if (token != TokenNameRBRACE) {
2813           throwSyntaxError("'}' expected in reference variable.");
2814         }
2815         getNextToken();
2816       } else if (token == TokenNameLBRACKET) {
2817         getNextToken();
2818         if (token != TokenNameRBRACKET) {
2819           expr();
2820           //        dim_offset();
2821           if (token != TokenNameRBRACKET) {
2822             throwSyntaxError("']' expected in reference variable.");
2823           }
2824         }
2825         getNextToken();
2826       } else {
2827         break;
2828       }
2829     }
2830   }
2831
2832   private void compound_variable() {
2833     //  compound_variable:
2834     //                  T_VARIABLE
2835     //          | '$' '{' expr '}'
2836     if (Scanner.TRACE) {
2837       System.out.println("TRACE: compound_variable()");
2838     }
2839     if (token == TokenNameVariable) {
2840       getNextToken();
2841     } else {
2842       // because of simple_indirect_reference
2843       while (token == TokenNameDOLLAR) {
2844         getNextToken();
2845       }
2846       if (token != TokenNameLBRACE) {
2847         throwSyntaxError("'{' expected after compound variable token '$'.");
2848       }
2849       getNextToken();
2850       expr();
2851       if (token != TokenNameRBRACE) {
2852         throwSyntaxError("'}' expected after compound variable token '$'.");
2853       }
2854       getNextToken();
2855     }
2856   }
2857
2858   //  private void dim_offset() {
2859   //    // dim_offset:
2860   //    // /* empty */
2861   //    // | expr
2862   //    expr();
2863   //  }
2864   private void object_property() {
2865     //  object_property:
2866     //  object_dim_list
2867     //| variable_without_objects
2868     if (Scanner.TRACE) {
2869       System.out.println("TRACE: object_property()");
2870     }
2871     if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2872       variable_without_objects();
2873     } else {
2874       object_dim_list();
2875     }
2876   }
2877
2878   private void object_dim_list() {
2879     //object_dim_list:
2880     //  object_dim_list '[' dim_offset ']'
2881     //| object_dim_list '{' expr '}'
2882     //| variable_name
2883     if (Scanner.TRACE) {
2884       System.out.println("TRACE: object_dim_list()");
2885     }
2886     variable_name();
2887     while (true) {
2888       if (token == TokenNameLBRACE) {
2889         getNextToken();
2890         expr();
2891         if (token != TokenNameRBRACE) {
2892           throwSyntaxError("'}' expected in object_dim_list.");
2893         }
2894         getNextToken();
2895       } else if (token == TokenNameLBRACKET) {
2896         getNextToken();
2897         if (token == TokenNameRBRACKET) {
2898           getNextToken();
2899           continue;
2900         }
2901         expr();
2902         if (token != TokenNameRBRACKET) {
2903           throwSyntaxError("']' expected in object_dim_list.");
2904         }
2905         getNextToken();
2906       } else {
2907         break;
2908       }
2909     }
2910   }
2911
2912   private void variable_name() {
2913     //variable_name:
2914     //  T_STRING
2915     //| '{' expr '}'
2916     if (Scanner.TRACE) {
2917       System.out.println("TRACE: variable_name()");
2918     }
2919     if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
2920       if (token > TokenNameKEYWORD) {
2921         // TODO show a warning "Keyword used as variable" ?
2922       }
2923       getNextToken();
2924     } else {
2925       if (token != TokenNameLBRACE) {
2926         throwSyntaxError("'{' expected in variable name.");
2927       }
2928       getNextToken();
2929       expr();
2930       if (token != TokenNameRBRACE) {
2931         throwSyntaxError("'}' expected in variable name.");
2932       }
2933       getNextToken();
2934     }
2935   }
2936
2937   private void r_variable() {
2938     variable();
2939   }
2940
2941   private void w_variable() {
2942     variable();
2943   }
2944
2945   private void rw_variable() {
2946     variable();
2947   }
2948
2949   private void variable() {
2950     //    variable:
2951     //          base_variable_with_function_calls T_OBJECT_OPERATOR
2952     //                  object_property method_or_not variable_properties
2953     //  | base_variable_with_function_calls
2954     base_variable_with_function_calls();
2955     if (token == TokenNameMINUS_GREATER) {
2956       getNextToken();
2957       object_property();
2958       method_or_not();
2959       variable_properties();
2960     }
2961     //    if (token == TokenNameDOLLAR_LBRACE) {
2962     //      getNextToken();
2963     //      expr();
2964     //      ;
2965     //      if (token != TokenNameRBRACE) {
2966     //        throwSyntaxError("'}' expected after indirect variable token '${'.");
2967     //      }
2968     //      getNextToken();
2969     //    } else {
2970     //      if (token == TokenNameVariable) {
2971     //        getNextToken();
2972     //        if (token == TokenNameLBRACKET) {
2973     //          getNextToken();
2974     //          expr();
2975     //          if (token != TokenNameRBRACKET) {
2976     //            throwSyntaxError("']' expected in variable-list.");
2977     //          }
2978     //          getNextToken();
2979     //        } else if (token == TokenNameEQUAL) {
2980     //          getNextToken();
2981     //          static_scalar();
2982     //        }
2983     //      } else {
2984     //        throwSyntaxError("$-variable expected in variable-list.");
2985     //      }
2986     //    }
2987   }
2988
2989   private void variable_properties() {
2990     //  variable_properties:
2991     //                  variable_properties variable_property
2992     //          | /* empty */
2993     while (token == TokenNameMINUS_GREATER) {
2994       variable_property();
2995     }
2996   }
2997
2998   private void variable_property() {
2999     //  variable_property:
3000     //                  T_OBJECT_OPERATOR object_property method_or_not
3001     if (Scanner.TRACE) {
3002       System.out.println("TRACE: variable_property()");
3003     }
3004     if (token == TokenNameMINUS_GREATER) {
3005       getNextToken();
3006       object_property();
3007       method_or_not();
3008     } else {
3009       throwSyntaxError("'->' expected in variable_property.");
3010     }
3011   }
3012
3013   private void method_or_not() {
3014     //  method_or_not:
3015     //                  '(' function_call_parameter_list ')'
3016     //          | /* empty */
3017     if (Scanner.TRACE) {
3018       System.out.println("TRACE: method_or_not()");
3019     }
3020     if (token == TokenNameLPAREN) {
3021       getNextToken();
3022       if (token == TokenNameRPAREN) {
3023         getNextToken();
3024         return;
3025       }
3026       non_empty_function_call_parameter_list();
3027       if (token != TokenNameRPAREN) {
3028         throwSyntaxError("')' expected in method_or_not.");
3029       }
3030       getNextToken();
3031     }
3032   }
3033
3034   private void exit_expr() {
3035     //  /* empty */
3036     //  | '(' ')'
3037     //  | '(' expr ')'
3038     if (token != TokenNameLPAREN) {
3039       return;
3040     }
3041     getNextToken();
3042     if (token == TokenNameRPAREN) {
3043       getNextToken();
3044       return;
3045     }
3046     expr();
3047     if (token != TokenNameRPAREN) {
3048       throwSyntaxError("')' expected after keyword 'exit'");
3049     }
3050     getNextToken();
3051   }
3052
3053   private void encaps_list() {
3054     //                  encaps_list encaps_var
3055     //          | encaps_list T_STRING
3056     //          | encaps_list T_NUM_STRING
3057     //          | encaps_list T_ENCAPSED_AND_WHITESPACE
3058     //          | encaps_list T_CHARACTER
3059     //          | encaps_list T_BAD_CHARACTER
3060     //          | encaps_list '['
3061     //          | encaps_list ']'
3062     //          | encaps_list '{'
3063     //          | encaps_list '}'
3064     //          | encaps_list T_OBJECT_OPERATOR
3065     //          | /* empty */
3066     while (true) {
3067       switch (token) {
3068       case TokenNameSTRING:
3069         getNextToken();
3070         break;
3071       case TokenNameLBRACE:
3072         //          scanner.encapsedStringStack.pop();
3073         getNextToken();
3074         break;
3075       case TokenNameRBRACE:
3076         //          scanner.encapsedStringStack.pop();
3077         getNextToken();
3078         break;
3079       case TokenNameLBRACKET:
3080         //          scanner.encapsedStringStack.pop();
3081         getNextToken();
3082         break;
3083       case TokenNameRBRACKET:
3084         //          scanner.encapsedStringStack.pop();
3085         getNextToken();
3086         break;
3087       case TokenNameMINUS_GREATER:
3088         //          scanner.encapsedStringStack.pop();
3089         getNextToken();
3090         break;
3091       case TokenNameVariable:
3092       case TokenNameDOLLAR_LBRACE:
3093       case TokenNameLBRACE_DOLLAR:
3094         encaps_var();
3095         break;
3096       default:
3097         char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3098         if (encapsedChar == '$') {
3099           scanner.encapsedStringStack.pop();
3100           encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3101           switch (encapsedChar) {
3102           case '`':
3103             if (token == TokenNameEncapsedString0) {
3104               return;
3105             }
3106             token = TokenNameSTRING;
3107             continue;
3108           case '\'':
3109             if (token == TokenNameEncapsedString1) {
3110               return;
3111             }
3112             token = TokenNameSTRING;
3113             continue;
3114           case '"':
3115             if (token == TokenNameEncapsedString2) {
3116               return;
3117             }
3118             token = TokenNameSTRING;
3119             continue;
3120           }
3121         }
3122         return;
3123       }
3124     }
3125   }
3126
3127   private void encaps_var() {
3128     //                  T_VARIABLE
3129     //          | T_VARIABLE '[' encaps_var_offset ']'
3130     //          | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3131     //          | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3132     //          | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3133     //          | T_CURLY_OPEN variable '}'
3134     switch (token) {
3135     case TokenNameVariable:
3136       getNextToken();
3137       if (token == TokenNameLBRACKET) {
3138         getNextToken();
3139         expr(); //encaps_var_offset();
3140         if (token != TokenNameRBRACKET) {
3141           throwSyntaxError("']' expected after variable.");
3142         }
3143         //          scanner.encapsedStringStack.pop();
3144         getNextToken();
3145         //          }
3146       } else if (token == TokenNameMINUS_GREATER) {
3147         getNextToken();
3148         if (token != TokenNameIdentifier) {
3149           throwSyntaxError("Identifier expected after '->'.");
3150         }
3151         //          scanner.encapsedStringStack.pop();
3152         getNextToken();
3153       }
3154       //        else {
3155       //          // scanner.encapsedStringStack.pop();
3156       //          int tempToken = TokenNameSTRING;
3157       //          if (!scanner.encapsedStringStack.isEmpty()
3158       //              && (token == TokenNameEncapsedString0
3159       //                  || token == TokenNameEncapsedString1
3160       //                  || token == TokenNameEncapsedString2 || token ==
3161       // TokenNameERROR)) {
3162       //            char encapsedChar = ((Character)
3163       // scanner.encapsedStringStack.peek())
3164       //                .charValue();
3165       //            switch (token) {
3166       //              case TokenNameEncapsedString0 :
3167       //                if (encapsedChar == '`') {
3168       //                  tempToken = TokenNameEncapsedString0;
3169       //                }
3170       //                break;
3171       //              case TokenNameEncapsedString1 :
3172       //                if (encapsedChar == '\'') {
3173       //                  tempToken = TokenNameEncapsedString1;
3174       //                }
3175       //                break;
3176       //              case TokenNameEncapsedString2 :
3177       //                if (encapsedChar == '"') {
3178       //                  tempToken = TokenNameEncapsedString2;
3179       //                }
3180       //                break;
3181       //              case TokenNameERROR :
3182       //                if (scanner.source[scanner.currentPosition - 1] == '\\') {
3183       //                  scanner.currentPosition--;
3184       //                  getNextToken();
3185       //                }
3186       //                break;
3187       //            }
3188       //          }
3189       //          token = tempToken;
3190       //        }
3191       break;
3192     case TokenNameDOLLAR_LBRACE:
3193       getNextToken();
3194       if (token == TokenNameDOLLAR_LBRACE) {
3195         encaps_var();
3196       } else if (token == TokenNameIdentifier) {
3197         getNextToken();
3198         if (token == TokenNameLBRACKET) {
3199           getNextToken();
3200           //            if (token == TokenNameRBRACKET) {
3201           //              getNextToken();
3202           //            } else {
3203           expr();
3204           if (token != TokenNameRBRACKET) {
3205             throwSyntaxError("']' expected after '${'.");
3206           }
3207           getNextToken();
3208           //            }
3209         }
3210       } else {
3211         expr();
3212       }
3213       if (token != TokenNameRBRACE) {
3214         throwSyntaxError("'}' expected.");
3215       }
3216       getNextToken();
3217       break;
3218     case TokenNameLBRACE_DOLLAR:
3219       getNextToken();
3220       if (token == TokenNameLBRACE_DOLLAR) {
3221         encaps_var();
3222       } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3223         getNextToken();
3224         if (token == TokenNameLBRACKET) {
3225           getNextToken();
3226           //            if (token == TokenNameRBRACKET) {
3227           //              getNextToken();
3228           //            } else {
3229           expr();
3230           if (token != TokenNameRBRACKET) {
3231             throwSyntaxError("']' expected.");
3232           }
3233           getNextToken();
3234           //            }
3235         } else if (token == TokenNameMINUS_GREATER) {
3236           getNextToken();
3237           if (token != TokenNameIdentifier && token != TokenNameVariable) {
3238             throwSyntaxError("String or Variable token expected.");
3239           }
3240           getNextToken();
3241           if (token == TokenNameLBRACKET) {
3242             getNextToken();
3243             //            if (token == TokenNameRBRACKET) {
3244             //              getNextToken();
3245             //            } else {
3246             expr();
3247             if (token != TokenNameRBRACKET) {
3248               throwSyntaxError("']' expected after '${'.");
3249             }
3250             getNextToken();
3251             //            }
3252           }
3253         }
3254         //          if (token != TokenNameRBRACE) {
3255         //            throwSyntaxError("'}' expected after '{$'.");
3256         //          }
3257         //          // scanner.encapsedStringStack.pop();
3258         //          getNextToken();
3259       } else {
3260         expr();
3261         if (token != TokenNameRBRACE) {
3262           throwSyntaxError("'}' expected.");
3263         }
3264         //          scanner.encapsedStringStack.pop();
3265         getNextToken();
3266       }
3267       break;
3268     }
3269   }
3270
3271   private void encaps_var_offset() {
3272     //                  T_STRING
3273     //          | T_NUM_STRING
3274     //          | T_VARIABLE
3275     switch (token) {
3276     case TokenNameSTRING:
3277       getNextToken();
3278       break;
3279     case TokenNameIntegerLiteral:
3280       getNextToken();
3281       break;
3282     case TokenNameVariable:
3283       getNextToken();
3284       break;
3285     case TokenNameIdentifier:
3286       getNextToken();
3287       break;
3288     default:
3289       throwSyntaxError("Variable or String token expected.");
3290       break;
3291     }
3292   }
3293
3294   private void internal_functions_in_yacc() {
3295     //    int start = 0;
3296     ImportReference impt = null;
3297     switch (token) {
3298     case TokenNameisset:
3299       //        T_ISSET '(' isset_variables ')'
3300       getNextToken();
3301       if (token != TokenNameLPAREN) {
3302         throwSyntaxError("'(' expected after keyword 'isset'");
3303       }
3304       getNextToken();
3305       isset_variables();
3306       if (token != TokenNameRPAREN) {
3307         throwSyntaxError("')' expected after keyword 'isset'");
3308       }
3309       getNextToken();
3310       break;
3311     case TokenNameempty:
3312       //        T_EMPTY '(' variable ')'
3313       getNextToken();
3314       if (token != TokenNameLPAREN) {
3315         throwSyntaxError("'(' expected after keyword 'empty'");
3316       }
3317       getNextToken();
3318       variable();
3319       if (token != TokenNameRPAREN) {
3320         throwSyntaxError("')' expected after keyword 'empty'");
3321       }
3322       getNextToken();
3323       break;
3324     case TokenNameinclude:
3325       //T_INCLUDE expr
3326       checkFileName(token, impt);
3327       break;
3328     case TokenNameinclude_once:
3329       //        T_INCLUDE_ONCE expr
3330       checkFileName(token, impt);
3331       break;
3332     case TokenNameeval:
3333       //        T_EVAL '(' expr ')'
3334       getNextToken();
3335       if (token != TokenNameLPAREN) {
3336         throwSyntaxError("'(' expected after keyword 'eval'");
3337       }
3338       getNextToken();
3339       expr();
3340       if (token != TokenNameRPAREN) {
3341         throwSyntaxError("')' expected after keyword 'eval'");
3342       }
3343       getNextToken();
3344       break;
3345     case TokenNamerequire:
3346       //T_REQUIRE expr
3347       checkFileName(token, impt);
3348       break;
3349     case TokenNamerequire_once:
3350       //        T_REQUIRE_ONCE expr
3351       checkFileName(token, impt);
3352       break;
3353     }
3354   }
3355
3356   private void checkFileName(int includeToken, ImportReference impt) {
3357     //<include-token> expr
3358     int start = scanner.getCurrentTokenStartPosition();
3359     boolean hasLPAREN = false;
3360     getNextToken();
3361     if (token == TokenNameLPAREN) {
3362       hasLPAREN = true;
3363       getNextToken();
3364     }
3365     Expression expression = expr();
3366     if (hasLPAREN) {
3367       if (token == TokenNameRPAREN) {
3368         getNextToken();
3369       } else {
3370         throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3371       }
3372     }
3373     impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3374     impt.declarationSourceEnd = impt.sourceEnd;
3375     impt.declarationEnd = impt.declarationSourceEnd;
3376     //endPosition is just before the ;
3377     impt.declarationSourceStart = start;
3378     includesList.add(impt);
3379
3380     if (expression instanceof StringLiteral) {
3381       StringLiteral literal = (StringLiteral) expression;
3382       char[] includeName = literal.source();
3383       if (includeName.length == 0) {
3384         reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3385             literal.sourceStart + 1);
3386       }
3387       String includeNameString = new String(includeName);
3388       if (literal instanceof StringLiteralDQ) {
3389         if (includeNameString.indexOf('$') >= 0) {
3390           // assuming that the filename contains a variable => no filename check
3391           return;
3392         }
3393       }
3394       if (includeNameString.startsWith("http://")) {
3395         // assuming external include location
3396         return;
3397       }
3398       if (scanner.compilationUnit != null) {
3399         IResource resource = scanner.compilationUnit.getResource();
3400         //        java.io.File f = new java.io.File(new String(compilationUnit.getFileName()));
3401         //        System.out.println(expression.toStringExpression());
3402         //      }
3403         if (resource != null && resource instanceof IFile) {
3404           // check the filename:
3405           //      System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
3406           IProject project = resource.getProject();
3407           if (project != null) {
3408             IPath path = PHPFileUtil.determineFilePath(includeNameString, resource, project);
3409             
3410             if (path == null) {
3411               //              reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
3412               //                  + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
3413               String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3414               problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3415                   compilationUnit.compilationResult);
3416             } else {
3417               impt.setFile( PHPFileUtil.createFile(path, project) );
3418             }
3419           }
3420         }
3421       }
3422     }
3423   }
3424
3425   private void isset_variables() {
3426     //  variable
3427     //  | isset_variables ','
3428     if (token == TokenNameRPAREN) {
3429       throwSyntaxError("Variable expected after keyword 'isset'");
3430     }
3431     while (true) {
3432       variable();
3433       if (token == TokenNameCOMMA) {
3434         getNextToken();
3435       } else {
3436         break;
3437       }
3438     }
3439   }
3440
3441   private boolean common_scalar() {
3442     //  common_scalar:
3443     //  T_LNUMBER
3444     //  | T_DNUMBER
3445     //  | T_CONSTANT_ENCAPSED_STRING
3446     //  | T_LINE
3447     //  | T_FILE
3448     //  | T_CLASS_C
3449     //  | T_METHOD_C
3450     //  | T_FUNC_C
3451     switch (token) {
3452     case TokenNameIntegerLiteral:
3453       getNextToken();
3454       return true;
3455     case TokenNameDoubleLiteral:
3456       getNextToken();
3457       return true;
3458     case TokenNameStringDoubleQuote:
3459       getNextToken();
3460       return true;
3461     case TokenNameStringSingleQuote:
3462       getNextToken();
3463       return true;
3464     case TokenNameStringInterpolated:
3465       getNextToken();
3466       return true;
3467     case TokenNameFILE:
3468       getNextToken();
3469       return true;
3470     case TokenNameLINE:
3471       getNextToken();
3472       return true;
3473     case TokenNameCLASS_C:
3474       getNextToken();
3475       return true;
3476     case TokenNameMETHOD_C:
3477       getNextToken();
3478       return true;
3479     case TokenNameFUNC_C:
3480       getNextToken();
3481       return true;
3482     }
3483     return false;
3484   }
3485
3486   private void scalar() {
3487     //  scalar:
3488     //  T_STRING
3489     //| T_STRING_VARNAME
3490     //| class_constant
3491     //| common_scalar
3492     //| '"' encaps_list '"'
3493     //| '\'' encaps_list '\''
3494     //| T_START_HEREDOC encaps_list T_END_HEREDOC
3495     throwSyntaxError("Not yet implemented (scalar).");
3496   }
3497
3498   private void static_scalar() {
3499     //    static_scalar: /* compile-time evaluated scalars */
3500     //          common_scalar
3501     //  | T_STRING
3502     //  | '+' static_scalar
3503     //  | '-' static_scalar
3504     //  | T_ARRAY '(' static_array_pair_list ')'
3505     //  | static_class_constant
3506     if (common_scalar()) {
3507       return;
3508     }
3509     switch (token) {
3510     case TokenNameIdentifier:
3511       getNextToken();
3512       //        static_class_constant:
3513       //                T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3514       if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3515         getNextToken();
3516         if (token == TokenNameIdentifier) {
3517           getNextToken();
3518         } else {
3519           throwSyntaxError("Identifier expected after '::' operator.");
3520         }
3521       }
3522       break;
3523     case TokenNameEncapsedString0:
3524       try {
3525         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3526         while (scanner.currentCharacter != '`') {
3527           if (scanner.currentCharacter == '\\') {
3528             scanner.currentPosition++;
3529           }
3530           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3531         }
3532         getNextToken();
3533       } catch (IndexOutOfBoundsException e) {
3534         throwSyntaxError("'`' expected at end of static string.");
3535       }
3536       break;
3537     case TokenNameEncapsedString1:
3538       try {
3539         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3540         while (scanner.currentCharacter != '\'') {
3541           if (scanner.currentCharacter == '\\') {
3542             scanner.currentPosition++;
3543           }
3544           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3545         }
3546         getNextToken();
3547       } catch (IndexOutOfBoundsException e) {
3548         throwSyntaxError("'\'' expected at end of static string.");
3549       }
3550       break;
3551     case TokenNameEncapsedString2:
3552       try {
3553         scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3554         while (scanner.currentCharacter != '"') {
3555           if (scanner.currentCharacter == '\\') {
3556             scanner.currentPosition++;
3557           }
3558           scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3559         }
3560         getNextToken();
3561       } catch (IndexOutOfBoundsException e) {
3562         throwSyntaxError("'\"' expected at end of static string.");
3563       }
3564       break;
3565     case TokenNamePLUS:
3566       getNextToken();
3567       static_scalar();
3568       break;
3569     case TokenNameMINUS:
3570       getNextToken();
3571       static_scalar();
3572       break;
3573     case TokenNamearray:
3574       getNextToken();
3575       if (token != TokenNameLPAREN) {
3576         throwSyntaxError("'(' expected after keyword 'array'");
3577       }
3578       getNextToken();
3579       if (token == TokenNameRPAREN) {
3580         getNextToken();
3581         break;
3582       }
3583       non_empty_static_array_pair_list();
3584       if (token != TokenNameRPAREN) {
3585         throwSyntaxError("')' expected after keyword 'array'");
3586       }
3587       getNextToken();
3588       break;
3589     //      case TokenNamenull :
3590     //        getNextToken();
3591     //        break;
3592     //      case TokenNamefalse :
3593     //        getNextToken();
3594     //        break;
3595     //      case TokenNametrue :
3596     //        getNextToken();
3597     //        break;
3598     default:
3599       throwSyntaxError("Static scalar/constant expected.");
3600     }
3601   }
3602
3603   private void non_empty_static_array_pair_list() {
3604     //  non_empty_static_array_pair_list:
3605     //  non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3606     // static_scalar
3607     //| non_empty_static_array_pair_list ',' static_scalar
3608     //| static_scalar T_DOUBLE_ARROW static_scalar
3609     //| static_scalar
3610     while (true) {
3611       static_scalar();
3612       if (token == TokenNameEQUAL_GREATER) {
3613         getNextToken();
3614         static_scalar();
3615       }
3616       if (token != TokenNameCOMMA) {
3617         break;
3618       }
3619       getNextToken();
3620       if (token == TokenNameRPAREN) {
3621         break;
3622       }
3623     }
3624   }
3625
3626   public void reportSyntaxError() { //int act, int currentKind, int
3627     // stateStackTop) {
3628     /* remember current scanner position */
3629     int startPos = scanner.startPosition;
3630     int currentPos = scanner.currentPosition;
3631     //          String[] expectings;
3632     //          String tokenName = name[symbol_index[currentKind]];
3633     //fetch all "accurate" possible terminals that could recover the error
3634     //          int start, end = start = asi(stack[stateStackTop]);
3635     //          while (asr[end] != 0)
3636     //                  end++;
3637     //          int length = end - start;
3638     //          expectings = new String[length];
3639     //          if (length != 0) {
3640     //                  char[] indexes = new char[length];
3641     //                  System.arraycopy(asr, start, indexes, 0, length);
3642     //                  for (int i = 0; i < length; i++) {
3643     //                          expectings[i] = name[symbol_index[indexes[i]]];
3644     //                  }
3645     //          }
3646     //if the pb is an EOF, try to tell the user that they are some
3647     //          if (tokenName.equals(UNEXPECTED_EOF)) {
3648     //                  if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3649     //                          char[] tokenSource;
3650     //                          try {
3651     //                                  tokenSource = this.scanner.getCurrentTokenSource();
3652     //                          } catch (Exception e) {
3653     //                                  tokenSource = new char[] {};
3654     //                          }
3655     //                          problemReporter().parseError(
3656     //                                  this.scanner.startPosition,
3657     //                                  this.scanner.currentPosition - 1,
3658     //                                  tokenSource,
3659     //                                  tokenName,
3660     //                                  expectings);
3661     //                  }
3662     //          } else { //the next test is HEAVILY grammar DEPENDENT.
3663     //                  if ((length == 14)
3664     //                          && (expectings[0] == "=") //$NON-NLS-1$
3665     //                          && (expectings[1] == "*=") //$NON-NLS-1$
3666     //                          && (expressionPtr > -1)) {
3667     //                                  switch(currentKind) {
3668     //                                          case TokenNameSEMICOLON:
3669     //                                          case TokenNamePLUS:
3670     //                                          case TokenNameMINUS:
3671     //                                          case TokenNameDIVIDE:
3672     //                                          case TokenNameREMAINDER:
3673     //                                          case TokenNameMULTIPLY:
3674     //                                          case TokenNameLEFT_SHIFT:
3675     //                                          case TokenNameRIGHT_SHIFT:
3676     //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3677     //                                          case TokenNameLESS:
3678     //                                          case TokenNameGREATER:
3679     //                                          case TokenNameLESS_EQUAL:
3680     //                                          case TokenNameGREATER_EQUAL:
3681     //                                          case TokenNameEQUAL_EQUAL:
3682     //                                          case TokenNameNOT_EQUAL:
3683     //                                          case TokenNameXOR:
3684     //                                          case TokenNameAND:
3685     //                                          case TokenNameOR:
3686     //                                          case TokenNameOR_OR:
3687     //                                          case TokenNameAND_AND:
3688     //                                                  // the ; is not the expected token ==> it ends a statement when an
3689     // expression is not ended
3690     //                                                  problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3691     //                                                  break;
3692     //                                          case TokenNameRBRACE :
3693     //                                                  problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3694     //                                                  break;
3695     //                                          default:
3696     //                                                  char[] tokenSource;
3697     //                                                  try {
3698     //                                                          tokenSource = this.scanner.getCurrentTokenSource();
3699     //                                                  } catch (Exception e) {
3700     //                                                          tokenSource = new char[] {};
3701     //                                                  }
3702     //                                                  problemReporter().parseError(
3703     //                                                          this.scanner.startPosition,
3704     //                                                          this.scanner.currentPosition - 1,
3705     //                                                          tokenSource,
3706     //                                                          tokenName,
3707     //                                                          expectings);
3708     //                                                  this.checkAndReportBracketAnomalies(problemReporter());
3709     //                                  }
3710     //                  } else {
3711     char[] tokenSource;
3712     try {
3713       tokenSource = this.scanner.getCurrentTokenSource();
3714     } catch (Exception e) {
3715       tokenSource = new char[] {};
3716     }
3717     //                          problemReporter().parseError(
3718     //                                  this.scanner.startPosition,
3719     //                                  this.scanner.currentPosition - 1,
3720     //                                  tokenSource,
3721     //                                  tokenName,
3722     //                                  expectings);
3723     this.checkAndReportBracketAnomalies(problemReporter());
3724     //                  }
3725     //          }
3726     /* reset scanner where it was */
3727     scanner.startPosition = startPos;
3728     scanner.currentPosition = currentPos;
3729   }
3730
3731   public static final int RoundBracket = 0;
3732
3733   public static final int SquareBracket = 1;
3734
3735   public static final int CurlyBracket = 2;
3736
3737   public static final int BracketKinds = 3;
3738
3739   protected int[] nestedMethod; //the ptr is nestedType
3740
3741   protected int nestedType, dimensions;
3742
3743   //ast stack
3744   final static int AstStackIncrement = 100;
3745
3746   protected int astPtr;
3747
3748   protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
3749
3750   protected int astLengthPtr;
3751
3752   protected int[] astLengthStack;
3753
3754   ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
3755
3756   public CompilationUnitDeclaration compilationUnit; /*
3757                                                       * the result from parse()
3758                                                       */
3759
3760   protected ReferenceContext referenceContext;
3761
3762   protected ProblemReporter problemReporter;
3763
3764   protected CompilerOptions options;
3765
3766   private ArrayList includesList;
3767
3768   //  protected CompilationResult compilationResult;
3769   /**
3770    * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
3771    * reported, so initializes the compilation result's line positions.
3772    */
3773   public ProblemReporter problemReporter() {
3774     if (scanner.recordLineSeparator) {
3775       compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
3776     }
3777     problemReporter.referenceContext = referenceContext;
3778     return problemReporter;
3779   }
3780
3781   /*
3782    * Reconsider the entire source looking for inconsistencies in {} () []
3783    */
3784   public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
3785     scanner.wasAcr = false;
3786     boolean anomaliesDetected = false;
3787     try {
3788       char[] source = scanner.source;
3789       int[] leftCount = { 0, 0, 0 };
3790       int[] rightCount = { 0, 0, 0 };
3791       int[] depths = { 0, 0, 0 };
3792       int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
3793       int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
3794       int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
3795       int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
3796       scanner.currentPosition = scanner.initialPosition; //starting
3797       // point
3798       // (first-zero-based
3799       // char)
3800       while (scanner.currentPosition < scanner.eofPosition) { //loop for
3801         // jumping
3802         // over
3803         // comments
3804         try {
3805           // ---------Consume white space and handles
3806           // startPosition---------
3807           boolean isWhiteSpace;
3808           do {
3809             scanner.startPosition = scanner.currentPosition;
3810             //                                          if (((scanner.currentCharacter =
3811             // source[scanner.currentPosition++]) == '\\') &&
3812             // (source[scanner.currentPosition] == 'u')) {
3813             //                                                  isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
3814             //                                          } else {
3815             if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3816               if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3817                 // only record line positions we have not
3818                 // recorded yet
3819                 scanner.pushLineSeparator();
3820               }
3821             }
3822             isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
3823             //                                          }
3824           } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
3825           // -------consume token until } is found---------
3826           switch (scanner.currentCharacter) {
3827           case '{': {
3828             int index = leftCount[CurlyBracket]++;
3829             if (index == leftPositions[CurlyBracket].length) {
3830               System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
3831               System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
3832             }
3833             leftPositions[CurlyBracket][index] = scanner.startPosition;
3834             leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
3835           }
3836             break;
3837           case '}': {
3838             int index = rightCount[CurlyBracket]++;
3839             if (index == rightPositions[CurlyBracket].length) {
3840               System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
3841               System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
3842             }
3843             rightPositions[CurlyBracket][index] = scanner.startPosition;
3844             rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
3845           }
3846             break;
3847           case '(': {
3848             int index = leftCount[RoundBracket]++;
3849             if (index == leftPositions[RoundBracket].length) {
3850               System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
3851               System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
3852             }
3853             leftPositions[RoundBracket][index] = scanner.startPosition;
3854             leftDepths[RoundBracket][index] = depths[RoundBracket]++;
3855           }
3856             break;
3857           case ')': {
3858             int index = rightCount[RoundBracket]++;
3859             if (index == rightPositions[RoundBracket].length) {
3860               System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
3861               System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
3862             }
3863             rightPositions[RoundBracket][index] = scanner.startPosition;
3864             rightDepths[RoundBracket][index] = --depths[RoundBracket];
3865           }
3866             break;
3867           case '[': {
3868             int index = leftCount[SquareBracket]++;
3869             if (index == leftPositions[SquareBracket].length) {
3870               System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
3871               System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
3872             }
3873             leftPositions[SquareBracket][index] = scanner.startPosition;
3874             leftDepths[SquareBracket][index] = depths[SquareBracket]++;
3875           }
3876             break;
3877           case ']': {
3878             int index = rightCount[SquareBracket]++;
3879             if (index == rightPositions[SquareBracket].length) {
3880               System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
3881               System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
3882             }
3883             rightPositions[SquareBracket][index] = scanner.startPosition;
3884             rightDepths[SquareBracket][index] = --depths[SquareBracket];
3885           }
3886             break;
3887           case '\'': {
3888             if (scanner.getNextChar('\\')) {
3889               scanner.scanEscapeCharacter();
3890             } else { // consume next character
3891               scanner.unicodeAsBackSlash = false;
3892               //                                                                        if (((scanner.currentCharacter =
3893               // source[scanner.currentPosition++]) ==
3894               // '\\') &&
3895               // (source[scanner.currentPosition] ==
3896               // 'u')) {
3897               //                                                                                scanner.getNextUnicodeChar();
3898               //                                                                        } else {
3899               if (scanner.withoutUnicodePtr != 0) {
3900                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3901               }
3902               //                                                                        }
3903             }
3904             scanner.getNextChar('\'');
3905             break;
3906           }
3907           case '"':
3908             // consume next character
3909             scanner.unicodeAsBackSlash = false;
3910             //                                                  if (((scanner.currentCharacter =
3911             // source[scanner.currentPosition++]) == '\\') &&
3912             // (source[scanner.currentPosition] == 'u')) {
3913             //                                                          scanner.getNextUnicodeChar();
3914             //                                                  } else {
3915             if (scanner.withoutUnicodePtr != 0) {
3916               scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3917             }
3918             //                                                  }
3919             while (scanner.currentCharacter != '"') {
3920               if (scanner.currentCharacter == '\r') {
3921                 if (source[scanner.currentPosition] == '\n')
3922                   scanner.currentPosition++;
3923                 break; // the string cannot go further that
3924                 // the line
3925               }
3926               if (scanner.currentCharacter == '\n') {
3927                 break; // the string cannot go further that
3928                 // the line
3929               }
3930               if (scanner.currentCharacter == '\\') {
3931                 scanner.scanEscapeCharacter();
3932               }
3933               // consume next character
3934               scanner.unicodeAsBackSlash = false;
3935               //                                                                if (((scanner.currentCharacter =
3936               // source[scanner.currentPosition++]) == '\\')
3937               // && (source[scanner.currentPosition] == 'u'))
3938               // {
3939               //                                                                        scanner.getNextUnicodeChar();
3940               //                                                                } else {
3941               if (scanner.withoutUnicodePtr != 0) {
3942                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3943               }
3944               //                                                                }
3945             }
3946             break;
3947           case '/': {
3948             int test;
3949             if ((test = scanner.getNextChar('/', '*')) == 0) { //line
3950               // comment
3951               //get the next char
3952               if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3953                   && (source[scanner.currentPosition] == 'u')) {
3954                 //-------------unicode traitement
3955                 // ------------
3956                 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3957                 scanner.currentPosition++;
3958                 while (source[scanner.currentPosition] == 'u') {
3959                   scanner.currentPosition++;
3960                 }
3961                 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3962                     || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3963                     || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3964                     || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3965                   // don't
3966                   // care of the
3967                   // value
3968                   scanner.currentCharacter = 'A';
3969                 } //something different from \n and \r
3970                 else {
3971                   scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3972                 }
3973               }
3974               while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
3975                 //get the next char
3976                 scanner.startPosition = scanner.currentPosition;
3977                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3978                     && (source[scanner.currentPosition] == 'u')) {
3979                   //-------------unicode traitement
3980                   // ------------
3981                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3982                   scanner.currentPosition++;
3983                   while (source[scanner.currentPosition] == 'u') {
3984                     scanner.currentPosition++;
3985                   }
3986                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3987                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3988                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3989                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3990                     // don't
3991                     // care of the
3992                     // value
3993                     scanner.currentCharacter = 'A';
3994                   } //something different from \n
3995                   // and \r
3996                   else {
3997                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3998                   }
3999                 }
4000               }
4001               if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4002                 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4003                   // only record line positions we
4004                   // have not recorded yet
4005                   scanner.pushLineSeparator();
4006                   if (this.scanner.taskTags != null) {
4007                     this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
4008                         .getCurrentTokenEndPosition());
4009                   }
4010                 }
4011               }
4012               break;
4013             }
4014             if (test > 0) { //traditional and annotation
4015               // comment
4016               boolean star = false;
4017               // consume next character
4018               scanner.unicodeAsBackSlash = false;
4019               //                                                                        if (((scanner.currentCharacter =
4020               // source[scanner.currentPosition++]) ==
4021               // '\\') &&
4022               // (source[scanner.currentPosition] ==
4023               // 'u')) {
4024               //                                                                                scanner.getNextUnicodeChar();
4025               //                                                                        } else {
4026               if (scanner.withoutUnicodePtr != 0) {
4027                 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4028               }
4029               //                                                                        }
4030               if (scanner.currentCharacter == '*') {
4031                 star = true;
4032               }
4033               //get the next char
4034               if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4035                   && (source[scanner.currentPosition] == 'u')) {
4036                 //-------------unicode traitement
4037                 // ------------
4038                 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4039                 scanner.currentPosition++;
4040                 while (source[scanner.currentPosition] == 'u') {
4041                   scanner.currentPosition++;
4042                 }
4043                 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4044                     || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4045                     || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4046                     || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4047                   // don't
4048                   // care of the
4049                   // value
4050                   scanner.currentCharacter = 'A';
4051                 } //something different from * and /
4052                 else {
4053                   scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4054                 }
4055               }
4056               //loop until end of comment */
4057               while ((scanner.currentCharacter != '/') || (!star)) {
4058                 star = scanner.currentCharacter == '*';
4059                 //get next char
4060                 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4061                     && (source[scanner.currentPosition] == 'u')) {
4062                   //-------------unicode traitement
4063                   // ------------
4064                   int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4065                   scanner.currentPosition++;
4066                   while (source[scanner.currentPosition] == 'u') {
4067                     scanner.currentPosition++;
4068                   }
4069                   if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4070                       || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4071                       || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4072                       || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4073                     // don't
4074                     // care of the
4075                     // value
4076                     scanner.currentCharacter = 'A';
4077                   } //something different from * and
4078                   // /
4079                   else {
4080                     scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4081                   }
4082                 }
4083               }
4084               if (this.scanner.taskTags != null) {
4085                 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
4086               }
4087               break;
4088             }
4089             break;
4090           }
4091           default:
4092             if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4093               scanner.scanIdentifierOrKeyword(false);
4094               break;
4095             }
4096             if (Character.isDigit(scanner.currentCharacter)) {
4097               scanner.scanNumber(false);
4098               break;
4099             }
4100           }
4101           //-----------------end switch while
4102           // try--------------------
4103         } catch (IndexOutOfBoundsException e) {
4104           break; // read until EOF
4105         } catch (InvalidInputException e) {
4106           return false; // no clue
4107         }
4108       }
4109       if (scanner.recordLineSeparator) {
4110         //                              compilationUnit.compilationResult.lineSeparatorPositions =
4111         // scanner.getLineEnds();
4112       }
4113       // check placement anomalies against other kinds of brackets
4114       for (int kind = 0; kind < BracketKinds; kind++) {
4115         for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4116           int start = leftPositions[kind][leftIndex]; // deepest
4117           // first
4118           // find matching closing bracket
4119           int depth = leftDepths[kind][leftIndex];
4120           int end = -1;
4121           for (int i = 0; i < rightCount[kind]; i++) {
4122             int pos = rightPositions[kind][i];
4123             // want matching bracket further in source with same
4124             // depth
4125             if ((pos > start) && (depth == rightDepths[kind][i])) {
4126               end = pos;
4127               break;
4128             }
4129           }
4130           if (end < 0) { // did not find a good closing match
4131             problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
4132             return true;
4133           }
4134           // check if even number of opening/closing other brackets
4135           // in between this pair of brackets
4136           int balance = 0;
4137           for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
4138             for (int i = 0; i < leftCount[otherKind]; i++) {
4139               int pos = leftPositions[otherKind][i];
4140               if ((pos > start) && (pos < end))
4141                 balance++;
4142             }
4143             for (int i = 0; i < rightCount[otherKind]; i++) {
4144               int pos = rightPositions[otherKind][i];
4145               if ((pos > start) && (pos < end))
4146                 balance--;
4147             }
4148             if (balance != 0) {
4149               problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
4150               // anomaly
4151               return true;
4152             }
4153           }
4154         }
4155         // too many opening brackets ?
4156         for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4157           anomaliesDetected = true;
4158           problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
4159               compilationUnit.compilationResult);
4160         }
4161         // too many closing brackets ?
4162         for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4163           anomaliesDetected = true;
4164           problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
4165         }
4166         if (anomaliesDetected)
4167           return true;
4168       }
4169       return anomaliesDetected;
4170     } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4171       return anomaliesDetected;
4172     } catch (NullPointerException e) { // jdk1.2.2 jit bug
4173       return anomaliesDetected;
4174     }
4175   }
4176
4177   protected void pushOnAstLengthStack(int pos) {
4178     try {
4179       astLengthStack[++astLengthPtr] = pos;
4180     } catch (IndexOutOfBoundsException e) {
4181       int oldStackLength = astLengthStack.length;
4182       int[] oldPos = astLengthStack;
4183       astLengthStack = new int[oldStackLength + StackIncrement];
4184       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4185       astLengthStack[astLengthPtr] = pos;
4186     }
4187   }
4188
4189   protected void pushOnAstStack(ASTNode node) {
4190     /*
4191      * add a new obj on top of the ast stack
4192      */
4193     try {
4194       astStack[++astPtr] = node;
4195     } catch (IndexOutOfBoundsException e) {
4196       int oldStackLength = astStack.length;
4197       ASTNode[] oldStack = astStack;
4198       astStack = new ASTNode[oldStackLength + AstStackIncrement];
4199       System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4200       astPtr = oldStackLength;
4201       astStack[astPtr] = node;
4202     }
4203     try {
4204       astLengthStack[++astLengthPtr] = 1;
4205     } catch (IndexOutOfBoundsException e) {
4206       int oldStackLength = astLengthStack.length;
4207       int[] oldPos = astLengthStack;
4208       astLengthStack = new int[oldStackLength + AstStackIncrement];
4209       System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4210       astLengthStack[astLengthPtr] = 1;
4211     }
4212   }
4213
4214   protected void resetModifiers() {
4215     this.modifiers = AccDefault;
4216     this.modifiersSourceStart = -1; // <-- see comment into
4217     // modifiersFlag(int)
4218     this.scanner.commentPtr = -1;
4219   }
4220 }