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