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
6 * Contributors: www.phpeclipse.de
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
12 import net.sourceforge.phpdt.core.compiler.CharOperation;
13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
14 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
15 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
16 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
17 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
18 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
19 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
20 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
21 import net.sourceforge.phpdt.internal.compiler.util.Util;
22 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
23 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
24 import net.sourceforge.phpeclipse.internal.compiler.ast.AND_AND_Expression;
25 import net.sourceforge.phpeclipse.internal.compiler.ast.ASTNode;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.BinaryExpression;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.ConditionalExpression;
30 import net.sourceforge.phpeclipse.internal.compiler.ast.EqualExpression;
31 import net.sourceforge.phpeclipse.internal.compiler.ast.Expression;
32 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
33 import net.sourceforge.phpeclipse.internal.compiler.ast.IfStatement;
34 import net.sourceforge.phpeclipse.internal.compiler.ast.ImportReference;
35 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
36 import net.sourceforge.phpeclipse.internal.compiler.ast.OR_OR_Expression;
37 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
38 import net.sourceforge.phpeclipse.internal.compiler.ast.Statement;
39 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
40 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralDQ;
41 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteralSQ;
42 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
44 import org.eclipse.core.resources.IFile;
45 import org.eclipse.core.resources.IProject;
46 import org.eclipse.core.resources.IResource;
47 import org.eclipse.core.runtime.IPath;
49 public class Parser //extends PHPParserSuperclass
50 implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
51 //internal data for the automat
52 protected final static int StackIncrement = 255;
54 protected int stateStackTop;
56 protected int[] stack = new int[StackIncrement];
58 public int firstToken; // handle for multiple parsing goals
60 public int lastAct; //handle for multiple parsing goals
62 protected RecoveredElement currentElement;
64 public static boolean VERBOSE_RECOVERY = false;
66 protected boolean diet = false; //tells the scanner to jump over some
68 // parts of the code/expressions like
71 public Scanner scanner;
73 private ArrayList phpList;
75 private int currentPHPString;
77 private boolean phpEnd;
79 // private static HashMap keywordMap = null;
87 // row counter for syntax errors:
89 // column counter for syntax errors:
93 // // current identifier
99 private String stringValue;
101 /** Contains the current expression. */
102 // private StringBuffer expression;
103 //private boolean phpMode;
104 protected int modifiers;
106 protected int modifiersSourceStart;
108 // protected IdentifierIndexManager indexManager;
110 protected Parser(ProblemReporter problemReporter) {
111 this.problemReporter = problemReporter;
112 this.options = problemReporter.options;
113 this.currentPHPString = 0;
114 // PHPParserSuperclass.fileToParse = fileToParse;
116 // this.indexManager = null;
118 this.token = TokenNameEOF;
120 // this.rowCount = 1;
121 // this.columnCount = 0;
124 this.initializeScanner();
127 public void setFileToParse(IFile fileToParse) {
128 this.currentPHPString = 0;
129 // PHPParserSuperclass.fileToParse = fileToParse;
131 // this.indexManager = null;
133 this.token = TokenNameEOF;
135 this.initializeScanner();
139 * ClassDeclaration Constructor.
143 * Description of Parameter
146 public Parser(IFile fileToParse) {
147 // if (keywordMap == null) {
148 // keywordMap = new HashMap();
149 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
150 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
153 this.currentPHPString = 0;
154 // PHPParserSuperclass.fileToParse = fileToParse;
156 this.includesList = null;
158 this.token = TokenNameEOF;
160 // this.rowCount = 1;
161 // this.columnCount = 0;
164 this.initializeScanner();
167 public void initializeScanner() {
168 this.scanner = new Scanner(false /* comment */, false /* whitespace */, this.options
169 .getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /* nls */, false, false,
170 this.options.taskTags/* taskTags */,
171 this.options.taskPriorites/* taskPriorities */,
172 true/*isTaskCaseSensitive*/);
176 * Create marker for the parse error
178 // private void setMarker(String message, int charStart, int charEnd, int
180 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
183 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
187 * @throws SyntaxError
190 private void throwSyntaxError(String error) {
191 int problemStartPosition = scanner.getCurrentTokenStartPosition();
192 int problemEndPosition = scanner.getCurrentTokenEndPosition();
193 throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
197 * This method will throw the SyntaxError. It will add the good lines and columns to the Error
201 * @throws SyntaxError
204 // private void throwSyntaxError(String error, int startRow) {
205 // throw new SyntaxError(startRow, 0, " ", error);
207 private void throwSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
208 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
209 compilationUnit.compilationResult);
210 throw new SyntaxError(1, 0, " ", error);
213 private void reportSyntaxError(String error) {
214 int problemStartPosition = scanner.getCurrentTokenStartPosition();
215 int problemEndPosition = scanner.getCurrentTokenEndPosition();
216 reportSyntaxError(error, problemStartPosition, problemEndPosition + 1);
219 private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) {
220 problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
221 compilationUnit.compilationResult);
224 private void reportSyntaxWarning(String error, int problemStartPosition, int problemEndPosition) {
225 problemReporter.phpParsingWarning(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext,
226 compilationUnit.compilationResult);
230 * gets the next token from input
232 private void getNextToken() {
234 token = scanner.getNextToken();
236 int currentEndPosition = scanner.getCurrentTokenEndPosition();
237 int currentStartPosition = scanner.getCurrentTokenStartPosition();
238 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
239 System.out.println(scanner.toStringAction(token));
241 } catch (InvalidInputException e) {
242 token = TokenNameERROR;
243 String detailedMessage = e.getMessage();
245 if (detailedMessage == Scanner.UNTERMINATED_STRING) {
246 throwSyntaxError("Unterminated string.");
247 } else if (detailedMessage == Scanner.UNTERMINATED_COMMENT) {
248 throwSyntaxError("Unterminated commment.");
254 public void init(String s) {
256 this.token = TokenNameEOF;
258 // this.rowCount = 1;
259 // this.columnCount = 0;
261 // this.phpMode = false;
262 /* scanner initialization */
263 scanner.setSource(s.toCharArray());
264 scanner.setPHPMode(false);
267 protected void initialize(boolean phpMode) {
268 initialize(phpMode, null);
271 protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
272 compilationUnit = null;
273 referenceContext = null;
274 includesList = new ArrayList();
275 // this.indexManager = indexManager;
277 this.token = TokenNameEOF;
279 // this.rowCount = 1;
280 // this.columnCount = 0;
282 // this.phpMode = phpMode;
283 scanner.setPHPMode(phpMode);
287 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
289 public void parse(String s) {
295 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?> </body>'
297 protected void parse() {
301 if (token != TokenNameEOF && token != TokenNameERROR) {
304 if (token != TokenNameEOF) {
305 if (token == TokenNameERROR) {
306 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
308 if (token == TokenNameRPAREN) {
309 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
311 if (token == TokenNameRBRACE) {
312 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
314 if (token == TokenNameRBRACKET) {
315 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
317 if (token == TokenNameLPAREN) {
318 throwSyntaxError("Read character '('; end-of-file not reached.");
320 if (token == TokenNameLBRACE) {
321 throwSyntaxError("Read character '{'; end-of-file not reached.");
323 if (token == TokenNameLBRACKET) {
324 throwSyntaxError("Read character '['; end-of-file not reached.");
326 throwSyntaxError("End-of-file not reached.");
329 } catch (SyntaxError sytaxErr1) {
330 // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
332 // setMarker(sytaxErr1.getMessage(),
333 // scanner.getCurrentTokenStartPosition(),
334 // scanner.getCurrentTokenEndPosition(), ERROR);
336 // if an error occured,
337 // try to find keywords 'class' or 'function'
338 // to parse the rest of the string
339 while (token != TokenNameEOF && token != TokenNameERROR) {
340 if (token == TokenNameabstract || token == TokenNamefinal || token == TokenNameclass || token == TokenNamefunction) {
345 if (token == TokenNameEOF || token == TokenNameERROR) {
348 } catch (SyntaxError sytaxErr2) {
349 // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
351 // setMarker(sytaxErr2.getMessage(),
352 // scanner.getCurrentTokenStartPosition(),
353 // scanner.getCurrentTokenEndPosition(), ERROR);
362 protected CompilationUnitDeclaration endParse(int act) {
366 if (currentElement != null) {
367 currentElement.topElement().updateParseTree();
368 if (VERBOSE_RECOVERY) {
369 System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
370 System.out.println("--------------------------"); //$NON-NLS-1$
371 System.out.println(compilationUnit);
372 System.out.println("----------------------------------"); //$NON-NLS-1$
375 if (diet & VERBOSE_RECOVERY) {
376 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
377 System.out.println("--------------------------"); //$NON-NLS-1$
378 System.out.println(compilationUnit);
379 System.out.println("----------------------------------"); //$NON-NLS-1$
382 if (scanner.recordLineSeparator) {
383 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
385 if (scanner.taskTags != null) {
386 for (int i = 0; i < scanner.foundTaskCount; i++) {
387 problemReporter().task(new String(scanner.foundTaskTags[i]), new String(scanner.foundTaskMessages[i]),
388 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
389 scanner.foundTaskPositions[i][0], scanner.foundTaskPositions[i][1]);
392 compilationUnit.imports = new ImportReference[includesList.size()];
393 for (int i = 0; i < includesList.size(); i++) {
394 compilationUnit.imports[i] = (ImportReference) includesList.get(i);
396 return compilationUnit;
399 // public PHPOutlineInfo parseInfo(Object parent, String s) {
400 // PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
401 // // Stack stack = new Stack();
402 // // stack.push(outlineInfo.getDeclarations());
404 // this.token = TokenNameEOF;
405 // // this.chIndx = 0;
406 // // this.rowCount = 1;
407 // // this.columnCount = 0;
408 // this.phpEnd = false;
409 // this.phpMode = false;
410 // scanner.setSource(s.toCharArray());
411 // scanner.setPHPMode(false);
414 // parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
416 // return outlineInfo;
418 private boolean isVariable() {
419 return token == TokenNameVariable; // || token == TokenNamethis;
422 // private void parseDeclarations(PHPOutlineInfo outlineInfo,
423 // OutlineableWithChildren current, boolean goBack) {
425 // // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
426 // PHPSegmentWithChildren temp;
428 // IPreferenceStore store =
429 // PHPeclipsePlugin.getDefault().getPreferenceStore();
431 // while (token != TokenNameEOF && token != TokenNameERROR) {
432 // if (token == TokenNameVariable) {
433 // ident = scanner.getCurrentIdentifierSource();
434 // outlineInfo.addVariable(new String(ident));
436 // } else if (token == TokenNamevar) {
438 // if (token == TokenNameVariable
439 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
440 // ident = scanner.getCurrentIdentifierSource();
441 // //substring(1) added because PHPVarDeclaration doesn't
442 // // need the $ anymore
443 // String variableName = new String(ident).substring(1);
444 // outlineInfo.addVariable(variableName);
446 // if (token != TokenNameSEMICOLON) {
448 // ident = scanner.getCurrentTokenSource();
449 // if (token > TokenNameKEYWORD) {
450 // current.add(new PHPVarDeclaration(current, variableName,
451 // // chIndx - ident.length,
452 // scanner.getCurrentTokenStartPosition(), new String(ident)));
455 // case TokenNameVariable :
456 // case TokenNamethis :
457 // current.add(new PHPVarDeclaration(current, variableName,
460 // scanner.getCurrentTokenStartPosition(), new String(
463 // case TokenNameIdentifier :
464 // current.add(new PHPVarDeclaration(current, variableName,
467 // scanner.getCurrentTokenStartPosition(), new String(
470 // case TokenNameDoubleLiteral :
471 // current.add(new PHPVarDeclaration(current, variableName
475 // scanner.getCurrentTokenStartPosition(), new String(
478 // case TokenNameIntegerLiteral :
479 // current.add(new PHPVarDeclaration(current, variableName,
482 // scanner.getCurrentTokenStartPosition(), new String(
485 // case TokenNameStringInterpolated :
486 // case TokenNameStringLiteral :
487 // current.add(new PHPVarDeclaration(current, variableName,
490 // scanner.getCurrentTokenStartPosition(), new String(
493 // case TokenNameStringConstant :
494 // current.add(new PHPVarDeclaration(current, variableName,
497 // scanner.getCurrentTokenStartPosition(), new String(
501 // current.add(new PHPVarDeclaration(current, variableName,
504 // scanner.getCurrentTokenStartPosition()));
509 // ident = scanner.getCurrentIdentifierSource();
510 // current.add(new PHPVarDeclaration(current, variableName,
511 // // chIndx - ident.length
512 // scanner.getCurrentTokenStartPosition()));
515 // } else if (token == TokenNamefunction) {
517 // if (token == TokenNameAND) {
520 // if (token == TokenNameIdentifier
521 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
522 // ident = scanner.getCurrentIdentifierSource();
523 // outlineInfo.addVariable(new String(ident));
524 // temp = new PHPFunctionDeclaration(current, new String(ident),
525 // // chIndx - ident.length
526 // scanner.getCurrentTokenStartPosition());
527 // current.add(temp);
529 // parseDeclarations(outlineInfo, temp, true);
531 // } else if (token == TokenNameclass) {
533 // if (token == TokenNameIdentifier
534 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
535 // ident = scanner.getCurrentIdentifierSource();
536 // outlineInfo.addVariable(new String(ident));
537 // temp = new PHPClassDeclaration(current, new String(ident),
538 // // chIndx - ident.len
539 // scanner.getCurrentTokenStartPosition());
540 // current.add(temp);
541 // // stack.push(temp);
543 // //skip tokens for classname, extends and others until
544 // // we have the opening '{'
545 // while (token != TokenNameLBRACE && token != TokenNameEOF
546 // && token != TokenNameERROR) {
549 // parseDeclarations(outlineInfo, temp, true);
552 // } else if ((token == TokenNameLBRACE)
553 // || (token == TokenNameDOLLAR_LBRACE)) {
556 // } else if (token == TokenNameRBRACE) {
559 // if (counter == 0 && goBack) {
562 // } else if (token == TokenNamerequire || token == TokenNamerequire_once
563 // || token == TokenNameinclude || token == TokenNameinclude_once) {
564 // ident = scanner.getCurrentTokenSource();
566 // int startPosition = scanner.getCurrentTokenStartPosition();
568 // char[] expr = scanner.getCurrentTokenSource(startPosition);
569 // outlineInfo.addVariable(new String(ident));
570 // current.add(new PHPReqIncDeclaration(current, new String(ident),
571 // // chIndx - ident.length,
572 // startPosition, new String(expr)));
578 // } catch (SyntaxError sytaxErr) {
580 // // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
581 // // setMarker(sytaxErr.getMessage(),
582 // // scanner.getCurrentTokenStartPosition(),
583 // // scanner.getCurrentTokenEndPosition(), ERROR);
584 // // } catch (CoreException e) {
588 private void statementList() {
590 statement(TokenNameEOF);
591 if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse)
592 || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)
593 || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch)
594 || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) {
600 private void functionBody(MethodDeclaration methodDecl) {
601 // '{' [statement-list] '}'
602 if (token == TokenNameLBRACE) {
605 throwSyntaxError("'{' expected in compound-statement.");
607 if (token != TokenNameRBRACE) {
610 if (token == TokenNameRBRACE) {
611 methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
614 throwSyntaxError("'}' expected in compound-statement.");
618 private Statement statement(int previousToken) {
619 Statement statement = null;
620 Expression expression;
621 int sourceStart = scanner.getCurrentTokenStartPosition();
622 if (token == TokenNameif) {
624 if (token == TokenNameLPAREN) {
627 throwSyntaxError("'(' expected after 'if' keyword.");
630 if (token == TokenNameRPAREN) {
633 throwSyntaxError("')' expected after 'if' condition.");
636 return new IfStatement(expression, statement, sourceStart, scanner.getCurrentTokenEndPosition());
637 } else if (token == TokenNameswitch) {
639 if (token == TokenNameLPAREN) {
642 throwSyntaxError("'(' expected after 'switch' keyword.");
645 if (token == TokenNameRPAREN) {
648 throwSyntaxError("')' expected after 'switch' condition.");
652 } else if (token == TokenNamefor) {
654 if (token == TokenNameLPAREN) {
657 throwSyntaxError("'(' expected after 'for' keyword.");
659 if (token == TokenNameSEMICOLON) {
663 if (token == TokenNameSEMICOLON) {
666 throwSyntaxError("';' expected after 'for'.");
669 if (token == TokenNameSEMICOLON) {
673 if (token == TokenNameSEMICOLON) {
676 throwSyntaxError("';' expected after 'for'.");
679 if (token == TokenNameRPAREN) {
683 if (token == TokenNameRPAREN) {
686 throwSyntaxError("')' expected after 'for'.");
691 } else if (token == TokenNamewhile) {
693 if (token == TokenNameLPAREN) {
696 throwSyntaxError("'(' expected after 'while' keyword.");
699 if (token == TokenNameRPAREN) {
702 throwSyntaxError("')' expected after 'while' condition.");
706 } else if (token == TokenNamedo) {
708 if (token == TokenNameLBRACE) {
710 if (token != TokenNameRBRACE) {
713 if (token == TokenNameRBRACE) {
716 throwSyntaxError("'}' expected after 'do' keyword.");
719 statement(TokenNameEOF);
721 if (token == TokenNamewhile) {
723 if (token == TokenNameLPAREN) {
726 throwSyntaxError("'(' expected after 'while' keyword.");
729 if (token == TokenNameRPAREN) {
732 throwSyntaxError("')' expected after 'while' condition.");
735 throwSyntaxError("'while' expected after 'do' keyword.");
737 if (token == TokenNameSEMICOLON) {
740 if (token != TokenNameINLINE_HTML) {
741 throwSyntaxError("';' expected after do-while statement.");
746 } else if (token == TokenNameforeach) {
748 if (token == TokenNameLPAREN) {
751 throwSyntaxError("'(' expected after 'foreach' keyword.");
754 if (token == TokenNameas) {
757 throwSyntaxError("'as' expected after 'foreach' exxpression.");
761 foreach_optional_arg();
762 if (token == TokenNameEQUAL_GREATER) {
766 if (token == TokenNameRPAREN) {
769 throwSyntaxError("')' expected after 'foreach' expression.");
773 } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
775 if (token != TokenNameSEMICOLON) {
778 if (token == TokenNameSEMICOLON) {
781 if (token != TokenNameINLINE_HTML) {
782 throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
787 } else if (token == TokenNameecho) {
790 if (token == TokenNameSEMICOLON) {
793 if (token != TokenNameINLINE_HTML) {
794 throwSyntaxError("';' expected after 'echo' statement.");
799 } else if (token == TokenNameINLINE_HTML) {
802 // } else if (token == TokenNameprint) {
805 // if (token == TokenNameSEMICOLON) {
808 // if (token != TokenNameStopPHP) {
809 // throwSyntaxError("';' expected after 'print' statement.");
814 } else if (token == TokenNameglobal) {
817 if (token == TokenNameSEMICOLON) {
820 if (token != TokenNameINLINE_HTML) {
821 throwSyntaxError("';' expected after 'global' statement.");
826 } else if (token == TokenNamestatic) {
829 if (token == TokenNameSEMICOLON) {
832 if (token != TokenNameINLINE_HTML) {
833 throwSyntaxError("';' expected after 'static' statement.");
838 } else if (token == TokenNameunset) {
840 if (token == TokenNameLPAREN) {
843 throwSyntaxError("'(' expected after 'unset' statement.");
846 if (token == TokenNameRPAREN) {
849 throwSyntaxError("')' expected after 'unset' statement.");
851 if (token == TokenNameSEMICOLON) {
854 if (token != TokenNameINLINE_HTML) {
855 throwSyntaxError("';' expected after 'unset' statement.");
860 } else if (token == TokenNamefunction) {
861 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
862 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
863 methodDecl.modifiers = AccDefault;
865 functionDefinition(methodDecl);
867 } else if (token == TokenNamedeclare) {
868 //T_DECLARE '(' declare_list ')' declare_statement
870 if (token != TokenNameLPAREN) {
871 throwSyntaxError("'(' expected in 'declare' statement.");
875 if (token != TokenNameRPAREN) {
876 throwSyntaxError("')' expected in 'declare' statement.");
881 } else if (token == TokenNametry) {
883 if (token != TokenNameLBRACE) {
884 throwSyntaxError("'{' expected in 'try' statement.");
888 if (token != TokenNameRBRACE) {
889 throwSyntaxError("'}' expected in 'try' statement.");
893 } else if (token == TokenNamecatch) {
895 if (token != TokenNameLPAREN) {
896 throwSyntaxError("'(' expected in 'catch' statement.");
899 fully_qualified_class_name();
900 if (token != TokenNameVariable) {
901 throwSyntaxError("Variable expected in 'catch' statement.");
904 if (token != TokenNameRPAREN) {
905 throwSyntaxError("')' expected in 'catch' statement.");
908 if (token != TokenNameLBRACE) {
909 throwSyntaxError("'{' expected in 'catch' statement.");
912 if (token != TokenNameRBRACE) {
914 if (token != TokenNameRBRACE) {
915 throwSyntaxError("'}' expected in 'catch' statement.");
919 additional_catches();
921 } else if (token == TokenNamethrow) {
924 if (token == TokenNameSEMICOLON) {
927 throwSyntaxError("';' expected after 'throw' exxpression.");
930 } else if (token == TokenNamefinal || token == TokenNameabstract || token == TokenNameclass || token == TokenNameinterface) {
931 TypeDeclaration typeDecl = new TypeDeclaration(this.compilationUnit.compilationResult);
932 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
933 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
934 typeDecl.name = new char[] { ' ' };
935 // default super class
936 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
937 compilationUnit.types.add(typeDecl);
939 pushOnAstStack(typeDecl);
940 unticked_class_declaration_statement(typeDecl);
941 // classBody(typeDecl);
948 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
949 } else if (token == TokenNameLBRACE) {
951 if (token != TokenNameRBRACE) {
954 if (token == TokenNameRBRACE) {
958 throwSyntaxError("'}' expected.");
961 if (token != TokenNameSEMICOLON) {
964 if (token == TokenNameSEMICOLON) {
968 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
969 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
978 private void declare_statement() {
980 //| ':' inner_statement_list T_ENDDECLARE ';'
982 if (token == TokenNameCOLON) {
984 // TODO: implement inner_statement_list();
986 if (token != TokenNameenddeclare) {
987 throwSyntaxError("'enddeclare' expected in 'declare' statement.");
990 if (token != TokenNameSEMICOLON) {
991 throwSyntaxError("';' expected after 'enddeclare' keyword.");
995 statement(TokenNameRPAREN);
999 private void declare_list() {
1000 // T_STRING '=' static_scalar
1001 //| declare_list ',' T_STRING '=' static_scalar
1003 if (token != TokenNameIdentifier) {
1004 throwSyntaxError("Identifier expected in 'declare' list.");
1007 if (token != TokenNameEQUAL) {
1008 throwSyntaxError("'=' expected in 'declare' list.");
1012 if (token != TokenNameCOMMA) {
1019 private void additional_catches() {
1020 while (token == TokenNamecatch) {
1022 if (token != TokenNameLPAREN) {
1023 throwSyntaxError("'(' expected in 'catch' statement.");
1026 fully_qualified_class_name();
1027 if (token != TokenNameVariable) {
1028 throwSyntaxError("Variable expected in 'catch' statement.");
1031 if (token != TokenNameRPAREN) {
1032 throwSyntaxError("')' expected in 'catch' statement.");
1035 if (token != TokenNameLBRACE) {
1036 throwSyntaxError("'{' expected in 'catch' statement.");
1039 if (token != TokenNameRBRACE) {
1042 if (token != TokenNameRBRACE) {
1043 throwSyntaxError("'}' expected in 'catch' statement.");
1049 private void foreach_variable() {
1052 if (token == TokenNameAND) {
1058 private void foreach_optional_arg() {
1060 //| T_DOUBLE_ARROW foreach_variable
1061 if (token == TokenNameEQUAL_GREATER) {
1067 private void global_var_list() {
1069 // global_var_list ',' global_var
1073 if (token != TokenNameCOMMA) {
1080 private void global_var() {
1084 //| '$' '{' expr '}'
1085 if (token == TokenNameVariable) {
1087 } else if (token == TokenNameDOLLAR) {
1089 if (token == TokenNameLPAREN) {
1092 if (token != TokenNameLPAREN) {
1093 throwSyntaxError("')' expected in global variable.");
1102 private void static_var_list() {
1104 // static_var_list ',' T_VARIABLE
1105 //| static_var_list ',' T_VARIABLE '=' static_scalar
1107 //| T_VARIABLE '=' static_scalar
1109 if (token == TokenNameVariable) {
1111 if (token == TokenNameEQUAL) {
1115 if (token != TokenNameCOMMA) {
1125 private void unset_variables() {
1128 // | unset_variables ',' unset_variable
1133 if (token != TokenNameCOMMA) {
1140 private final void initializeModifiers() {
1142 this.modifiersSourceStart = -1;
1145 private final void checkAndSetModifiers(int flag) {
1146 this.modifiers |= flag;
1147 if (this.modifiersSourceStart < 0)
1148 this.modifiersSourceStart = this.scanner.startPosition;
1151 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1152 initializeModifiers();
1153 if (token == TokenNameinterface) {
1154 // interface_entry T_STRING
1155 // interface_extends_list
1156 // '{' class_statement_list '}'
1157 checkAndSetModifiers(AccInterface);
1159 typeDecl.modifiers = this.modifiers;
1160 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1161 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1162 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1163 typeDecl.name = scanner.getCurrentIdentifierSource();
1164 if (token > TokenNameKEYWORD) {
1165 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1166 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1167 // throwSyntaxError("Don't use a keyword for interface declaration [" + scanner.toStringAction(token) + "].",
1168 // typeDecl.sourceStart, typeDecl.sourceEnd);
1171 interface_extends_list(typeDecl);
1173 typeDecl.name = new char[] { ' ' };
1174 throwSyntaxError("Interface name expected after keyword 'interface'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1178 // class_entry_type T_STRING extends_from
1180 // '{' class_statement_list'}'
1182 typeDecl.modifiers = this.modifiers;
1183 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1184 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1186 //identifier 'extends' identifier
1187 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1188 typeDecl.name = scanner.getCurrentIdentifierSource();
1189 if (token > TokenNameKEYWORD) {
1190 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1191 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1192 // throwSyntaxError("Don't use a keyword for class declaration [" + scanner.toStringAction(token) + "].",
1193 // typeDecl.sourceStart, typeDecl.sourceEnd);
1198 // | T_EXTENDS fully_qualified_class_name
1199 if (token == TokenNameextends) {
1200 interface_extends_list(typeDecl);
1202 // if (token != TokenNameIdentifier) {
1203 // throwSyntaxError("Class name expected after keyword
1205 // scanner.getCurrentTokenStartPosition(), scanner
1206 // .getCurrentTokenEndPosition());
1209 implements_list(typeDecl);
1211 typeDecl.name = new char[] { ' ' };
1212 throwSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd);
1216 // '{' class_statement_list '}'
1217 if (token == TokenNameLBRACE) {
1219 if (token != TokenNameRBRACE) {
1220 ArrayList list = new ArrayList();
1221 class_statement_list(list);
1222 typeDecl.fields = new FieldDeclaration[list.size()];
1223 for (int i = 0; i < list.size(); i++) {
1224 typeDecl.fields[i] = (FieldDeclaration) list.get(i);
1227 if (token == TokenNameRBRACE) {
1228 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1231 throwSyntaxError("'}' expected at end of class body.");
1234 throwSyntaxError("'{' expected at start of class body.");
1238 private void class_entry_type() {
1240 // | T_ABSTRACT T_CLASS
1241 // | T_FINAL T_CLASS
1242 if (token == TokenNameclass) {
1244 } else if (token == TokenNameabstract) {
1245 checkAndSetModifiers(AccAbstract);
1247 if (token != TokenNameclass) {
1248 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1251 } else if (token == TokenNamefinal) {
1252 checkAndSetModifiers(AccFinal);
1254 if (token != TokenNameclass) {
1255 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1259 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1263 private void class_extends(TypeDeclaration typeDecl) {
1265 // | T_EXTENDS interface_list
1266 if (token == TokenNameextends) {
1269 if (token == TokenNameIdentifier) {
1272 throwSyntaxError("Class name expected after keyword 'extends'.");
1277 private void interface_extends_list(TypeDeclaration typeDecl) {
1279 // | T_EXTENDS interface_list
1280 if (token == TokenNameextends) {
1286 private void implements_list(TypeDeclaration typeDecl) {
1288 // | T_IMPLEMENTS interface_list
1289 if (token == TokenNameimplements) {
1295 private void interface_list() {
1297 // fully_qualified_class_name
1298 //| interface_list ',' fully_qualified_class_name
1300 if (token == TokenNameIdentifier) {
1303 throwSyntaxError("Interface name expected after keyword 'implements'.");
1305 if (token != TokenNameCOMMA) {
1312 // private void classBody(TypeDeclaration typeDecl) {
1313 // //'{' [class-element-list] '}'
1314 // if (token == TokenNameLBRACE) {
1316 // if (token != TokenNameRBRACE) {
1317 // class_statement_list();
1319 // if (token == TokenNameRBRACE) {
1320 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1323 // throwSyntaxError("'}' expected at end of class body.");
1326 // throwSyntaxError("'{' expected at start of class body.");
1329 private void class_statement_list(ArrayList list) {
1331 class_statement(list);
1332 } while (token == TokenNamepublic || token == TokenNameprotected || token == TokenNameprivate || token == TokenNamestatic
1333 || token == TokenNameabstract || token == TokenNamefinal || token == TokenNamefunction || token == TokenNamevar
1334 || token == TokenNameconst);
1337 private void class_statement(ArrayList list) {
1339 // variable_modifiers class_variable_declaration ';'
1340 // | class_constant_declaration ';'
1341 // | method_modifiers T_FUNCTION is_reference T_STRING
1342 // '(' parameter_list ')' method_body
1343 initializeModifiers();
1344 int declarationSourceStart = scanner.getCurrentTokenStartPosition();
1346 if (token == TokenNamevar) {
1347 checkAndSetModifiers(AccPublic);
1348 problemReporter.phpVarDeprecatedWarning(scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(),
1349 referenceContext, compilationUnit.compilationResult);
1351 class_variable_declaration(declarationSourceStart, list);
1352 } else if (token == TokenNameconst) {
1353 checkAndSetModifiers(AccFinal | AccPublic);
1354 class_constant_declaration(declarationSourceStart, list);
1355 if (token != TokenNameSEMICOLON) {
1356 throwSyntaxError("';' expected after class const declaration.");
1360 boolean hasModifiers = member_modifiers();
1361 if (token == TokenNamefunction) {
1362 if (!hasModifiers) {
1363 checkAndSetModifiers(AccPublic);
1365 MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
1366 methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
1367 methodDecl.modifiers = this.modifiers;
1369 functionDefinition(methodDecl);
1371 if (!hasModifiers) {
1372 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1374 class_variable_declaration(declarationSourceStart, list);
1379 private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
1380 // class_constant_declaration ',' T_STRING '=' static_scalar
1381 // | T_CONST T_STRING '=' static_scalar
1382 if (token != TokenNameconst) {
1383 throwSyntaxError("'const' keyword expected in class declaration.");
1388 if (token != TokenNameIdentifier) {
1389 throwSyntaxError("Identifier expected in class const declaration.");
1391 FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
1392 .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1393 fieldDeclaration.modifiers = this.modifiers;
1394 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1395 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1396 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1397 // fieldDeclaration.type
1398 list.add(fieldDeclaration);
1400 if (token != TokenNameEQUAL) {
1401 throwSyntaxError("'=' expected in class const declaration.");
1405 if (token != TokenNameCOMMA) {
1406 break; // while(true)-loop
1412 // private void variable_modifiers() {
1413 // // variable_modifiers:
1414 // // non_empty_member_modifiers
1416 // initializeModifiers();
1417 // if (token == TokenNamevar) {
1418 // checkAndSetModifiers(AccPublic);
1419 // reportSyntaxError(
1420 // "Keyword 'var' is deprecated. Please use 'public' 'private' or
1422 // modifier for field declarations.",
1423 // scanner.getCurrentTokenStartPosition(), scanner
1424 // .getCurrentTokenEndPosition());
1427 // if (!member_modifiers()) {
1428 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1429 // field declarations.");
1433 // private void method_modifiers() {
1434 // //method_modifiers:
1436 // //| non_empty_member_modifiers
1437 // initializeModifiers();
1438 // if (!member_modifiers()) {
1439 // checkAndSetModifiers(AccPublic);
1442 private boolean member_modifiers() {
1449 boolean foundToken = false;
1451 if (token == TokenNamepublic) {
1452 checkAndSetModifiers(AccPublic);
1455 } else if (token == TokenNameprotected) {
1456 checkAndSetModifiers(AccProtected);
1459 } else if (token == TokenNameprivate) {
1460 checkAndSetModifiers(AccPrivate);
1463 } else if (token == TokenNamestatic) {
1464 checkAndSetModifiers(AccStatic);
1467 } else if (token == TokenNameabstract) {
1468 checkAndSetModifiers(AccAbstract);
1471 } else if (token == TokenNamefinal) {
1472 checkAndSetModifiers(AccFinal);
1482 private void class_variable_declaration(int declarationSourceStart, ArrayList list) {
1483 // class_variable_declaration:
1484 // class_variable_declaration ',' T_VARIABLE
1485 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1487 // | T_VARIABLE '=' static_scalar
1488 char[] classVariable;
1490 if (token == TokenNameVariable) {
1491 classVariable = scanner.getCurrentIdentifierSource();
1492 // indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
1493 FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner.getCurrentTokenStartPosition(), scanner
1494 .getCurrentTokenEndPosition());
1495 fieldDeclaration.modifiers = this.modifiers;
1496 fieldDeclaration.declarationSourceStart = declarationSourceStart;
1497 fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1498 fieldDeclaration.modifiersSourceStart = declarationSourceStart;
1499 // fieldDeclaration.type
1500 list.add(fieldDeclaration);
1502 if (token == TokenNameEQUAL) {
1507 // if (token == TokenNamethis) {
1508 // throwSyntaxError("'$this' not allowed after keyword 'public'
1509 // 'protected' 'private' 'var'.");
1511 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1513 if (token != TokenNameCOMMA) {
1518 if (token != TokenNameSEMICOLON) {
1519 throwSyntaxError("';' expected after field declaration.");
1524 private void functionDefinition(MethodDeclaration methodDecl) {
1525 boolean isAbstract = false;
1527 compilationUnit.types.add(methodDecl);
1529 ASTNode node = astStack[astPtr];
1530 if (node instanceof TypeDeclaration) {
1531 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1532 if (typeDecl.methods == null) {
1533 typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl };
1535 AbstractMethodDeclaration[] newMethods;
1536 System.arraycopy(typeDecl.methods, 0, newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], 1,
1537 typeDecl.methods.length);
1538 newMethods[0] = methodDecl;
1539 typeDecl.methods = newMethods;
1541 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1543 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1548 functionDeclarator(methodDecl);
1549 if (token == TokenNameSEMICOLON) {
1551 throwSyntaxError("Body declaration expected for method: " + new String(methodDecl.selector));
1556 functionBody(methodDecl);
1559 private void functionDeclarator(MethodDeclaration methodDecl) {
1560 //identifier '(' [parameter-list] ')'
1561 if (token == TokenNameAND) {
1564 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1565 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1566 if (Scanner.isIdentifierOrKeyword(token)) {
1567 methodDecl.selector = scanner.getCurrentIdentifierSource();
1568 if (token > TokenNameKEYWORD) {
1569 problemReporter.phpKeywordWarning(new String[] { scanner.toStringAction(token) }, scanner.getCurrentTokenStartPosition(),
1570 scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult);
1571 // reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
1572 // scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
1575 if (token == TokenNameLPAREN) {
1578 throwSyntaxError("'(' expected in function declaration.");
1580 if (token != TokenNameRPAREN) {
1583 if (token != TokenNameRPAREN) {
1584 throwSyntaxError("')' expected in function declaration.");
1586 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1590 methodDecl.selector = "<undefined>".toCharArray();
1591 throwSyntaxError("Function name expected after keyword 'function'.");
1596 private void parameter_list() {
1597 // non_empty_parameter_list
1599 non_empty_parameter_list(true);
1602 private void non_empty_parameter_list(boolean empty_allowed) {
1603 // optional_class_type T_VARIABLE
1604 // | optional_class_type '&' T_VARIABLE
1605 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1606 // | optional_class_type T_VARIABLE '=' static_scalar
1607 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1608 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1609 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1611 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1613 if (token == TokenNameIdentifier || token == TokenNameVariable || token == TokenNameAND) {
1615 if (token == TokenNameIdentifier) {
1618 if (token == TokenNameAND) {
1621 if (token == TokenNameVariable) {
1623 if (token == TokenNameEQUAL) {
1628 throwSyntaxError("Variable expected in parameter list.");
1630 if (token != TokenNameCOMMA) {
1637 if (!empty_allowed) {
1638 throwSyntaxError("Identifier expected in parameter list.");
1642 private void optional_class_type() {
1647 private void parameterDeclaration() {
1649 //variable-reference
1650 if (token == TokenNameAND) {
1655 throwSyntaxError("Variable expected after reference operator '&'.");
1658 //variable '=' constant
1659 if (token == TokenNameVariable) {
1661 if (token == TokenNameEQUAL) {
1667 // if (token == TokenNamethis) {
1668 // throwSyntaxError("Reserved word '$this' not allowed in parameter
1673 private void labeledStatementList() {
1674 if (token != TokenNamecase && token != TokenNamedefault) {
1675 throwSyntaxError("'case' or 'default' expected.");
1678 if (token == TokenNamecase) {
1680 expr(); //constant();
1681 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1683 if (token == TokenNamecase || token == TokenNamedefault) {
1684 // empty case statement ?
1689 // else if (token == TokenNameSEMICOLON) {
1691 // "':' expected after 'case' keyword (Found token: " +
1692 // scanner.toStringAction(token) + ")",
1693 // scanner.getCurrentTokenStartPosition(),
1694 // scanner.getCurrentTokenEndPosition(),
1697 // if (token == TokenNamecase) { // empty case statement ?
1703 throwSyntaxError("':' character expected after 'case' constant (Found token: " + scanner.toStringAction(token) + ")");
1705 } else { // TokenNamedefault
1707 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1709 if (token == TokenNameRBRACE) {
1710 // empty default case
1713 if (token != TokenNamecase) {
1717 throwSyntaxError("':' character expected after 'default'.");
1720 } while (token == TokenNamecase || token == TokenNamedefault);
1723 // public void labeledStatement() {
1724 // if (token == TokenNamecase) {
1727 // if (token == TokenNameDDOT) {
1731 // throwSyntaxError("':' character after 'case' constant expected.");
1734 // } else if (token == TokenNamedefault) {
1736 // if (token == TokenNameDDOT) {
1740 // throwSyntaxError("':' character after 'default' expected.");
1745 // public void expressionStatement() {
1747 // private void inclusionStatement() {
1749 // public void compoundStatement() {
1751 // public void selectionStatement() {
1754 // public void iterationStatement() {
1757 // public void jumpStatement() {
1760 // public void outputStatement() {
1763 // public void scopeStatement() {
1766 // public void flowStatement() {
1769 // public void definitionStatement() {
1771 private void ifStatement() {
1772 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
1773 if (token == TokenNameCOLON) {
1775 if (token != TokenNameendif) {
1780 if (token == TokenNameCOLON) {
1782 if (token != TokenNameendif) {
1786 if (token == TokenNameif) { //'else if'
1788 elseifStatementList();
1790 throwSyntaxError("':' expected after 'else'.");
1794 case TokenNameelseif:
1796 elseifStatementList();
1800 if (token != TokenNameendif) {
1801 throwSyntaxError("'endif' expected.");
1804 if (token != TokenNameSEMICOLON) {
1805 throwSyntaxError("';' expected after if-statement.");
1809 // statement [else-statement]
1810 statement(TokenNameEOF);
1811 if (token == TokenNameelseif) {
1813 if (token == TokenNameLPAREN) {
1816 throwSyntaxError("'(' expected after 'elseif' keyword.");
1819 if (token == TokenNameRPAREN) {
1822 throwSyntaxError("')' expected after 'elseif' condition.");
1825 } else if (token == TokenNameelse) {
1827 statement(TokenNameEOF);
1832 private void elseifStatementList() {
1838 if (token == TokenNameCOLON) {
1840 if (token != TokenNameendif) {
1845 if (token == TokenNameif) { //'else if'
1848 throwSyntaxError("':' expected after 'else'.");
1852 case TokenNameelseif:
1861 private void elseifStatement() {
1862 if (token == TokenNameLPAREN) {
1865 if (token != TokenNameRPAREN) {
1866 throwSyntaxError("')' expected in else-if-statement.");
1869 if (token != TokenNameCOLON) {
1870 throwSyntaxError("':' expected in else-if-statement.");
1873 if (token != TokenNameendif) {
1879 private void switchStatement() {
1880 if (token == TokenNameCOLON) {
1881 // ':' [labeled-statement-list] 'endswitch' ';'
1883 labeledStatementList();
1884 if (token != TokenNameendswitch) {
1885 throwSyntaxError("'endswitch' expected.");
1888 if (token != TokenNameSEMICOLON) {
1889 throwSyntaxError("';' expected after switch-statement.");
1893 // '{' [labeled-statement-list] '}'
1894 if (token != TokenNameLBRACE) {
1895 throwSyntaxError("'{' expected in switch statement.");
1898 if (token != TokenNameRBRACE) {
1899 labeledStatementList();
1901 if (token != TokenNameRBRACE) {
1902 throwSyntaxError("'}' expected in switch statement.");
1908 private void forStatement() {
1909 if (token == TokenNameCOLON) {
1912 if (token != TokenNameendfor) {
1913 throwSyntaxError("'endfor' expected.");
1916 if (token != TokenNameSEMICOLON) {
1917 throwSyntaxError("';' expected after for-statement.");
1921 statement(TokenNameEOF);
1925 private void whileStatement() {
1926 // ':' statement-list 'endwhile' ';'
1927 if (token == TokenNameCOLON) {
1930 if (token != TokenNameendwhile) {
1931 throwSyntaxError("'endwhile' expected.");
1934 if (token != TokenNameSEMICOLON) {
1935 throwSyntaxError("';' expected after while-statement.");
1939 statement(TokenNameEOF);
1943 private void foreachStatement() {
1944 if (token == TokenNameCOLON) {
1947 if (token != TokenNameendforeach) {
1948 throwSyntaxError("'endforeach' expected.");
1951 if (token != TokenNameSEMICOLON) {
1952 throwSyntaxError("';' expected after foreach-statement.");
1956 statement(TokenNameEOF);
1960 // private void exitStatus() {
1961 // if (token == TokenNameLPAREN) {
1964 // throwSyntaxError("'(' expected in 'exit-status'.");
1966 // if (token != TokenNameRPAREN) {
1969 // if (token == TokenNameRPAREN) {
1972 // throwSyntaxError("')' expected after 'exit-status'.");
1975 private void expressionList() {
1978 if (token == TokenNameCOMMA) {
1986 private Expression expr() {
1988 // | expr_without_variable
1989 // if (token!=TokenNameEOF) {
1990 if (Scanner.TRACE) {
1991 System.out.println("TRACE: expr()");
1993 return expr_without_variable(true);
1997 private Expression expr_without_variable(boolean only_variable) {
1998 int exprSourceStart = scanner.getCurrentTokenStartPosition();
1999 int exprSourceEnd = scanner.getCurrentTokenEndPosition();
2000 Expression expression = new Expression();
2001 expression.sourceStart = exprSourceStart;
2002 // default, may be overwritten
2003 expression.sourceEnd = exprSourceEnd;
2004 // internal_functions_in_yacc
2013 // | T_INC rw_variable
2014 // | T_DEC rw_variable
2015 // | T_INT_CAST expr
2016 // | T_DOUBLE_CAST expr
2017 // | T_STRING_CAST expr
2018 // | T_ARRAY_CAST expr
2019 // | T_OBJECT_CAST expr
2020 // | T_BOOL_CAST expr
2021 // | T_UNSET_CAST expr
2022 // | T_EXIT exit_expr
2024 // | T_ARRAY '(' array_pair_list ')'
2025 // | '`' encaps_list '`'
2026 // | T_LIST '(' assignment_list ')' '=' expr
2027 // | T_NEW class_name_reference ctor_arguments
2028 // | variable '=' expr
2029 // | variable '=' '&' variable
2030 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2031 // | variable T_PLUS_EQUAL expr
2032 // | variable T_MINUS_EQUAL expr
2033 // | variable T_MUL_EQUAL expr
2034 // | variable T_DIV_EQUAL expr
2035 // | variable T_CONCAT_EQUAL expr
2036 // | variable T_MOD_EQUAL expr
2037 // | variable T_AND_EQUAL expr
2038 // | variable T_OR_EQUAL expr
2039 // | variable T_XOR_EQUAL expr
2040 // | variable T_SL_EQUAL expr
2041 // | variable T_SR_EQUAL expr
2042 // | rw_variable T_INC
2043 // | rw_variable T_DEC
2044 // | expr T_BOOLEAN_OR expr
2045 // | expr T_BOOLEAN_AND expr
2046 // | expr T_LOGICAL_OR expr
2047 // | expr T_LOGICAL_AND expr
2048 // | expr T_LOGICAL_XOR expr
2060 // | expr T_IS_IDENTICAL expr
2061 // | expr T_IS_NOT_IDENTICAL expr
2062 // | expr T_IS_EQUAL expr
2063 // | expr T_IS_NOT_EQUAL expr
2065 // | expr T_IS_SMALLER_OR_EQUAL expr
2067 // | expr T_IS_GREATER_OR_EQUAL expr
2068 // | expr T_INSTANCEOF class_name_reference
2069 // | expr '?' expr ':' expr
2070 if (Scanner.TRACE) {
2071 System.out.println("TRACE: expr_without_variable() PART 1");
2074 case TokenNameisset:
2075 case TokenNameempty:
2077 case TokenNameinclude:
2078 case TokenNameinclude_once:
2079 case TokenNamerequire:
2080 case TokenNamerequire_once:
2081 internal_functions_in_yacc();
2084 case TokenNameLPAREN:
2087 if (token == TokenNameRPAREN) {
2090 throwSyntaxError("')' expected in expression.");
2100 // | T_INT_CAST expr
2101 // | T_DOUBLE_CAST expr
2102 // | T_STRING_CAST expr
2103 // | T_ARRAY_CAST expr
2104 // | T_OBJECT_CAST expr
2105 // | T_BOOL_CAST expr
2106 // | T_UNSET_CAST expr
2107 case TokenNameclone:
2108 case TokenNameprint:
2111 case TokenNameMINUS:
2113 case TokenNameTWIDDLE:
2114 case TokenNameintCAST:
2115 case TokenNamedoubleCAST:
2116 case TokenNamestringCAST:
2117 case TokenNamearrayCAST:
2118 case TokenNameobjectCAST:
2119 case TokenNameboolCAST:
2120 case TokenNameunsetCAST:
2130 //| T_STRING_VARNAME
2132 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2133 // | '`' encaps_list '`'
2135 // | '`' encaps_list '`'
2136 case TokenNameEncapsedString0:
2137 scanner.encapsedStringStack.push(new Character('`'));
2140 if (token == TokenNameEncapsedString0) {
2143 if (token != TokenNameEncapsedString0) {
2144 throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2148 scanner.encapsedStringStack.pop();
2152 // | '\'' encaps_list '\''
2153 case TokenNameEncapsedString1:
2154 scanner.encapsedStringStack.push(new Character('\''));
2157 exprSourceStart = scanner.getCurrentTokenStartPosition();
2158 if (token == TokenNameEncapsedString1) {
2159 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2160 .getCurrentTokenEndPosition());
2163 if (token != TokenNameEncapsedString1) {
2164 throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2166 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2167 .getCurrentTokenEndPosition());
2171 scanner.encapsedStringStack.pop();
2175 //| '"' encaps_list '"'
2176 case TokenNameEncapsedString2:
2177 scanner.encapsedStringStack.push(new Character('"'));
2180 exprSourceStart = scanner.getCurrentTokenStartPosition();
2181 if (token == TokenNameEncapsedString2) {
2182 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2183 .getCurrentTokenEndPosition());
2186 if (token != TokenNameEncapsedString2) {
2187 throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
2189 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
2190 .getCurrentTokenEndPosition());
2194 scanner.encapsedStringStack.pop();
2198 case TokenNameStringDoubleQuote:
2199 expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2200 .getCurrentTokenEndPosition());
2203 case TokenNameStringSingleQuote:
2204 expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
2205 .getCurrentTokenEndPosition());
2208 case TokenNameIntegerLiteral:
2209 case TokenNameDoubleLiteral:
2210 case TokenNameStringInterpolated:
2213 case TokenNameCLASS_C:
2214 case TokenNameMETHOD_C:
2215 case TokenNameFUNC_C:
2218 case TokenNameHEREDOC:
2221 case TokenNamearray:
2222 // T_ARRAY '(' array_pair_list ')'
2224 if (token == TokenNameLPAREN) {
2226 if (token == TokenNameRPAREN) {
2231 if (token != TokenNameRPAREN) {
2232 throwSyntaxError("')' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2236 throwSyntaxError("'(' expected after keyword 'array'" + "(Found token: " + scanner.toStringAction(token) + ")");
2240 // | T_LIST '(' assignment_list ')' '=' expr
2242 if (token == TokenNameLPAREN) {
2245 if (token != TokenNameRPAREN) {
2246 throwSyntaxError("')' expected after 'list' keyword.");
2249 if (token != TokenNameEQUAL) {
2250 throwSyntaxError("'=' expected after 'list' keyword.");
2255 throwSyntaxError("'(' expected after 'list' keyword.");
2259 // | T_NEW class_name_reference ctor_arguments
2261 class_name_reference();
2264 // | T_INC rw_variable
2265 // | T_DEC rw_variable
2266 case TokenNamePLUS_PLUS:
2267 case TokenNameMINUS_MINUS:
2271 // | variable '=' expr
2272 // | variable '=' '&' variable
2273 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2274 // | variable T_PLUS_EQUAL expr
2275 // | variable T_MINUS_EQUAL expr
2276 // | variable T_MUL_EQUAL expr
2277 // | variable T_DIV_EQUAL expr
2278 // | variable T_CONCAT_EQUAL expr
2279 // | variable T_MOD_EQUAL expr
2280 // | variable T_AND_EQUAL expr
2281 // | variable T_OR_EQUAL expr
2282 // | variable T_XOR_EQUAL expr
2283 // | variable T_SL_EQUAL expr
2284 // | variable T_SR_EQUAL expr
2285 // | rw_variable T_INC
2286 // | rw_variable T_DEC
2287 case TokenNameIdentifier:
2288 case TokenNameVariable:
2289 case TokenNameDOLLAR:
2292 case TokenNameEQUAL:
2294 if (token == TokenNameAND) {
2296 if (token == TokenNamenew) {
2297 // | variable '=' '&' T_NEW class_name_reference
2300 class_name_reference();
2309 case TokenNamePLUS_EQUAL:
2310 case TokenNameMINUS_EQUAL:
2311 case TokenNameMULTIPLY_EQUAL:
2312 case TokenNameDIVIDE_EQUAL:
2313 case TokenNameDOT_EQUAL:
2314 case TokenNameREMAINDER_EQUAL:
2315 case TokenNameAND_EQUAL:
2316 case TokenNameOR_EQUAL:
2317 case TokenNameXOR_EQUAL:
2318 case TokenNameRIGHT_SHIFT_EQUAL:
2319 case TokenNameLEFT_SHIFT_EQUAL:
2323 case TokenNamePLUS_PLUS:
2324 case TokenNameMINUS_MINUS:
2328 if (!only_variable) {
2329 throwSyntaxError("Variable expression not allowed (found token '" + scanner.toStringAction(token) + "').");
2334 if (token != TokenNameINLINE_HTML) {
2335 if (token > TokenNameKEYWORD) {
2339 throwSyntaxError("Error in expression (found token '" + scanner.toStringAction(token) + "').");
2344 if (Scanner.TRACE) {
2345 System.out.println("TRACE: expr_without_variable() PART 2");
2347 // | expr T_BOOLEAN_OR expr
2348 // | expr T_BOOLEAN_AND expr
2349 // | expr T_LOGICAL_OR expr
2350 // | expr T_LOGICAL_AND expr
2351 // | expr T_LOGICAL_XOR expr
2363 // | expr T_IS_IDENTICAL expr
2364 // | expr T_IS_NOT_IDENTICAL expr
2365 // | expr T_IS_EQUAL expr
2366 // | expr T_IS_NOT_EQUAL expr
2368 // | expr T_IS_SMALLER_OR_EQUAL expr
2370 // | expr T_IS_GREATER_OR_EQUAL expr
2373 case TokenNameOR_OR:
2375 expression = new OR_OR_Expression(expression, expr(), token);
2377 case TokenNameAND_AND:
2379 expression = new AND_AND_Expression(expression, expr(), token);
2381 case TokenNameEQUAL_EQUAL:
2383 expression = new EqualExpression(expression, expr(), token);
2393 case TokenNameMINUS:
2394 case TokenNameMULTIPLY:
2395 case TokenNameDIVIDE:
2396 case TokenNameREMAINDER:
2397 case TokenNameLEFT_SHIFT:
2398 case TokenNameRIGHT_SHIFT:
2399 case TokenNameEQUAL_EQUAL_EQUAL:
2400 case TokenNameNOT_EQUAL_EQUAL:
2401 case TokenNameNOT_EQUAL:
2403 case TokenNameLESS_EQUAL:
2404 case TokenNameGREATER:
2405 case TokenNameGREATER_EQUAL:
2407 expression = new BinaryExpression(expression, expr(), token);
2409 // | expr T_INSTANCEOF class_name_reference
2410 // | expr '?' expr ':' expr
2411 case TokenNameinstanceof:
2413 class_name_reference();
2414 // TODO use InstanceofExpression
2415 expression = new Expression();
2416 expression.sourceStart = exprSourceStart;
2417 expression.sourceEnd = scanner.getCurrentTokenEndPosition();
2419 case TokenNameQUESTION:
2421 Expression valueIfTrue = expr();
2422 if (token != TokenNameCOLON) {
2423 throwSyntaxError("':' expected in conditional expression.");
2426 Expression valueIfFalse = expr();
2428 expression = new ConditionalExpression(expression, valueIfTrue, valueIfFalse);
2436 private void class_name_reference() {
2437 // class_name_reference:
2439 //| dynamic_class_name_reference
2440 if (Scanner.TRACE) {
2441 System.out.println("TRACE: class_name_reference()");
2443 if (token == TokenNameIdentifier) {
2446 dynamic_class_name_reference();
2450 private void dynamic_class_name_reference() {
2451 //dynamic_class_name_reference:
2452 // base_variable T_OBJECT_OPERATOR object_property
2453 // dynamic_class_name_variable_properties
2455 if (Scanner.TRACE) {
2456 System.out.println("TRACE: dynamic_class_name_reference()");
2459 if (token == TokenNameMINUS_GREATER) {
2462 dynamic_class_name_variable_properties();
2466 private void dynamic_class_name_variable_properties() {
2467 // dynamic_class_name_variable_properties:
2468 // dynamic_class_name_variable_properties
2469 // dynamic_class_name_variable_property
2471 if (Scanner.TRACE) {
2472 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2474 while (token == TokenNameMINUS_GREATER) {
2475 dynamic_class_name_variable_property();
2479 private void dynamic_class_name_variable_property() {
2480 // dynamic_class_name_variable_property:
2481 // T_OBJECT_OPERATOR object_property
2482 if (Scanner.TRACE) {
2483 System.out.println("TRACE: dynamic_class_name_variable_property()");
2485 if (token == TokenNameMINUS_GREATER) {
2491 private void ctor_arguments() {
2494 //| '(' function_call_parameter_list ')'
2495 if (token == TokenNameLPAREN) {
2497 if (token == TokenNameRPAREN) {
2501 non_empty_function_call_parameter_list();
2502 if (token != TokenNameRPAREN) {
2503 throwSyntaxError("')' expected in ctor_arguments.");
2509 private void assignment_list() {
2511 // assignment_list ',' assignment_list_element
2512 //| assignment_list_element
2514 assignment_list_element();
2515 if (token != TokenNameCOMMA) {
2522 private void assignment_list_element() {
2523 //assignment_list_element:
2525 //| T_LIST '(' assignment_list ')'
2527 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2530 if (token == TokenNamelist) {
2532 if (token == TokenNameLPAREN) {
2535 if (token != TokenNameRPAREN) {
2536 throwSyntaxError("')' expected after 'list' keyword.");
2540 throwSyntaxError("'(' expected after 'list' keyword.");
2546 private void array_pair_list() {
2549 //| non_empty_array_pair_list possible_comma
2550 non_empty_array_pair_list();
2551 if (token == TokenNameCOMMA) {
2556 private void non_empty_array_pair_list() {
2557 //non_empty_array_pair_list:
2558 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2559 //| non_empty_array_pair_list ',' expr
2560 //| expr T_DOUBLE_ARROW expr
2562 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2563 //| non_empty_array_pair_list ',' '&' w_variable
2564 //| expr T_DOUBLE_ARROW '&' w_variable
2567 if (token == TokenNameAND) {
2572 if (token == TokenNameAND) {
2575 } else if (token == TokenNameEQUAL_GREATER) {
2577 if (token == TokenNameAND) {
2585 if (token != TokenNameCOMMA) {
2589 if (token == TokenNameRPAREN) {
2595 // private void variableList() {
2598 // if (token == TokenNameCOMMA) {
2605 private void variable_without_objects() {
2606 // variable_without_objects:
2607 // reference_variable
2608 // | simple_indirect_reference reference_variable
2609 if (Scanner.TRACE) {
2610 System.out.println("TRACE: variable_without_objects()");
2612 while (token == TokenNameDOLLAR) {
2615 reference_variable();
2618 private void function_call() {
2620 // T_STRING '(' function_call_parameter_list ')'
2621 //| class_constant '(' function_call_parameter_list ')'
2622 //| static_member '(' function_call_parameter_list ')'
2623 //| variable_without_objects '(' function_call_parameter_list ')'
2624 char[] defineName = null;
2625 char[] ident = null;
2628 if (Scanner.TRACE) {
2629 System.out.println("TRACE: function_call()");
2631 if (token == TokenNameIdentifier) {
2632 ident = scanner.getCurrentIdentifierSource();
2634 startPos = scanner.getCurrentTokenStartPosition();
2635 endPos = scanner.getCurrentTokenEndPosition();
2638 case TokenNamePAAMAYIM_NEKUDOTAYIM:
2642 if (token == TokenNameIdentifier) {
2647 variable_without_objects();
2652 variable_without_objects();
2654 if (token != TokenNameLPAREN) {
2655 if (defineName != null) {
2656 // does this identifier contain only uppercase characters?
2657 if (defineName.length == 3) {
2658 if (defineName[0] == 'd' && defineName[1] == 'i' && defineName[2] == 'e') {
2661 } else if (defineName.length == 4) {
2662 if (defineName[0] == 't' && defineName[1] == 'r' && defineName[2] == 'u' && defineName[3] == 'e') {
2664 } else if (defineName[0] == 'n' && defineName[1] == 'u' && defineName[2] == 'l' && defineName[3] == 'l') {
2667 } else if (defineName.length == 5) {
2668 if (defineName[0] == 'f' && defineName[1] == 'a' && defineName[2] == 'l' && defineName[3] == 's' && defineName[4] == 'e') {
2672 if (defineName != null) {
2673 for (int i = 0; i < defineName.length; i++) {
2674 if (Character.isLowerCase(defineName[i])) {
2675 problemReporter.phpUppercaseIdentifierWarning(startPos, endPos, referenceContext, compilationUnit.compilationResult);
2681 // TODO is this ok ?
2683 // throwSyntaxError("'(' expected in function call.");
2686 if (token == TokenNameRPAREN) {
2690 non_empty_function_call_parameter_list();
2691 if (token != TokenNameRPAREN) {
2692 String functionName;
2693 if (ident == null) {
2694 functionName = new String(" ");
2696 functionName = new String(ident);
2698 throwSyntaxError("')' expected in function call (" + functionName + ").");
2703 // private void function_call_parameter_list() {
2704 // function_call_parameter_list:
2705 // non_empty_function_call_parameter_list { $$ = $1; }
2708 private void non_empty_function_call_parameter_list() {
2709 //non_empty_function_call_parameter_list:
2710 // expr_without_variable
2713 // | non_empty_function_call_parameter_list ',' expr_without_variable
2714 // | non_empty_function_call_parameter_list ',' variable
2715 // | non_empty_function_call_parameter_list ',' '&' w_variable
2716 if (Scanner.TRACE) {
2717 System.out.println("TRACE: non_empty_function_call_parameter_list()");
2720 if (token == TokenNameAND) {
2724 // if (token == TokenNameIdentifier || token ==
2725 // TokenNameVariable
2726 // || token == TokenNameDOLLAR) {
2729 expr_without_variable(true);
2732 if (token != TokenNameCOMMA) {
2739 private void fully_qualified_class_name() {
2740 if (token == TokenNameIdentifier) {
2743 throwSyntaxError("Class name expected.");
2747 private void static_member() {
2749 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2750 // variable_without_objects
2751 if (Scanner.TRACE) {
2752 System.out.println("TRACE: static_member()");
2754 fully_qualified_class_name();
2755 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2756 throwSyntaxError("'::' expected after class name (static_member).");
2759 variable_without_objects();
2762 private void base_variable_with_function_calls() {
2763 // base_variable_with_function_calls:
2766 boolean functionCall = false;
2767 if (Scanner.TRACE) {
2768 System.out.println("TRACE: base_variable_with_function_calls()");
2770 // if (token == TokenNameIdentifier) {
2771 // functionCall = true;
2772 // } else if (token == TokenNameVariable) {
2773 // int tempToken = token;
2774 // int tempPosition = scanner.currentPosition;
2776 // if (token == TokenNameLPAREN) {
2777 // functionCall = true;
2779 // token = tempToken;
2780 // scanner.currentPosition = tempPosition;
2781 // scanner.phpMode = true;
2783 // if (functionCall) {
2790 private void base_variable() {
2792 // reference_variable
2793 // | simple_indirect_reference reference_variable
2795 if (Scanner.TRACE) {
2796 System.out.println("TRACE: base_variable()");
2798 if (token == TokenNameIdentifier) {
2801 while (token == TokenNameDOLLAR) {
2804 reference_variable();
2808 // private void simple_indirect_reference() {
2809 // // simple_indirect_reference:
2811 // //| simple_indirect_reference '$'
2813 private void reference_variable() {
2814 // reference_variable:
2815 // reference_variable '[' dim_offset ']'
2816 // | reference_variable '{' expr '}'
2817 // | compound_variable
2818 if (Scanner.TRACE) {
2819 System.out.println("TRACE: reference_variable()");
2821 compound_variable();
2823 if (token == TokenNameLBRACE) {
2826 if (token != TokenNameRBRACE) {
2827 throwSyntaxError("'}' expected in reference variable.");
2830 } else if (token == TokenNameLBRACKET) {
2832 if (token != TokenNameRBRACKET) {
2835 if (token != TokenNameRBRACKET) {
2836 throwSyntaxError("']' expected in reference variable.");
2846 private void compound_variable() {
2847 // compound_variable:
2849 // | '$' '{' expr '}'
2850 if (Scanner.TRACE) {
2851 System.out.println("TRACE: compound_variable()");
2853 if (token == TokenNameVariable) {
2856 // because of simple_indirect_reference
2857 while (token == TokenNameDOLLAR) {
2860 if (token != TokenNameLBRACE) {
2861 throwSyntaxError("'{' expected after compound variable token '$'.");
2865 if (token != TokenNameRBRACE) {
2866 throwSyntaxError("'}' expected after compound variable token '$'.");
2872 // private void dim_offset() {
2878 private void object_property() {
2881 //| variable_without_objects
2882 if (Scanner.TRACE) {
2883 System.out.println("TRACE: object_property()");
2885 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2886 variable_without_objects();
2892 private void object_dim_list() {
2894 // object_dim_list '[' dim_offset ']'
2895 //| object_dim_list '{' expr '}'
2897 if (Scanner.TRACE) {
2898 System.out.println("TRACE: object_dim_list()");
2902 if (token == TokenNameLBRACE) {
2905 if (token != TokenNameRBRACE) {
2906 throwSyntaxError("'}' expected in object_dim_list.");
2909 } else if (token == TokenNameLBRACKET) {
2911 if (token == TokenNameRBRACKET) {
2916 if (token != TokenNameRBRACKET) {
2917 throwSyntaxError("']' expected in object_dim_list.");
2926 private void variable_name() {
2930 if (Scanner.TRACE) {
2931 System.out.println("TRACE: variable_name()");
2933 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
2934 if (token > TokenNameKEYWORD) {
2935 // TODO show a warning "Keyword used as variable" ?
2939 if (token != TokenNameLBRACE) {
2940 throwSyntaxError("'{' expected in variable name.");
2944 if (token != TokenNameRBRACE) {
2945 throwSyntaxError("'}' expected in variable name.");
2951 private void r_variable() {
2955 private void w_variable() {
2959 private void rw_variable() {
2963 private void variable() {
2965 // base_variable_with_function_calls T_OBJECT_OPERATOR
2966 // object_property method_or_not variable_properties
2967 // | base_variable_with_function_calls
2968 base_variable_with_function_calls();
2969 if (token == TokenNameMINUS_GREATER) {
2973 variable_properties();
2975 // if (token == TokenNameDOLLAR_LBRACE) {
2979 // if (token != TokenNameRBRACE) {
2980 // throwSyntaxError("'}' expected after indirect variable token '${'.");
2984 // if (token == TokenNameVariable) {
2986 // if (token == TokenNameLBRACKET) {
2989 // if (token != TokenNameRBRACKET) {
2990 // throwSyntaxError("']' expected in variable-list.");
2993 // } else if (token == TokenNameEQUAL) {
2998 // throwSyntaxError("$-variable expected in variable-list.");
3003 private void variable_properties() {
3004 // variable_properties:
3005 // variable_properties variable_property
3007 while (token == TokenNameMINUS_GREATER) {
3008 variable_property();
3012 private void variable_property() {
3013 // variable_property:
3014 // T_OBJECT_OPERATOR object_property method_or_not
3015 if (Scanner.TRACE) {
3016 System.out.println("TRACE: variable_property()");
3018 if (token == TokenNameMINUS_GREATER) {
3023 throwSyntaxError("'->' expected in variable_property.");
3027 private void method_or_not() {
3029 // '(' function_call_parameter_list ')'
3031 if (Scanner.TRACE) {
3032 System.out.println("TRACE: method_or_not()");
3034 if (token == TokenNameLPAREN) {
3036 if (token == TokenNameRPAREN) {
3040 non_empty_function_call_parameter_list();
3041 if (token != TokenNameRPAREN) {
3042 throwSyntaxError("')' expected in method_or_not.");
3048 private void exit_expr() {
3052 if (token != TokenNameLPAREN) {
3056 if (token == TokenNameRPAREN) {
3061 if (token != TokenNameRPAREN) {
3062 throwSyntaxError("')' expected after keyword 'exit'");
3067 private void encaps_list() {
3068 // encaps_list encaps_var
3069 // | encaps_list T_STRING
3070 // | encaps_list T_NUM_STRING
3071 // | encaps_list T_ENCAPSED_AND_WHITESPACE
3072 // | encaps_list T_CHARACTER
3073 // | encaps_list T_BAD_CHARACTER
3074 // | encaps_list '['
3075 // | encaps_list ']'
3076 // | encaps_list '{'
3077 // | encaps_list '}'
3078 // | encaps_list T_OBJECT_OPERATOR
3082 case TokenNameSTRING:
3085 case TokenNameLBRACE:
3086 // scanner.encapsedStringStack.pop();
3089 case TokenNameRBRACE:
3090 // scanner.encapsedStringStack.pop();
3093 case TokenNameLBRACKET:
3094 // scanner.encapsedStringStack.pop();
3097 case TokenNameRBRACKET:
3098 // scanner.encapsedStringStack.pop();
3101 case TokenNameMINUS_GREATER:
3102 // scanner.encapsedStringStack.pop();
3105 case TokenNameVariable:
3106 case TokenNameDOLLAR_LBRACE:
3107 case TokenNameLBRACE_DOLLAR:
3111 char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3112 if (encapsedChar == '$') {
3113 scanner.encapsedStringStack.pop();
3114 encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
3115 switch (encapsedChar) {
3117 if (token == TokenNameEncapsedString0) {
3120 token = TokenNameSTRING;
3123 if (token == TokenNameEncapsedString1) {
3126 token = TokenNameSTRING;
3129 if (token == TokenNameEncapsedString2) {
3132 token = TokenNameSTRING;
3141 private void encaps_var() {
3143 // | T_VARIABLE '[' encaps_var_offset ']'
3144 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
3145 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
3146 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
3147 // | T_CURLY_OPEN variable '}'
3149 case TokenNameVariable:
3151 if (token == TokenNameLBRACKET) {
3153 expr(); //encaps_var_offset();
3154 if (token != TokenNameRBRACKET) {
3155 throwSyntaxError("']' expected after variable.");
3157 // scanner.encapsedStringStack.pop();
3160 } else if (token == TokenNameMINUS_GREATER) {
3162 if (token != TokenNameIdentifier) {
3163 throwSyntaxError("Identifier expected after '->'.");
3165 // scanner.encapsedStringStack.pop();
3169 // // scanner.encapsedStringStack.pop();
3170 // int tempToken = TokenNameSTRING;
3171 // if (!scanner.encapsedStringStack.isEmpty()
3172 // && (token == TokenNameEncapsedString0
3173 // || token == TokenNameEncapsedString1
3174 // || token == TokenNameEncapsedString2 || token ==
3175 // TokenNameERROR)) {
3176 // char encapsedChar = ((Character)
3177 // scanner.encapsedStringStack.peek())
3180 // case TokenNameEncapsedString0 :
3181 // if (encapsedChar == '`') {
3182 // tempToken = TokenNameEncapsedString0;
3185 // case TokenNameEncapsedString1 :
3186 // if (encapsedChar == '\'') {
3187 // tempToken = TokenNameEncapsedString1;
3190 // case TokenNameEncapsedString2 :
3191 // if (encapsedChar == '"') {
3192 // tempToken = TokenNameEncapsedString2;
3195 // case TokenNameERROR :
3196 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
3197 // scanner.currentPosition--;
3203 // token = tempToken;
3206 case TokenNameDOLLAR_LBRACE:
3208 if (token == TokenNameDOLLAR_LBRACE) {
3210 } else if (token == TokenNameIdentifier) {
3212 if (token == TokenNameLBRACKET) {
3214 // if (token == TokenNameRBRACKET) {
3218 if (token != TokenNameRBRACKET) {
3219 throwSyntaxError("']' expected after '${'.");
3227 if (token != TokenNameRBRACE) {
3228 throwSyntaxError("'}' expected.");
3232 case TokenNameLBRACE_DOLLAR:
3234 if (token == TokenNameLBRACE_DOLLAR) {
3236 } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
3238 if (token == TokenNameLBRACKET) {
3240 // if (token == TokenNameRBRACKET) {
3244 if (token != TokenNameRBRACKET) {
3245 throwSyntaxError("']' expected.");
3249 } else if (token == TokenNameMINUS_GREATER) {
3251 if (token != TokenNameIdentifier && token != TokenNameVariable) {
3252 throwSyntaxError("String or Variable token expected.");
3255 if (token == TokenNameLBRACKET) {
3257 // if (token == TokenNameRBRACKET) {
3261 if (token != TokenNameRBRACKET) {
3262 throwSyntaxError("']' expected after '${'.");
3268 // if (token != TokenNameRBRACE) {
3269 // throwSyntaxError("'}' expected after '{$'.");
3271 // // scanner.encapsedStringStack.pop();
3275 if (token != TokenNameRBRACE) {
3276 throwSyntaxError("'}' expected.");
3278 // scanner.encapsedStringStack.pop();
3285 private void encaps_var_offset() {
3290 case TokenNameSTRING:
3293 case TokenNameIntegerLiteral:
3296 case TokenNameVariable:
3299 case TokenNameIdentifier:
3303 throwSyntaxError("Variable or String token expected.");
3308 private void internal_functions_in_yacc() {
3310 ImportReference impt = null;
3312 case TokenNameisset:
3313 // T_ISSET '(' isset_variables ')'
3315 if (token != TokenNameLPAREN) {
3316 throwSyntaxError("'(' expected after keyword 'isset'");
3320 if (token != TokenNameRPAREN) {
3321 throwSyntaxError("')' expected after keyword 'isset'");
3325 case TokenNameempty:
3326 // T_EMPTY '(' variable ')'
3328 if (token != TokenNameLPAREN) {
3329 throwSyntaxError("'(' expected after keyword 'empty'");
3333 if (token != TokenNameRPAREN) {
3334 throwSyntaxError("')' expected after keyword 'empty'");
3338 case TokenNameinclude:
3340 checkFileName(token, impt);
3342 case TokenNameinclude_once:
3343 // T_INCLUDE_ONCE expr
3344 checkFileName(token, impt);
3347 // T_EVAL '(' expr ')'
3349 if (token != TokenNameLPAREN) {
3350 throwSyntaxError("'(' expected after keyword 'eval'");
3354 if (token != TokenNameRPAREN) {
3355 throwSyntaxError("')' expected after keyword 'eval'");
3359 case TokenNamerequire:
3361 checkFileName(token, impt);
3363 case TokenNamerequire_once:
3364 // T_REQUIRE_ONCE expr
3365 checkFileName(token, impt);
3370 private void checkFileName(int includeToken, ImportReference impt) {
3371 //<include-token> expr
3372 int start = scanner.getCurrentTokenStartPosition();
3373 boolean hasLPAREN = false;
3375 if (token == TokenNameLPAREN) {
3379 Expression expression = expr();
3381 if (token == TokenNameRPAREN) {
3384 throwSyntaxError("')' expected for keyword '" + scanner.toStringAction(includeToken) + "'");
3387 impt = new ImportReference(scanner.getCurrentTokenSource(start), start, scanner.getCurrentTokenEndPosition(), false);
3388 impt.declarationSourceEnd = impt.sourceEnd;
3389 impt.declarationEnd = impt.declarationSourceEnd;
3390 //endPosition is just before the ;
3391 impt.declarationSourceStart = start;
3392 includesList.add(impt);
3394 if (expression instanceof StringLiteral) {
3395 StringLiteral literal = (StringLiteral) expression;
3396 char[] includeName = literal.source();
3397 if (includeName.length == 0) {
3398 reportSyntaxError("Empty filename after keyword '" + scanner.toStringAction(includeToken) + "'", literal.sourceStart,
3399 literal.sourceStart + 1);
3401 String includeNameString = new String(includeName);
3402 if (literal instanceof StringLiteralDQ) {
3403 if (includeNameString.indexOf('$') >= 0) {
3404 // assuming that the filename contains a variable => no filename check
3408 if (includeNameString.startsWith("http://")) {
3409 // assuming external include location
3412 if (scanner.compilationUnit != null) {
3413 IResource resource = scanner.compilationUnit.getResource();
3414 // java.io.File f = new java.io.File(new String(compilationUnit.getFileName()));
3415 // System.out.println(expression.toStringExpression());
3417 if (resource != null && resource instanceof IFile) {
3418 // check the filename:
3419 // System.out.println(new String(compilationUnit.getFileName())+" - "+ expression.toStringExpression());
3420 IProject project = resource.getProject();
3421 if (project != null) {
3422 IPath path = PHPFileUtil.determineFilePath(includeNameString, resource, project);
3425 // reportSyntaxError("File: " + expression.toStringExpression() + " doesn't exist in project: "
3426 // + project.getLocation().toString(), literal.sourceStart, literal.sourceEnd);
3427 String[] args = { expression.toStringExpression(), project.getLocation().toString() };
3428 problemReporter.phpIncludeNotExistWarning(args, literal.sourceStart, literal.sourceEnd, referenceContext,
3429 compilationUnit.compilationResult);
3432 impt.setFile( PHPFileUtil.createFile(path, project) );
3433 } catch (Exception e) {
3434 // the file is outside of the workspace
3443 private void isset_variables() {
3445 // | isset_variables ','
3446 if (token == TokenNameRPAREN) {
3447 throwSyntaxError("Variable expected after keyword 'isset'");
3451 if (token == TokenNameCOMMA) {
3459 private boolean common_scalar() {
3463 // | T_CONSTANT_ENCAPSED_STRING
3470 case TokenNameIntegerLiteral:
3473 case TokenNameDoubleLiteral:
3476 case TokenNameStringDoubleQuote:
3479 case TokenNameStringSingleQuote:
3482 case TokenNameStringInterpolated:
3491 case TokenNameCLASS_C:
3494 case TokenNameMETHOD_C:
3497 case TokenNameFUNC_C:
3504 private void scalar() {
3507 //| T_STRING_VARNAME
3510 //| '"' encaps_list '"'
3511 //| '\'' encaps_list '\''
3512 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3513 throwSyntaxError("Not yet implemented (scalar).");
3516 private void static_scalar() {
3517 // static_scalar: /* compile-time evaluated scalars */
3520 // | '+' static_scalar
3521 // | '-' static_scalar
3522 // | T_ARRAY '(' static_array_pair_list ')'
3523 // | static_class_constant
3524 if (common_scalar()) {
3528 case TokenNameIdentifier:
3530 // static_class_constant:
3531 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3532 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3534 if (token == TokenNameIdentifier) {
3537 throwSyntaxError("Identifier expected after '::' operator.");
3541 case TokenNameEncapsedString0:
3543 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3544 while (scanner.currentCharacter != '`') {
3545 if (scanner.currentCharacter == '\\') {
3546 scanner.currentPosition++;
3548 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3551 } catch (IndexOutOfBoundsException e) {
3552 throwSyntaxError("'`' expected at end of static string.");
3555 case TokenNameEncapsedString1:
3557 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3558 while (scanner.currentCharacter != '\'') {
3559 if (scanner.currentCharacter == '\\') {
3560 scanner.currentPosition++;
3562 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3565 } catch (IndexOutOfBoundsException e) {
3566 throwSyntaxError("'\'' expected at end of static string.");
3569 case TokenNameEncapsedString2:
3571 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3572 while (scanner.currentCharacter != '"') {
3573 if (scanner.currentCharacter == '\\') {
3574 scanner.currentPosition++;
3576 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3579 } catch (IndexOutOfBoundsException e) {
3580 throwSyntaxError("'\"' expected at end of static string.");
3587 case TokenNameMINUS:
3591 case TokenNamearray:
3593 if (token != TokenNameLPAREN) {
3594 throwSyntaxError("'(' expected after keyword 'array'");
3597 if (token == TokenNameRPAREN) {
3601 non_empty_static_array_pair_list();
3602 if (token != TokenNameRPAREN) {
3603 throwSyntaxError("')' expected after keyword 'array'");
3607 // case TokenNamenull :
3610 // case TokenNamefalse :
3613 // case TokenNametrue :
3617 throwSyntaxError("Static scalar/constant expected.");
3621 private void non_empty_static_array_pair_list() {
3622 // non_empty_static_array_pair_list:
3623 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3625 //| non_empty_static_array_pair_list ',' static_scalar
3626 //| static_scalar T_DOUBLE_ARROW static_scalar
3630 if (token == TokenNameEQUAL_GREATER) {
3634 if (token != TokenNameCOMMA) {
3638 if (token == TokenNameRPAREN) {
3644 public void reportSyntaxError() { //int act, int currentKind, int
3646 /* remember current scanner position */
3647 int startPos = scanner.startPosition;
3648 int currentPos = scanner.currentPosition;
3649 // String[] expectings;
3650 // String tokenName = name[symbol_index[currentKind]];
3651 //fetch all "accurate" possible terminals that could recover the error
3652 // int start, end = start = asi(stack[stateStackTop]);
3653 // while (asr[end] != 0)
3655 // int length = end - start;
3656 // expectings = new String[length];
3657 // if (length != 0) {
3658 // char[] indexes = new char[length];
3659 // System.arraycopy(asr, start, indexes, 0, length);
3660 // for (int i = 0; i < length; i++) {
3661 // expectings[i] = name[symbol_index[indexes[i]]];
3664 //if the pb is an EOF, try to tell the user that they are some
3665 // if (tokenName.equals(UNEXPECTED_EOF)) {
3666 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3667 // char[] tokenSource;
3669 // tokenSource = this.scanner.getCurrentTokenSource();
3670 // } catch (Exception e) {
3671 // tokenSource = new char[] {};
3673 // problemReporter().parseError(
3674 // this.scanner.startPosition,
3675 // this.scanner.currentPosition - 1,
3680 // } else { //the next test is HEAVILY grammar DEPENDENT.
3681 // if ((length == 14)
3682 // && (expectings[0] == "=") //$NON-NLS-1$
3683 // && (expectings[1] == "*=") //$NON-NLS-1$
3684 // && (expressionPtr > -1)) {
3685 // switch(currentKind) {
3686 // case TokenNameSEMICOLON:
3687 // case TokenNamePLUS:
3688 // case TokenNameMINUS:
3689 // case TokenNameDIVIDE:
3690 // case TokenNameREMAINDER:
3691 // case TokenNameMULTIPLY:
3692 // case TokenNameLEFT_SHIFT:
3693 // case TokenNameRIGHT_SHIFT:
3694 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3695 // case TokenNameLESS:
3696 // case TokenNameGREATER:
3697 // case TokenNameLESS_EQUAL:
3698 // case TokenNameGREATER_EQUAL:
3699 // case TokenNameEQUAL_EQUAL:
3700 // case TokenNameNOT_EQUAL:
3701 // case TokenNameXOR:
3702 // case TokenNameAND:
3703 // case TokenNameOR:
3704 // case TokenNameOR_OR:
3705 // case TokenNameAND_AND:
3706 // // the ; is not the expected token ==> it ends a statement when an
3707 // expression is not ended
3708 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3710 // case TokenNameRBRACE :
3711 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3714 // char[] tokenSource;
3716 // tokenSource = this.scanner.getCurrentTokenSource();
3717 // } catch (Exception e) {
3718 // tokenSource = new char[] {};
3720 // problemReporter().parseError(
3721 // this.scanner.startPosition,
3722 // this.scanner.currentPosition - 1,
3726 // this.checkAndReportBracketAnomalies(problemReporter());
3731 tokenSource = this.scanner.getCurrentTokenSource();
3732 } catch (Exception e) {
3733 tokenSource = new char[] {};
3735 // problemReporter().parseError(
3736 // this.scanner.startPosition,
3737 // this.scanner.currentPosition - 1,
3741 this.checkAndReportBracketAnomalies(problemReporter());
3744 /* reset scanner where it was */
3745 scanner.startPosition = startPos;
3746 scanner.currentPosition = currentPos;
3749 public static final int RoundBracket = 0;
3751 public static final int SquareBracket = 1;
3753 public static final int CurlyBracket = 2;
3755 public static final int BracketKinds = 3;
3757 protected int[] nestedMethod; //the ptr is nestedType
3759 protected int nestedType, dimensions;
3762 final static int AstStackIncrement = 100;
3764 protected int astPtr;
3766 protected ASTNode[] astStack = new ASTNode[AstStackIncrement];
3768 protected int astLengthPtr;
3770 protected int[] astLengthStack;
3772 ASTNode[] noAstNodes = new ASTNode[AstStackIncrement];
3774 public CompilationUnitDeclaration compilationUnit; /*
3775 * the result from parse()
3778 protected ReferenceContext referenceContext;
3780 protected ProblemReporter problemReporter;
3782 protected CompilerOptions options;
3784 private ArrayList includesList;
3786 // protected CompilationResult compilationResult;
3788 * Returns this parser's problem reporter initialized with its reference context. Also it is assumed that a problem is going to be
3789 * reported, so initializes the compilation result's line positions.
3791 public ProblemReporter problemReporter() {
3792 if (scanner.recordLineSeparator) {
3793 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
3795 problemReporter.referenceContext = referenceContext;
3796 return problemReporter;
3800 * Reconsider the entire source looking for inconsistencies in {} () []
3802 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
3803 scanner.wasAcr = false;
3804 boolean anomaliesDetected = false;
3806 char[] source = scanner.source;
3807 int[] leftCount = { 0, 0, 0 };
3808 int[] rightCount = { 0, 0, 0 };
3809 int[] depths = { 0, 0, 0 };
3810 int[][] leftPositions = new int[][] { new int[10], new int[10], new int[10] };
3811 int[][] leftDepths = new int[][] { new int[10], new int[10], new int[10] };
3812 int[][] rightPositions = new int[][] { new int[10], new int[10], new int[10] };
3813 int[][] rightDepths = new int[][] { new int[10], new int[10], new int[10] };
3814 scanner.currentPosition = scanner.initialPosition; //starting
3816 // (first-zero-based
3818 while (scanner.currentPosition < scanner.eofPosition) { //loop for
3823 // ---------Consume white space and handles
3824 // startPosition---------
3825 boolean isWhiteSpace;
3827 scanner.startPosition = scanner.currentPosition;
3828 // if (((scanner.currentCharacter =
3829 // source[scanner.currentPosition++]) == '\\') &&
3830 // (source[scanner.currentPosition] == 'u')) {
3831 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
3833 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3834 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3835 // only record line positions we have not
3837 scanner.pushLineSeparator();
3840 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
3842 } while (isWhiteSpace && (scanner.currentPosition < scanner.eofPosition));
3843 // -------consume token until } is found---------
3844 switch (scanner.currentCharacter) {
3846 int index = leftCount[CurlyBracket]++;
3847 if (index == leftPositions[CurlyBracket].length) {
3848 System.arraycopy(leftPositions[CurlyBracket], 0, (leftPositions[CurlyBracket] = new int[index * 2]), 0, index);
3849 System.arraycopy(leftDepths[CurlyBracket], 0, (leftDepths[CurlyBracket] = new int[index * 2]), 0, index);
3851 leftPositions[CurlyBracket][index] = scanner.startPosition;
3852 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
3856 int index = rightCount[CurlyBracket]++;
3857 if (index == rightPositions[CurlyBracket].length) {
3858 System.arraycopy(rightPositions[CurlyBracket], 0, (rightPositions[CurlyBracket] = new int[index * 2]), 0, index);
3859 System.arraycopy(rightDepths[CurlyBracket], 0, (rightDepths[CurlyBracket] = new int[index * 2]), 0, index);
3861 rightPositions[CurlyBracket][index] = scanner.startPosition;
3862 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
3866 int index = leftCount[RoundBracket]++;
3867 if (index == leftPositions[RoundBracket].length) {
3868 System.arraycopy(leftPositions[RoundBracket], 0, (leftPositions[RoundBracket] = new int[index * 2]), 0, index);
3869 System.arraycopy(leftDepths[RoundBracket], 0, (leftDepths[RoundBracket] = new int[index * 2]), 0, index);
3871 leftPositions[RoundBracket][index] = scanner.startPosition;
3872 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
3876 int index = rightCount[RoundBracket]++;
3877 if (index == rightPositions[RoundBracket].length) {
3878 System.arraycopy(rightPositions[RoundBracket], 0, (rightPositions[RoundBracket] = new int[index * 2]), 0, index);
3879 System.arraycopy(rightDepths[RoundBracket], 0, (rightDepths[RoundBracket] = new int[index * 2]), 0, index);
3881 rightPositions[RoundBracket][index] = scanner.startPosition;
3882 rightDepths[RoundBracket][index] = --depths[RoundBracket];
3886 int index = leftCount[SquareBracket]++;
3887 if (index == leftPositions[SquareBracket].length) {
3888 System.arraycopy(leftPositions[SquareBracket], 0, (leftPositions[SquareBracket] = new int[index * 2]), 0, index);
3889 System.arraycopy(leftDepths[SquareBracket], 0, (leftDepths[SquareBracket] = new int[index * 2]), 0, index);
3891 leftPositions[SquareBracket][index] = scanner.startPosition;
3892 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
3896 int index = rightCount[SquareBracket]++;
3897 if (index == rightPositions[SquareBracket].length) {
3898 System.arraycopy(rightPositions[SquareBracket], 0, (rightPositions[SquareBracket] = new int[index * 2]), 0, index);
3899 System.arraycopy(rightDepths[SquareBracket], 0, (rightDepths[SquareBracket] = new int[index * 2]), 0, index);
3901 rightPositions[SquareBracket][index] = scanner.startPosition;
3902 rightDepths[SquareBracket][index] = --depths[SquareBracket];
3906 if (scanner.getNextChar('\\')) {
3907 scanner.scanEscapeCharacter();
3908 } else { // consume next character
3909 scanner.unicodeAsBackSlash = false;
3910 // if (((scanner.currentCharacter =
3911 // source[scanner.currentPosition++]) ==
3913 // (source[scanner.currentPosition] ==
3915 // scanner.getNextUnicodeChar();
3917 if (scanner.withoutUnicodePtr != 0) {
3918 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3922 scanner.getNextChar('\'');
3926 // consume next character
3927 scanner.unicodeAsBackSlash = false;
3928 // if (((scanner.currentCharacter =
3929 // source[scanner.currentPosition++]) == '\\') &&
3930 // (source[scanner.currentPosition] == 'u')) {
3931 // scanner.getNextUnicodeChar();
3933 if (scanner.withoutUnicodePtr != 0) {
3934 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3937 while (scanner.currentCharacter != '"') {
3938 if (scanner.currentCharacter == '\r') {
3939 if (source[scanner.currentPosition] == '\n')
3940 scanner.currentPosition++;
3941 break; // the string cannot go further that
3944 if (scanner.currentCharacter == '\n') {
3945 break; // the string cannot go further that
3948 if (scanner.currentCharacter == '\\') {
3949 scanner.scanEscapeCharacter();
3951 // consume next character
3952 scanner.unicodeAsBackSlash = false;
3953 // if (((scanner.currentCharacter =
3954 // source[scanner.currentPosition++]) == '\\')
3955 // && (source[scanner.currentPosition] == 'u'))
3957 // scanner.getNextUnicodeChar();
3959 if (scanner.withoutUnicodePtr != 0) {
3960 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3967 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
3970 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3971 && (source[scanner.currentPosition] == 'u')) {
3972 //-------------unicode traitement
3974 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3975 scanner.currentPosition++;
3976 while (source[scanner.currentPosition] == 'u') {
3977 scanner.currentPosition++;
3979 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
3980 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
3981 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
3982 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
3986 scanner.currentCharacter = 'A';
3987 } //something different from \n and \r
3989 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3992 while (scanner.currentCharacter != '\r' && scanner.currentCharacter != '\n') {
3994 scanner.startPosition = scanner.currentPosition;
3995 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3996 && (source[scanner.currentPosition] == 'u')) {
3997 //-------------unicode traitement
3999 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4000 scanner.currentPosition++;
4001 while (source[scanner.currentPosition] == 'u') {
4002 scanner.currentPosition++;
4004 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4005 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4006 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4007 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4011 scanner.currentCharacter = 'A';
4012 } //something different from \n
4015 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4019 if (scanner.recordLineSeparator && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
4020 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
4021 // only record line positions we
4022 // have not recorded yet
4023 scanner.pushLineSeparator();
4024 if (this.scanner.taskTags != null) {
4025 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner
4026 .getCurrentTokenEndPosition());
4032 if (test > 0) { //traditional and annotation
4034 boolean star = false;
4035 // consume next character
4036 scanner.unicodeAsBackSlash = false;
4037 // if (((scanner.currentCharacter =
4038 // source[scanner.currentPosition++]) ==
4040 // (source[scanner.currentPosition] ==
4042 // scanner.getNextUnicodeChar();
4044 if (scanner.withoutUnicodePtr != 0) {
4045 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
4048 if (scanner.currentCharacter == '*') {
4052 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4053 && (source[scanner.currentPosition] == 'u')) {
4054 //-------------unicode traitement
4056 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4057 scanner.currentPosition++;
4058 while (source[scanner.currentPosition] == 'u') {
4059 scanner.currentPosition++;
4061 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4062 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4063 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4064 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4068 scanner.currentCharacter = 'A';
4069 } //something different from * and /
4071 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4074 //loop until end of comment */
4075 while ((scanner.currentCharacter != '/') || (!star)) {
4076 star = scanner.currentCharacter == '*';
4078 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
4079 && (source[scanner.currentPosition] == 'u')) {
4080 //-------------unicode traitement
4082 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
4083 scanner.currentPosition++;
4084 while (source[scanner.currentPosition] == 'u') {
4085 scanner.currentPosition++;
4087 if ((c1 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c1 < 0
4088 || (c2 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c2 < 0
4089 || (c3 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c3 < 0
4090 || (c4 = Character.getNumericValue(source[scanner.currentPosition++])) > 15 || c4 < 0) { //error
4094 scanner.currentCharacter = 'A';
4095 } //something different from * and
4098 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
4102 if (this.scanner.taskTags != null) {
4103 this.scanner.checkTaskTag(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
4110 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
4111 scanner.scanIdentifierOrKeyword(false);
4114 if (Character.isDigit(scanner.currentCharacter)) {
4115 scanner.scanNumber(false);
4119 //-----------------end switch while
4120 // try--------------------
4121 } catch (IndexOutOfBoundsException e) {
4122 break; // read until EOF
4123 } catch (InvalidInputException e) {
4124 return false; // no clue
4127 if (scanner.recordLineSeparator) {
4128 // compilationUnit.compilationResult.lineSeparatorPositions =
4129 // scanner.getLineEnds();
4131 // check placement anomalies against other kinds of brackets
4132 for (int kind = 0; kind < BracketKinds; kind++) {
4133 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
4134 int start = leftPositions[kind][leftIndex]; // deepest
4136 // find matching closing bracket
4137 int depth = leftDepths[kind][leftIndex];
4139 for (int i = 0; i < rightCount[kind]; i++) {
4140 int pos = rightPositions[kind][i];
4141 // want matching bracket further in source with same
4143 if ((pos > start) && (depth == rightDepths[kind][i])) {
4148 if (end < 0) { // did not find a good closing match
4149 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult);
4152 // check if even number of opening/closing other brackets
4153 // in between this pair of brackets
4155 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
4156 for (int i = 0; i < leftCount[otherKind]; i++) {
4157 int pos = leftPositions[otherKind][i];
4158 if ((pos > start) && (pos < end))
4161 for (int i = 0; i < rightCount[otherKind]; i++) {
4162 int pos = rightPositions[otherKind][i];
4163 if ((pos > start) && (pos < end))
4167 problemReporter.unmatchedBracket(start, referenceContext, compilationUnit.compilationResult); //bracket
4173 // too many opening brackets ?
4174 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
4175 anomaliesDetected = true;
4176 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind] - i - 1], referenceContext,
4177 compilationUnit.compilationResult);
4179 // too many closing brackets ?
4180 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
4181 anomaliesDetected = true;
4182 problemReporter.unmatchedBracket(rightPositions[kind][i], referenceContext, compilationUnit.compilationResult);
4184 if (anomaliesDetected)
4187 return anomaliesDetected;
4188 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
4189 return anomaliesDetected;
4190 } catch (NullPointerException e) { // jdk1.2.2 jit bug
4191 return anomaliesDetected;
4195 protected void pushOnAstLengthStack(int pos) {
4197 astLengthStack[++astLengthPtr] = pos;
4198 } catch (IndexOutOfBoundsException e) {
4199 int oldStackLength = astLengthStack.length;
4200 int[] oldPos = astLengthStack;
4201 astLengthStack = new int[oldStackLength + StackIncrement];
4202 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4203 astLengthStack[astLengthPtr] = pos;
4207 protected void pushOnAstStack(ASTNode node) {
4209 * add a new obj on top of the ast stack
4212 astStack[++astPtr] = node;
4213 } catch (IndexOutOfBoundsException e) {
4214 int oldStackLength = astStack.length;
4215 ASTNode[] oldStack = astStack;
4216 astStack = new ASTNode[oldStackLength + AstStackIncrement];
4217 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
4218 astPtr = oldStackLength;
4219 astStack[astPtr] = node;
4222 astLengthStack[++astLengthPtr] = 1;
4223 } catch (IndexOutOfBoundsException e) {
4224 int oldStackLength = astLengthStack.length;
4225 int[] oldPos = astLengthStack;
4226 astLengthStack = new int[oldStackLength + AstStackIncrement];
4227 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
4228 astLengthStack[astLengthPtr] = 1;
4232 protected void resetModifiers() {
4233 this.modifiers = AccDefault;
4234 this.modifiersSourceStart = -1; // <-- see comment into
4235 // modifiersFlag(int)
4236 this.scanner.commentPtr = -1;