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