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