1 /**********************************************************************
2 Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de
3 All rights reserved. This program and the accompanying material
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 Klaus Hartlage - www.eclipseproject.de
10 **********************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.parser;
12 import java.util.ArrayList;
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
17 import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
18 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
19 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
20 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
21 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
22 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
23 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
24 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
25 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
26 import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
27 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
28 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
29 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
30 import net.sourceforge.phpdt.internal.compiler.util.Util;
32 import org.eclipse.core.resources.IFile;
33 public class Parser //extends PHPParserSuperclass
34 implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
35 //internal data for the automat
36 protected final static int StackIncrement = 255;
37 protected int stateStackTop;
38 protected int[] stack = new int[StackIncrement];
39 public int firstToken; // handle for multiple parsing goals
40 public int lastAct; //handle for multiple parsing goals
41 protected RecoveredElement currentElement;
42 public static boolean VERBOSE_RECOVERY = false;
43 protected boolean diet = false; //tells the scanner to jump over some
44 // parts of the code/expressions like
47 public Scanner scanner;
48 private ArrayList phpList;
49 private int currentPHPString;
50 private boolean phpEnd;
51 // private static HashMap keywordMap = null;
57 // row counter for syntax errors:
59 // column counter for syntax errors:
63 // // current identifier
67 private String stringValue;
68 /** Contains the current expression. */
69 // private StringBuffer expression;
70 //private boolean phpMode;
71 protected int modifiers;
72 protected int modifiersSourceStart;
73 protected Parser(ProblemReporter problemReporter) {
74 this.problemReporter = problemReporter;
75 this.options = problemReporter.options;
76 this.currentPHPString = 0;
77 // PHPParserSuperclass.fileToParse = fileToParse;
80 this.token = TokenNameEOF;
83 // this.columnCount = 0;
86 this.initializeScanner();
88 public void setFileToParse(IFile fileToParse) {
89 this.currentPHPString = 0;
90 // PHPParserSuperclass.fileToParse = fileToParse;
93 this.token = TokenNameEOF;
95 this.initializeScanner();
98 * ClassDeclaration Constructor.
102 * Description of Parameter
105 public Parser(IFile fileToParse) {
106 // if (keywordMap == null) {
107 // keywordMap = new HashMap();
108 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
109 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
112 this.currentPHPString = 0;
113 // PHPParserSuperclass.fileToParse = fileToParse;
116 this.token = TokenNameEOF;
118 // this.rowCount = 1;
119 // this.columnCount = 0;
122 this.initializeScanner();
124 public void initializeScanner() {
125 this.scanner = new Scanner(
127 false /*whitespace*/,
128 this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/,
131 this.options.taskTags/*taskTags*/,
132 this.options.taskPriorites/*taskPriorities*/);
135 * Create marker for the parse error
137 // private void setMarker(String message, int charStart, int charEnd, int
139 // setMarker(fileToParse, message, charStart, charEnd, errorLevel);
142 * This method will throw the SyntaxError. It will add the good lines and
143 * columns to the Error
147 * @throws SyntaxError
150 private void throwSyntaxError(String error) {
151 int problemStartPosition = scanner.getCurrentTokenStartPosition();
152 int problemEndPosition = scanner.getCurrentTokenEndPosition();
153 throwSyntaxError(error, problemStartPosition, problemEndPosition + 1);
156 * This method will throw the SyntaxError. It will add the good lines and
157 * columns to the Error
161 * @throws SyntaxError
164 // private void throwSyntaxError(String error, int startRow) {
165 // throw new SyntaxError(startRow, 0, " ", error);
167 private void throwSyntaxError(String error, int problemStartPosition,
168 int problemEndPosition) {
170 .phpParsingError(new String[]{error}, problemStartPosition,
171 problemEndPosition, referenceContext,
172 compilationUnit.compilationResult);
173 throw new SyntaxError(1, 0, " ", error);
175 private void reportSyntaxError(String error, int problemStartPosition,
176 int problemEndPosition) {
178 .phpParsingError(new String[]{error}, problemStartPosition,
179 problemEndPosition, referenceContext,
180 compilationUnit.compilationResult);
182 private void reportSyntaxWarning(String error, int problemStartPosition,
183 int problemEndPosition) {
184 problemReporter.phpParsingWarning(new String[]{error},
185 problemStartPosition, problemEndPosition, referenceContext,
186 compilationUnit.compilationResult);
189 * Method Declaration.
193 // private void getChar() {
194 // if (str.length() > chIndx) {
195 // ch = str.charAt(chIndx++);
200 // chIndx = str.length() + 1;
202 // // token = TokenNameEOF;
206 * gets the next token from input
208 private void getNextToken() {
210 token = scanner.getNextToken();
212 int currentEndPosition = scanner.getCurrentTokenEndPosition();
213 int currentStartPosition = scanner.getCurrentTokenStartPosition();
215 .print(currentStartPosition + "," + currentEndPosition + ": ");
216 System.out.println(scanner.toStringAction(token));
218 } catch (InvalidInputException e) {
219 token = TokenNameERROR;
223 public void init(String s) {
225 this.token = TokenNameEOF;
227 // this.rowCount = 1;
228 // this.columnCount = 0;
230 // this.phpMode = false;
231 /* scanner initialization */
232 scanner.setSource(s.toCharArray());
233 scanner.setPHPMode(false);
235 protected void initialize(boolean phpMode) {
236 compilationUnit = null;
237 referenceContext = null;
239 this.token = TokenNameEOF;
241 // this.rowCount = 1;
242 // this.columnCount = 0;
244 // this.phpMode = phpMode;
245 scanner.setPHPMode(phpMode);
248 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
251 public void parse(String s) {
256 * Parses a string with php tags i.e. '<body> <?php phpinfo() ?>
259 protected void parse() {
263 if (token != TokenNameEOF && token != TokenNameERROR) {
266 if (token != TokenNameEOF) {
267 if (token == TokenNameERROR) {
268 throwSyntaxError("Scanner error (Found unknown token: "
269 + scanner.toStringAction(token) + ")");
271 if (token == TokenNameRPAREN) {
272 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
274 if (token == TokenNameRBRACE) {
275 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
277 if (token == TokenNameRBRACKET) {
278 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
280 if (token == TokenNameLPAREN) {
281 throwSyntaxError("Read character '('; end-of-file not reached.");
283 if (token == TokenNameLBRACE) {
284 throwSyntaxError("Read character '{'; end-of-file not reached.");
286 if (token == TokenNameLBRACKET) {
287 throwSyntaxError("Read character '['; end-of-file not reached.");
289 throwSyntaxError("End-of-file not reached.");
292 } catch (SyntaxError sytaxErr1) {
293 // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
295 // setMarker(sytaxErr1.getMessage(),
296 // scanner.getCurrentTokenStartPosition(),
297 // scanner.getCurrentTokenEndPosition(), ERROR);
299 // if an error occured,
300 // try to find keywords 'class' or 'function'
301 // to parse the rest of the string
302 while (token != TokenNameEOF && token != TokenNameERROR) {
303 if (token == TokenNameabstract || token == TokenNamefinal
304 || token == TokenNameclass || token == TokenNamefunction) {
309 if (token == TokenNameEOF || token == TokenNameERROR) {
312 } catch (SyntaxError sytaxErr2) {
313 // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
315 // setMarker(sytaxErr2.getMessage(),
316 // scanner.getCurrentTokenStartPosition(),
317 // scanner.getCurrentTokenEndPosition(), ERROR);
326 protected CompilationUnitDeclaration endParse(int act) {
330 if (currentElement != null) {
331 currentElement.topElement().updateParseTree();
332 if (VERBOSE_RECOVERY) {
333 System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
334 System.out.println("--------------------------"); //$NON-NLS-1$
335 System.out.println(compilationUnit);
336 System.out.println("----------------------------------"); //$NON-NLS-1$
339 if (diet & VERBOSE_RECOVERY) {
340 System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
341 System.out.println("--------------------------"); //$NON-NLS-1$
342 System.out.println(compilationUnit);
343 System.out.println("----------------------------------"); //$NON-NLS-1$
346 if (scanner.recordLineSeparator) {
347 compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
349 if (scanner.taskTags != null) {
350 for (int i = 0; i < scanner.foundTaskCount; i++) {
351 problemReporter().task(
352 new String(scanner.foundTaskTags[i]),
353 new String(scanner.foundTaskMessages[i]),
354 scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
355 scanner.foundTaskPositions[i][0],
356 scanner.foundTaskPositions[i][1]);
359 return compilationUnit;
361 // public PHPOutlineInfo parseInfo(Object parent, String s) {
362 // PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
363 // // Stack stack = new Stack();
364 // // stack.push(outlineInfo.getDeclarations());
366 // this.token = TokenNameEOF;
367 // // this.chIndx = 0;
368 // // this.rowCount = 1;
369 // // this.columnCount = 0;
370 // this.phpEnd = false;
371 // this.phpMode = false;
372 // scanner.setSource(s.toCharArray());
373 // scanner.setPHPMode(false);
376 // parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
378 // return outlineInfo;
380 private boolean isVariable() {
381 return token == TokenNameVariable; // || token == TokenNamethis;
383 // private void parseDeclarations(PHPOutlineInfo outlineInfo,
384 // OutlineableWithChildren current, boolean goBack) {
386 // // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
387 // PHPSegmentWithChildren temp;
389 // IPreferenceStore store =
390 // PHPeclipsePlugin.getDefault().getPreferenceStore();
392 // while (token != TokenNameEOF && token != TokenNameERROR) {
393 // if (token == TokenNameVariable) {
394 // ident = scanner.getCurrentIdentifierSource();
395 // outlineInfo.addVariable(new String(ident));
397 // } else if (token == TokenNamevar) {
399 // if (token == TokenNameVariable
400 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
401 // ident = scanner.getCurrentIdentifierSource();
402 // //substring(1) added because PHPVarDeclaration doesn't
403 // // need the $ anymore
404 // String variableName = new String(ident).substring(1);
405 // outlineInfo.addVariable(variableName);
407 // if (token != TokenNameSEMICOLON) {
409 // ident = scanner.getCurrentTokenSource();
410 // if (token > TokenNameKEYWORD) {
411 // current.add(new PHPVarDeclaration(current, variableName,
412 // // chIndx - ident.length,
413 // scanner.getCurrentTokenStartPosition(), new String(ident)));
416 // case TokenNameVariable :
417 // case TokenNamethis :
418 // current.add(new PHPVarDeclaration(current, variableName,
421 // scanner.getCurrentTokenStartPosition(), new String(
424 // case TokenNameIdentifier :
425 // current.add(new PHPVarDeclaration(current, variableName,
428 // scanner.getCurrentTokenStartPosition(), new String(
431 // case TokenNameDoubleLiteral :
432 // current.add(new PHPVarDeclaration(current, variableName
436 // scanner.getCurrentTokenStartPosition(), new String(
439 // case TokenNameIntegerLiteral :
440 // current.add(new PHPVarDeclaration(current, variableName,
443 // scanner.getCurrentTokenStartPosition(), new String(
446 // case TokenNameStringInterpolated :
447 // case TokenNameStringLiteral :
448 // current.add(new PHPVarDeclaration(current, variableName,
451 // scanner.getCurrentTokenStartPosition(), new String(
454 // case TokenNameStringConstant :
455 // current.add(new PHPVarDeclaration(current, variableName,
458 // scanner.getCurrentTokenStartPosition(), new String(
462 // current.add(new PHPVarDeclaration(current, variableName,
465 // scanner.getCurrentTokenStartPosition()));
470 // ident = scanner.getCurrentIdentifierSource();
471 // current.add(new PHPVarDeclaration(current, variableName,
472 // // chIndx - ident.length
473 // scanner.getCurrentTokenStartPosition()));
476 // } else if (token == TokenNamefunction) {
478 // if (token == TokenNameAND) {
481 // if (token == TokenNameIdentifier
482 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
483 // ident = scanner.getCurrentIdentifierSource();
484 // outlineInfo.addVariable(new String(ident));
485 // temp = new PHPFunctionDeclaration(current, new String(ident),
486 // // chIndx - ident.length
487 // scanner.getCurrentTokenStartPosition());
488 // current.add(temp);
490 // parseDeclarations(outlineInfo, temp, true);
492 // } else if (token == TokenNameclass) {
494 // if (token == TokenNameIdentifier
495 // && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
496 // ident = scanner.getCurrentIdentifierSource();
497 // outlineInfo.addVariable(new String(ident));
498 // temp = new PHPClassDeclaration(current, new String(ident),
499 // // chIndx - ident.len
500 // scanner.getCurrentTokenStartPosition());
501 // current.add(temp);
502 // // stack.push(temp);
504 // //skip tokens for classname, extends and others until
505 // // we have the opening '{'
506 // while (token != TokenNameLBRACE && token != TokenNameEOF
507 // && token != TokenNameERROR) {
510 // parseDeclarations(outlineInfo, temp, true);
513 // } else if ((token == TokenNameLBRACE)
514 // || (token == TokenNameDOLLAR_LBRACE)) {
517 // } else if (token == TokenNameRBRACE) {
520 // if (counter == 0 && goBack) {
523 // } else if (token == TokenNamerequire || token == TokenNamerequire_once
524 // || token == TokenNameinclude || token == TokenNameinclude_once) {
525 // ident = scanner.getCurrentTokenSource();
527 // int startPosition = scanner.getCurrentTokenStartPosition();
529 // char[] expr = scanner.getCurrentTokenSource(startPosition);
530 // outlineInfo.addVariable(new String(ident));
531 // current.add(new PHPReqIncDeclaration(current, new String(ident),
532 // // chIndx - ident.length,
533 // startPosition, new String(expr)));
539 // } catch (SyntaxError sytaxErr) {
541 // // // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
542 // // setMarker(sytaxErr.getMessage(),
543 // // scanner.getCurrentTokenStartPosition(),
544 // // scanner.getCurrentTokenEndPosition(), ERROR);
545 // // } catch (CoreException e) {
549 private void statementList() {
551 statement(TokenNameEOF);
552 if ((token == TokenNameRBRACE) || (token == TokenNamecase)
553 || (token == TokenNamedefault) || (token == TokenNameelse)
554 || (token == TokenNameelseif) || (token == TokenNameendif)
555 || (token == TokenNameendfor) || (token == TokenNameendforeach)
556 || (token == TokenNameendwhile) || (token == TokenNameendswitch)
557 || (token == TokenNameEOF) || (token == TokenNameERROR)) {
562 private void functionBody(MethodDeclaration methodDecl) {
563 // '{' [statement-list] '}'
564 if (token == TokenNameLBRACE) {
567 throwSyntaxError("'{' expected in compound-statement.");
569 if (token != TokenNameRBRACE) {
572 if (token == TokenNameRBRACE) {
573 methodDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
576 throwSyntaxError("'}' expected in compound-statement.");
579 private void statement(int previousToken) {
580 // if (token > TokenNameKEYWORD && token != TokenNamelist && token !=
582 // char[] ident = scanner.getCurrentIdentifierSource();
583 // String keyword = new String(ident);
584 // if (token == TokenNameAT) {
586 // if (token != TokenNamerequire && token != TokenNamerequire_once
587 // && token != TokenNameinclude && token != TokenNameinclude_once
588 // && token != TokenNameIdentifier && token != TokenNameVariable
589 // && token != TokenNameStringInterpolated) {
590 // throwSyntaxError("identifier expected after '@'.");
593 // if (token == TokenNameinclude || token == TokenNameinclude_once) {
595 // if (token == TokenNameLPAREN) {
597 // if (token == TokenNameSEMICOLON) {
600 // if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
601 // throwSyntaxError("';' expected after 'include' or 'include_once'.");
603 // // getNextToken();
606 // concatenationExpression();
609 // } else if (token == TokenNamerequire || token == TokenNamerequire_once)
613 // if (token == TokenNameLPAREN) {
615 // if (token == TokenNameSEMICOLON) {
618 // if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
619 // throwSyntaxError("';' expected after 'require' or 'require_once'.");
621 // // getNextToken();
624 // concatenationExpression();
628 if (token == TokenNameif) {
630 if (token == TokenNameLPAREN) {
633 throwSyntaxError("'(' expected after 'if' keyword.");
636 if (token == TokenNameRPAREN) {
639 throwSyntaxError("')' expected after 'if' condition.");
643 } else if (token == TokenNameswitch) {
645 if (token == TokenNameLPAREN) {
648 throwSyntaxError("'(' expected after 'switch' keyword.");
651 if (token == TokenNameRPAREN) {
654 throwSyntaxError("')' expected after 'switch' condition.");
658 } else if (token == TokenNamefor) {
660 if (token == TokenNameLPAREN) {
663 throwSyntaxError("'(' expected after 'for' keyword.");
665 if (token == TokenNameSEMICOLON) {
669 if (token == TokenNameSEMICOLON) {
672 throwSyntaxError("';' expected after 'for'.");
675 if (token == TokenNameSEMICOLON) {
679 if (token == TokenNameSEMICOLON) {
682 throwSyntaxError("';' expected after 'for'.");
685 if (token == TokenNameRPAREN) {
689 if (token == TokenNameRPAREN) {
692 throwSyntaxError("')' expected after 'for'.");
697 } else if (token == TokenNamewhile) {
699 if (token == TokenNameLPAREN) {
702 throwSyntaxError("'(' expected after 'while' keyword.");
705 if (token == TokenNameRPAREN) {
708 throwSyntaxError("')' expected after 'while' condition.");
712 } else if (token == TokenNamedo) {
714 if (token == TokenNameLBRACE) {
716 if (token != TokenNameRBRACE) {
719 if (token == TokenNameRBRACE) {
722 throwSyntaxError("'}' expected after 'do' keyword.");
725 statement(TokenNameEOF);
727 if (token == TokenNamewhile) {
729 if (token == TokenNameLPAREN) {
732 throwSyntaxError("'(' expected after 'while' keyword.");
735 if (token == TokenNameRPAREN) {
738 throwSyntaxError("')' expected after 'while' condition.");
741 throwSyntaxError("'while' expected after 'do' keyword.");
743 if (token == TokenNameSEMICOLON) {
746 if (token != TokenNameINLINE_HTML) {
747 throwSyntaxError("';' expected after do-while statement.");
752 } else if (token == TokenNameforeach) {
754 if (token == TokenNameLPAREN) {
757 throwSyntaxError("'(' expected after 'foreach' keyword.");
760 if (token == TokenNameas) {
763 throwSyntaxError("'as' expected after 'foreach' exxpression.");
767 foreach_optional_arg();
768 if (token == TokenNameEQUAL_GREATER) {
772 if (token == TokenNameRPAREN) {
775 throwSyntaxError("')' expected after 'foreach' expression.");
779 } else if (token == TokenNamecontinue || token == TokenNamebreak
780 || token == TokenNamereturn) {
782 if (token != TokenNameSEMICOLON) {
785 if (token == TokenNameSEMICOLON) {
788 if (token != TokenNameINLINE_HTML) {
789 throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
794 } else if (token == TokenNameecho) {
797 if (token == TokenNameSEMICOLON) {
800 if (token != TokenNameINLINE_HTML) {
801 throwSyntaxError("';' expected after 'echo' statement.");
806 } else if (token == TokenNameINLINE_HTML) {
809 // } else if (token == TokenNameprint) {
812 // if (token == TokenNameSEMICOLON) {
815 // if (token != TokenNameStopPHP) {
816 // throwSyntaxError("';' expected after 'print' statement.");
821 } else if (token == TokenNameglobal) {
824 if (token == TokenNameSEMICOLON) {
827 if (token != TokenNameINLINE_HTML) {
828 throwSyntaxError("';' expected after 'global' statement.");
833 } else if (token == TokenNamestatic) {
836 if (token == TokenNameSEMICOLON) {
839 if (token != TokenNameINLINE_HTML) {
840 throwSyntaxError("';' expected after 'static' statement.");
845 } else if (token == TokenNameunset) {
847 if (token == TokenNameLPAREN) {
850 throwSyntaxError("'(' expected after 'unset' statement.");
853 if (token == TokenNameRPAREN) {
856 throwSyntaxError("')' expected after 'unset' statement.");
858 if (token == TokenNameSEMICOLON) {
861 if (token != TokenNameINLINE_HTML) {
862 throwSyntaxError("';' expected after 'unset' statement.");
867 } else if (token == TokenNamefunction) {
868 MethodDeclaration methodDecl = new MethodDeclaration(
869 this.compilationUnit.compilationResult);
870 methodDecl.declarationSourceStart = scanner
871 .getCurrentTokenStartPosition();
873 functionDefinition(methodDecl);
875 } else if (token == TokenNametry) {
877 if (token != TokenNameLBRACE) {
878 throwSyntaxError("'{' expected in 'try' statement.");
882 if (token != TokenNameRBRACE) {
883 throwSyntaxError("'}' expected in 'try' statement.");
887 } else if (token == TokenNamecatch) {
889 if (token != TokenNameLPAREN) {
890 throwSyntaxError("'(' expected in 'catch' statement.");
893 fully_qualified_class_name();
894 if (token != TokenNameVariable) {
895 throwSyntaxError("Variable expected in 'catch' statement.");
898 if (token != TokenNameRPAREN) {
899 throwSyntaxError("')' expected in 'catch' statement.");
902 if (token != TokenNameLBRACE) {
903 throwSyntaxError("'{' expected in 'catch' statement.");
906 if (token != TokenNameRBRACE) {
908 if (token != TokenNameRBRACE) {
909 throwSyntaxError("'}' expected in 'catch' statement.");
913 additional_catches();
915 } else if (token == TokenNamethrow) {
918 if (token == TokenNameSEMICOLON) {
921 throwSyntaxError("';' expected after 'throw' exxpression.");
924 } else if (token == TokenNamefinal || token == TokenNameabstract
925 || token == TokenNameclass || token == TokenNameinterface) {
926 TypeDeclaration typeDecl = new TypeDeclaration(
927 this.compilationUnit.compilationResult);
928 typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
929 // default super class
930 typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
931 compilationUnit.types.add(typeDecl);
933 pushOnAstStack(typeDecl);
934 unticked_class_declaration_statement(typeDecl);
935 // classBody(typeDecl);
942 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
943 } else if (token == TokenNameLBRACE) {
945 if (token != TokenNameRBRACE) {
948 if (token == TokenNameRBRACE) {
952 throwSyntaxError("'}' expected.");
955 if (token != TokenNameSEMICOLON) {
958 if (token == TokenNameSEMICOLON) {
962 if (token != TokenNameINLINE_HTML && token != TokenNameEOF) {
963 throwSyntaxError("';' expected after expression (Found token: "
964 + scanner.toStringAction(token) + ")");
970 private void additional_catches() {
971 while (token == TokenNamecatch) {
973 if (token != TokenNameLPAREN) {
974 throwSyntaxError("'(' expected in 'catch' statement.");
977 fully_qualified_class_name();
978 if (token != TokenNameVariable) {
979 throwSyntaxError("Variable expected in 'catch' statement.");
982 if (token != TokenNameRPAREN) {
983 throwSyntaxError("')' expected in 'catch' statement.");
986 if (token != TokenNameLBRACE) {
987 throwSyntaxError("'{' expected in 'catch' statement.");
991 if (token != TokenNameRBRACE) {
992 throwSyntaxError("'}' expected in 'catch' statement.");
997 private void foreach_variable() {
1000 if (token == TokenNameAND) {
1005 private void foreach_optional_arg() {
1007 //| T_DOUBLE_ARROW foreach_variable
1008 if (token == TokenNameEQUAL_GREATER) {
1013 private void global_var_list() {
1015 // global_var_list ',' global_var
1019 if (token != TokenNameCOMMA) {
1025 private void global_var() {
1029 //| '$' '{' expr '}'
1030 if (token == TokenNameVariable) {
1032 } else if (token == TokenNameDOLLAR) {
1034 if (token == TokenNameLPAREN) {
1037 if (token != TokenNameLPAREN) {
1038 throwSyntaxError("')' expected in global variable.");
1046 private void static_var_list() {
1048 // static_var_list ',' T_VARIABLE
1049 //| static_var_list ',' T_VARIABLE '=' static_scalar
1051 //| T_VARIABLE '=' static_scalar
1053 if (token == TokenNameVariable) {
1055 if (token == TokenNameEQUAL) {
1059 if (token != TokenNameCOMMA) {
1068 private void unset_variables() {
1071 // | unset_variables ',' unset_variable
1076 if (token != TokenNameCOMMA) {
1082 private final void initializeModifiers() {
1084 this.modifiersSourceStart = -1;
1086 private final void checkAndSetModifiers(int flag) {
1087 this.modifiers |= flag;
1088 if (this.modifiersSourceStart < 0)
1089 this.modifiersSourceStart = this.scanner.startPosition;
1091 private void unticked_class_declaration_statement(TypeDeclaration typeDecl) {
1092 initializeModifiers();
1093 if (token == TokenNameinterface) {
1094 // interface_entry T_STRING
1095 // interface_extends_list
1096 // '{' class_statement_list '}'
1097 checkAndSetModifiers(AccInterface);
1099 typeDecl.modifiers = this.modifiers;
1100 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1101 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1102 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1103 typeDecl.name = scanner.getCurrentIdentifierSource();
1104 if (token > TokenNameKEYWORD) {
1105 throwSyntaxError("Don't use a keyword for interface declaration ["
1106 + scanner.toStringAction(token) + "].", typeDecl.sourceStart,
1107 typeDecl.sourceEnd);
1110 interface_extends_list();
1112 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1113 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1114 typeDecl.name = new char[]{' '};
1115 throwSyntaxError("Interface name expected after keyword 'interface'.",
1116 typeDecl.sourceStart, typeDecl.sourceEnd);
1120 // class_entry_type T_STRING extends_from
1122 // '{' class_statement_list'}'
1124 typeDecl.modifiers = this.modifiers;
1126 //identifier 'extends' identifier
1127 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
1128 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1129 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1130 typeDecl.name = scanner.getCurrentIdentifierSource();
1131 if (token > TokenNameKEYWORD) {
1132 throwSyntaxError("Don't use a keyword for class declaration ["
1133 + scanner.toStringAction(token) + "].", typeDecl.sourceStart,
1134 typeDecl.sourceEnd);
1139 // | T_EXTENDS fully_qualified_class_name
1140 if (token == TokenNameextends) {
1141 interface_extends_list();
1143 // if (token != TokenNameIdentifier) {
1144 // throwSyntaxError("Class name expected after keyword 'extends'.",
1145 // scanner.getCurrentTokenStartPosition(), scanner
1146 // .getCurrentTokenEndPosition());
1151 typeDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1152 typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1153 typeDecl.name = new char[]{' '};
1154 throwSyntaxError("Class name expected after keyword 'class'.",
1155 typeDecl.sourceStart, typeDecl.sourceEnd);
1159 // '{' class_statement_list '}'
1160 if (token == TokenNameLBRACE) {
1162 if (token != TokenNameRBRACE) {
1163 class_statement_list();
1165 if (token == TokenNameRBRACE) {
1166 typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1169 throwSyntaxError("'}' expected at end of class body.");
1172 throwSyntaxError("'{' expected at start of class body.");
1175 private void class_entry_type() {
1177 // | T_ABSTRACT T_CLASS
1178 // | T_FINAL T_CLASS
1179 if (token == TokenNameclass) {
1181 } else if (token == TokenNameabstract) {
1182 checkAndSetModifiers(AccAbstract);
1184 if (token != TokenNameclass) {
1185 throwSyntaxError("Keyword 'class' expected after keyword 'abstract'.");
1188 } else if (token == TokenNamefinal) {
1189 checkAndSetModifiers(AccFinal);
1191 if (token != TokenNameclass) {
1192 throwSyntaxError("Keyword 'class' expected after keyword 'final'.");
1196 throwSyntaxError("Keyword 'class' 'final' or 'abstract' expected");
1199 private void interface_extends_list() {
1201 // | T_EXTENDS interface_list
1202 if (token == TokenNameextends) {
1207 private void implements_list() {
1209 // | T_IMPLEMENTS interface_list
1210 if (token == TokenNameimplements) {
1215 private void interface_list() {
1217 // fully_qualified_class_name
1218 //| interface_list ',' fully_qualified_class_name
1220 if (token == TokenNameIdentifier) {
1223 throwSyntaxError("Interface name expected after keyword 'implements'.");
1225 if (token != TokenNameCOMMA) {
1231 // private void classBody(TypeDeclaration typeDecl) {
1232 // //'{' [class-element-list] '}'
1233 // if (token == TokenNameLBRACE) {
1235 // if (token != TokenNameRBRACE) {
1236 // class_statement_list();
1238 // if (token == TokenNameRBRACE) {
1239 // typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
1242 // throwSyntaxError("'}' expected at end of class body.");
1245 // throwSyntaxError("'{' expected at start of class body.");
1248 private void class_statement_list() {
1251 } while (token == TokenNamepublic || token == TokenNameprotected
1252 || token == TokenNameprivate || token == TokenNamestatic
1253 || token == TokenNameabstract || token == TokenNamefinal
1254 || token == TokenNamefunction || token == TokenNamevar
1255 || token == TokenNameconst);
1257 private void class_statement() {
1259 // variable_modifiers class_variable_declaration ';'
1260 // | class_constant_declaration ';'
1261 // | method_modifiers T_FUNCTION is_reference T_STRING
1262 // '(' parameter_list ')' method_body
1263 initializeModifiers();
1264 if (token == TokenNamevar) {
1265 checkAndSetModifiers(AccPublic);
1266 problemReporter.phpVarDeprecatedWarning(scanner
1267 .getCurrentTokenStartPosition(),
1268 scanner.getCurrentTokenEndPosition(), referenceContext,
1269 compilationUnit.compilationResult);
1271 class_variable_declaration();
1272 } else if (token == TokenNameconst) {
1273 class_constant_declaration();
1274 if (token != TokenNameSEMICOLON) {
1275 throwSyntaxError("';' expected after class const declaration.");
1279 boolean hasModifiers = member_modifiers();
1280 if (token == TokenNamefunction) {
1281 if (!hasModifiers) {
1282 checkAndSetModifiers(AccPublic);
1284 MethodDeclaration methodDecl = new MethodDeclaration(
1285 this.compilationUnit.compilationResult);
1286 methodDecl.declarationSourceStart = scanner
1287 .getCurrentTokenStartPosition();
1288 methodDecl.modifiers = this.modifiers;
1290 functionDefinition(methodDecl);
1292 if (!hasModifiers) {
1293 throwSyntaxError("'public' 'private' or 'protected' modifier expected for field declarations.");
1295 class_variable_declaration();
1298 // if (token == TokenNamefunction) {
1299 // MethodDeclaration methodDecl = new MethodDeclaration(
1300 // this.compilationUnit.compilationResult);
1301 // methodDecl.declarationSourceStart = scanner
1302 // .getCurrentTokenStartPosition();
1304 // functionDefinition(methodDecl);
1305 // } else if (token == TokenNamevar) {
1309 // throwSyntaxError("'function' or 'var' expected.");
1312 private void class_constant_declaration() {
1313 // class_constant_declaration ',' T_STRING '=' static_scalar
1314 // | T_CONST T_STRING '=' static_scalar
1315 if (token != TokenNameconst) {
1316 throwSyntaxError("'const' keyword expected in class declaration.");
1321 if (token != TokenNameIdentifier) {
1322 throwSyntaxError("Identifier expected in class const declaration.");
1325 if (token != TokenNameEQUAL) {
1326 throwSyntaxError("'=' expected in class const declaration.");
1330 if (token != TokenNameCOMMA) {
1331 break; // while(true)-loop
1336 // private void variable_modifiers() {
1337 // // variable_modifiers:
1338 // // non_empty_member_modifiers
1340 // initializeModifiers();
1341 // if (token == TokenNamevar) {
1342 // checkAndSetModifiers(AccPublic);
1343 // reportSyntaxError(
1344 // "Keyword 'var' is deprecated. Please use 'public' 'private' or 'protected'
1345 // modifier for field declarations.",
1346 // scanner.getCurrentTokenStartPosition(), scanner
1347 // .getCurrentTokenEndPosition());
1350 // if (!member_modifiers()) {
1351 // throwSyntaxError("'public' 'private' or 'protected' modifier expected for
1352 // field declarations.");
1356 // private void method_modifiers() {
1357 // //method_modifiers:
1359 // //| non_empty_member_modifiers
1360 // initializeModifiers();
1361 // if (!member_modifiers()) {
1362 // checkAndSetModifiers(AccPublic);
1365 private boolean member_modifiers() {
1372 boolean foundToken = false;
1374 if (token == TokenNamepublic) {
1375 checkAndSetModifiers(AccPublic);
1378 } else if (token == TokenNameprotected) {
1379 checkAndSetModifiers(AccProtected);
1382 } else if (token == TokenNameprivate) {
1383 checkAndSetModifiers(AccPrivate);
1386 } else if (token == TokenNamestatic) {
1387 checkAndSetModifiers(AccStatic);
1390 } else if (token == TokenNameabstract) {
1391 checkAndSetModifiers(AccAbstract);
1394 } else if (token == TokenNamefinal) {
1395 checkAndSetModifiers(AccFinal);
1404 private void class_variable_declaration() {
1405 // class_variable_declaration:
1406 // class_variable_declaration ',' T_VARIABLE
1407 // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
1409 // | T_VARIABLE '=' static_scalar
1411 if (token == TokenNameVariable) {
1412 FieldDeclaration fieldDeclaration = new FieldDeclaration(null, scanner
1413 .getCurrentIdentifierSource(), scanner
1414 .getCurrentTokenStartPosition(), scanner
1415 .getCurrentTokenEndPosition());
1417 if (token == TokenNameEQUAL) {
1422 // if (token == TokenNamethis) {
1423 // throwSyntaxError("'$this' not allowed after keyword 'public'
1424 // 'protected' 'private' 'var'.");
1426 throwSyntaxError("Variable expected after keyword 'public' 'protected' 'private' 'var'.");
1428 if (token != TokenNameCOMMA) {
1433 if (token != TokenNameSEMICOLON) {
1434 throwSyntaxError("';' expected after field declaration.");
1438 private void functionDefinition(MethodDeclaration methodDecl) {
1439 boolean isAbstract = false;
1441 compilationUnit.types.add(methodDecl);
1443 AstNode node = astStack[astPtr];
1444 if (node instanceof TypeDeclaration) {
1445 TypeDeclaration typeDecl = ((TypeDeclaration) node);
1446 if (typeDecl.methods == null) {
1447 typeDecl.methods = new AbstractMethodDeclaration[]{methodDecl};
1449 AbstractMethodDeclaration[] newMethods;
1454 newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1],
1455 1, typeDecl.methods.length);
1456 newMethods[0] = methodDecl;
1457 typeDecl.methods = newMethods;
1459 if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
1461 } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
1466 functionDeclarator(methodDecl);
1467 if (token == TokenNameSEMICOLON) {
1469 throwSyntaxError("Body declaration expected for method: "
1470 + new String(methodDecl.selector));
1475 functionBody(methodDecl);
1477 private void functionDeclarator(MethodDeclaration methodDecl) {
1478 //identifier '(' [parameter-list] ')'
1479 if (token == TokenNameAND) {
1482 if (token == TokenNameIdentifier) {
1483 methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
1484 methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
1485 methodDecl.selector = scanner.getCurrentIdentifierSource();
1487 if (token == TokenNameLPAREN) {
1490 throwSyntaxError("'(' expected in function declaration.");
1492 if (token != TokenNameRPAREN) {
1495 if (token != TokenNameRPAREN) {
1496 throwSyntaxError("')' expected in function declaration.");
1498 methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
1502 if (token > TokenNameKEYWORD) {
1503 throwSyntaxError("Don't use keyword for function declaration [" + token
1506 throwSyntaxError("Function name expected after keyword 'function'.");
1510 private void parameter_list() {
1511 // non_empty_parameter_list
1513 non_empty_parameter_list(true);
1515 private void non_empty_parameter_list(boolean empty_allowed) {
1516 // optional_class_type T_VARIABLE
1517 // | optional_class_type '&' T_VARIABLE
1518 // | optional_class_type '&' T_VARIABLE '=' static_scalar
1519 // | optional_class_type T_VARIABLE '=' static_scalar
1520 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
1521 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
1522 // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
1524 // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
1526 if (token == TokenNameIdentifier || token == TokenNameVariable
1527 || token == TokenNameAND) {
1529 if (token == TokenNameIdentifier) {
1532 if (token == TokenNameAND) {
1535 if (token == TokenNameVariable) {
1537 if (token == TokenNameEQUAL) {
1542 throwSyntaxError("Variable expected in parameter list.");
1544 if (token != TokenNameCOMMA) {
1551 if (!empty_allowed) {
1552 throwSyntaxError("Identifier expected in parameter list.");
1555 private void optional_class_type() {
1559 private void parameterDeclaration() {
1561 //variable-reference
1562 if (token == TokenNameAND) {
1567 throwSyntaxError("Variable expected after reference operator '&'.");
1570 //variable '=' constant
1571 if (token == TokenNameVariable) {
1573 if (token == TokenNameEQUAL) {
1579 // if (token == TokenNamethis) {
1580 // throwSyntaxError("Reserved word '$this' not allowed in parameter
1584 private void labeledStatementList() {
1585 if (token != TokenNamecase && token != TokenNamedefault) {
1586 throwSyntaxError("'case' or 'default' expected.");
1589 if (token == TokenNamecase) {
1591 expr(); //constant();
1592 if (token == TokenNameCOLON || token == TokenNameSEMICOLON) {
1594 if (token == TokenNamecase || token == TokenNamedefault) {
1595 // empty case statement ?
1600 // else if (token == TokenNameSEMICOLON) {
1602 // "':' expected after 'case' keyword (Found token: " +
1603 // scanner.toStringAction(token) + ")",
1604 // scanner.getCurrentTokenStartPosition(),
1605 // scanner.getCurrentTokenEndPosition(),
1608 // if (token == TokenNamecase) { // empty case statement ?
1614 throwSyntaxError("':' character after 'case' constant expected (Found token: "
1615 + scanner.toStringAction(token) + ")");
1617 } else { // TokenNamedefault
1619 if (token == TokenNameCOLON) {
1621 if (token==TokenNameRBRACE) {
1622 // empty default case
1627 throwSyntaxError("':' character after 'default' expected.");
1630 } while (token == TokenNamecase || token == TokenNamedefault);
1632 // public void labeledStatement() {
1633 // if (token == TokenNamecase) {
1636 // if (token == TokenNameDDOT) {
1640 // throwSyntaxError("':' character after 'case' constant expected.");
1643 // } else if (token == TokenNamedefault) {
1645 // if (token == TokenNameDDOT) {
1649 // throwSyntaxError("':' character after 'default' expected.");
1654 // public void expressionStatement() {
1656 // private void inclusionStatement() {
1658 // public void compoundStatement() {
1660 // public void selectionStatement() {
1663 // public void iterationStatement() {
1666 // public void jumpStatement() {
1669 // public void outputStatement() {
1672 // public void scopeStatement() {
1675 // public void flowStatement() {
1678 // public void definitionStatement() {
1680 private void ifStatement() {
1681 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
1682 if (token == TokenNameCOLON) {
1684 if (token != TokenNameendif) {
1687 case TokenNameelse :
1689 if (token == TokenNameCOLON) {
1691 if (token != TokenNameendif) {
1695 if (token == TokenNameif) { //'else if'
1697 elseifStatementList();
1699 throwSyntaxError("':' expected after 'else'.");
1703 case TokenNameelseif :
1705 elseifStatementList();
1709 if (token != TokenNameendif) {
1710 throwSyntaxError("'endif' expected.");
1713 if (token != TokenNameSEMICOLON) {
1714 throwSyntaxError("';' expected after if-statement.");
1718 // statement [else-statement]
1719 statement(TokenNameEOF);
1720 if (token == TokenNameelseif) {
1722 if (token == TokenNameLPAREN) {
1725 throwSyntaxError("'(' expected after 'elseif' keyword.");
1728 if (token == TokenNameRPAREN) {
1731 throwSyntaxError("')' expected after 'elseif' condition.");
1734 } else if (token == TokenNameelse) {
1736 statement(TokenNameEOF);
1740 private void elseifStatementList() {
1744 case TokenNameelse :
1746 if (token == TokenNameCOLON) {
1748 if (token != TokenNameendif) {
1753 if (token == TokenNameif) { //'else if'
1756 throwSyntaxError("':' expected after 'else'.");
1760 case TokenNameelseif :
1768 private void elseifStatement() {
1769 if (token == TokenNameLPAREN) {
1772 if (token != TokenNameRPAREN) {
1773 throwSyntaxError("')' expected in else-if-statement.");
1776 if (token != TokenNameCOLON) {
1777 throwSyntaxError("':' expected in else-if-statement.");
1780 if (token != TokenNameendif) {
1785 private void switchStatement() {
1786 if (token == TokenNameCOLON) {
1787 // ':' [labeled-statement-list] 'endswitch' ';'
1789 labeledStatementList();
1790 if (token != TokenNameendswitch) {
1791 throwSyntaxError("'endswitch' expected.");
1794 if (token != TokenNameSEMICOLON) {
1795 throwSyntaxError("';' expected after switch-statement.");
1799 // '{' [labeled-statement-list] '}'
1800 if (token != TokenNameLBRACE) {
1801 throwSyntaxError("'{' expected in switch statement.");
1804 if (token != TokenNameRBRACE) {
1805 labeledStatementList();
1807 if (token != TokenNameRBRACE) {
1808 throwSyntaxError("'}' expected in switch statement.");
1813 private void forStatement() {
1814 if (token == TokenNameCOLON) {
1817 if (token != TokenNameendfor) {
1818 throwSyntaxError("'endfor' expected.");
1821 if (token != TokenNameSEMICOLON) {
1822 throwSyntaxError("';' expected after for-statement.");
1826 statement(TokenNameEOF);
1829 private void whileStatement() {
1830 // ':' statement-list 'endwhile' ';'
1831 if (token == TokenNameCOLON) {
1834 if (token != TokenNameendwhile) {
1835 throwSyntaxError("'endwhile' expected.");
1838 if (token != TokenNameSEMICOLON) {
1839 throwSyntaxError("';' expected after while-statement.");
1843 statement(TokenNameEOF);
1846 private void foreachStatement() {
1847 if (token == TokenNameCOLON) {
1850 if (token != TokenNameendforeach) {
1851 throwSyntaxError("'endforeach' expected.");
1854 if (token != TokenNameSEMICOLON) {
1855 throwSyntaxError("';' expected after foreach-statement.");
1859 statement(TokenNameEOF);
1862 // private void exitStatus() {
1863 // if (token == TokenNameLPAREN) {
1866 // throwSyntaxError("'(' expected in 'exit-status'.");
1868 // if (token != TokenNameRPAREN) {
1871 // if (token == TokenNameRPAREN) {
1874 // throwSyntaxError("')' expected after 'exit-status'.");
1877 private void expressionList() {
1880 if (token == TokenNameCOMMA) {
1887 private void expr() {
1889 // | expr_without_variable
1890 // if (token!=TokenNameEOF) {
1891 if (Scanner.TRACE) {
1892 System.out.println("TRACE: expr()");
1894 expr_without_variable(true);
1897 private void expr_without_variable(boolean only_variable) {
1898 // internal_functions_in_yacc
1907 // | T_INC rw_variable
1908 // | T_DEC rw_variable
1909 // | T_INT_CAST expr
1910 // | T_DOUBLE_CAST expr
1911 // | T_STRING_CAST expr
1912 // | T_ARRAY_CAST expr
1913 // | T_OBJECT_CAST expr
1914 // | T_BOOL_CAST expr
1915 // | T_UNSET_CAST expr
1916 // | T_EXIT exit_expr
1918 // | T_ARRAY '(' array_pair_list ')'
1919 // | '`' encaps_list '`'
1920 // | T_LIST '(' assignment_list ')' '=' expr
1921 // | T_NEW class_name_reference ctor_arguments
1922 // | variable '=' expr
1923 // | variable '=' '&' variable
1924 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
1925 // | variable T_PLUS_EQUAL expr
1926 // | variable T_MINUS_EQUAL expr
1927 // | variable T_MUL_EQUAL expr
1928 // | variable T_DIV_EQUAL expr
1929 // | variable T_CONCAT_EQUAL expr
1930 // | variable T_MOD_EQUAL expr
1931 // | variable T_AND_EQUAL expr
1932 // | variable T_OR_EQUAL expr
1933 // | variable T_XOR_EQUAL expr
1934 // | variable T_SL_EQUAL expr
1935 // | variable T_SR_EQUAL expr
1936 // | rw_variable T_INC
1937 // | rw_variable T_DEC
1938 // | expr T_BOOLEAN_OR expr
1939 // | expr T_BOOLEAN_AND expr
1940 // | expr T_LOGICAL_OR expr
1941 // | expr T_LOGICAL_AND expr
1942 // | expr T_LOGICAL_XOR expr
1954 // | expr T_IS_IDENTICAL expr
1955 // | expr T_IS_NOT_IDENTICAL expr
1956 // | expr T_IS_EQUAL expr
1957 // | expr T_IS_NOT_EQUAL expr
1959 // | expr T_IS_SMALLER_OR_EQUAL expr
1961 // | expr T_IS_GREATER_OR_EQUAL expr
1962 // | expr T_INSTANCEOF class_name_reference
1963 // | expr '?' expr ':' expr
1964 if (Scanner.TRACE) {
1965 System.out.println("TRACE: expr_without_variable() PART 1");
1968 case TokenNameisset :
1969 case TokenNameempty :
1970 case TokenNameeval :
1971 case TokenNameinclude :
1972 case TokenNameinclude_once :
1973 case TokenNamerequire :
1974 case TokenNamerequire_once :
1975 internal_functions_in_yacc();
1978 case TokenNameLPAREN :
1981 if (token == TokenNameRPAREN) {
1984 throwSyntaxError("')' expected in expression.");
1994 // | T_INT_CAST expr
1995 // | T_DOUBLE_CAST expr
1996 // | T_STRING_CAST expr
1997 // | T_ARRAY_CAST expr
1998 // | T_OBJECT_CAST expr
1999 // | T_BOOL_CAST expr
2000 // | T_UNSET_CAST expr
2001 case TokenNameclone :
2002 case TokenNameprint :
2004 case TokenNamePLUS :
2005 case TokenNameMINUS :
2007 case TokenNameTWIDDLE :
2008 case TokenNameintCAST :
2009 case TokenNamedoubleCAST :
2010 case TokenNamestringCAST :
2011 case TokenNamearrayCAST :
2012 case TokenNameobjectCAST :
2013 case TokenNameboolCAST :
2014 case TokenNameunsetCAST :
2018 case TokenNameexit :
2024 //| T_STRING_VARNAME
2026 //| T_START_HEREDOC encaps_list T_END_HEREDOC
2027 // | '`' encaps_list '`'
2029 // | '`' encaps_list '`'
2030 case TokenNameEncapsedString0 :
2031 scanner.encapsedStringStack.push(new Character('`'));
2034 if (token == TokenNameEncapsedString0) {
2037 if (token != TokenNameEncapsedString0) {
2038 throwSyntaxError("\'`\' expected at end of string"
2039 + "(Found token: " + scanner.toStringAction(token) + " )");
2043 scanner.encapsedStringStack.pop();
2047 // | '\'' encaps_list '\''
2048 case TokenNameEncapsedString1 :
2049 scanner.encapsedStringStack.push(new Character('\''));
2052 if (token == TokenNameEncapsedString1) {
2055 if (token != TokenNameEncapsedString1) {
2056 throwSyntaxError("\'\'\' expected at end of string"
2057 + "(Found token: " + scanner.toStringAction(token) + " )");
2061 scanner.encapsedStringStack.pop();
2065 //| '"' encaps_list '"'
2066 case TokenNameEncapsedString2 :
2067 scanner.encapsedStringStack.push(new Character('"'));
2070 if (token == TokenNameEncapsedString2) {
2073 if (token != TokenNameEncapsedString2) {
2074 throwSyntaxError("'\"' expected at end of string"
2075 + "(Found token: " + scanner.toStringAction(token) + " )");
2079 scanner.encapsedStringStack.pop();
2083 case TokenNameIntegerLiteral :
2084 case TokenNameDoubleLiteral :
2085 case TokenNameStringLiteral :
2086 case TokenNameStringConstant :
2087 case TokenNameStringInterpolated :
2088 case TokenNameFILE :
2089 case TokenNameLINE :
2090 case TokenNameCLASS_C :
2091 case TokenNameMETHOD_C :
2092 case TokenNameFUNC_C :
2095 case TokenNameHEREDOC :
2098 case TokenNamearray :
2099 // T_ARRAY '(' array_pair_list ')'
2101 if (token == TokenNameLPAREN) {
2103 if (token == TokenNameRPAREN) {
2108 if (token != TokenNameRPAREN) {
2109 throwSyntaxError("')' expected after keyword 'array'"
2110 + "(Found token: " + scanner.toStringAction(token) + ")");
2114 throwSyntaxError("'(' expected after keyword 'array'"
2115 + "(Found token: " + scanner.toStringAction(token) + ")");
2118 case TokenNamelist :
2119 // | T_LIST '(' assignment_list ')' '=' expr
2121 if (token == TokenNameLPAREN) {
2124 if (token != TokenNameRPAREN) {
2125 throwSyntaxError("')' expected after 'list' keyword.");
2128 if (token != TokenNameEQUAL) {
2129 throwSyntaxError("'=' expected after 'list' keyword.");
2134 throwSyntaxError("'(' expected after 'list' keyword.");
2138 // | T_NEW class_name_reference ctor_arguments
2140 class_name_reference();
2143 // | T_INC rw_variable
2144 // | T_DEC rw_variable
2145 case TokenNamePLUS_PLUS :
2146 case TokenNameMINUS_MINUS :
2150 // | variable '=' expr
2151 // | variable '=' '&' variable
2152 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2153 // | variable T_PLUS_EQUAL expr
2154 // | variable T_MINUS_EQUAL expr
2155 // | variable T_MUL_EQUAL expr
2156 // | variable T_DIV_EQUAL expr
2157 // | variable T_CONCAT_EQUAL expr
2158 // | variable T_MOD_EQUAL expr
2159 // | variable T_AND_EQUAL expr
2160 // | variable T_OR_EQUAL expr
2161 // | variable T_XOR_EQUAL expr
2162 // | variable T_SL_EQUAL expr
2163 // | variable T_SR_EQUAL expr
2164 // | rw_variable T_INC
2165 // | rw_variable T_DEC
2166 case TokenNameIdentifier :
2167 case TokenNameVariable :
2168 case TokenNameDOLLAR :
2171 case TokenNameEQUAL :
2173 if (token == TokenNameAND) {
2175 if (token == TokenNamenew) {
2176 // | variable '=' '&' T_NEW class_name_reference ctor_arguments
2178 class_name_reference();
2187 case TokenNamePLUS_EQUAL :
2188 case TokenNameMINUS_EQUAL :
2189 case TokenNameMULTIPLY_EQUAL :
2190 case TokenNameDIVIDE_EQUAL :
2191 case TokenNameDOT_EQUAL :
2192 case TokenNameREMAINDER_EQUAL :
2193 case TokenNameAND_EQUAL :
2194 case TokenNameOR_EQUAL :
2195 case TokenNameXOR_EQUAL :
2196 case TokenNameRIGHT_SHIFT_EQUAL :
2197 case TokenNameLEFT_SHIFT_EQUAL :
2201 case TokenNamePLUS_PLUS :
2202 case TokenNameMINUS_MINUS :
2206 if (!only_variable) {
2207 throwSyntaxError("Variable expression not allowed (found token '"
2208 + scanner.toStringAction(token) + "').");
2213 if (token != TokenNameINLINE_HTML) {
2214 if (token > TokenNameKEYWORD) {
2218 throwSyntaxError("Error in expression (found token '"
2219 + scanner.toStringAction(token) + "').");
2224 if (Scanner.TRACE) {
2225 System.out.println("TRACE: expr_without_variable() PART 2");
2227 // | expr T_BOOLEAN_OR expr
2228 // | expr T_BOOLEAN_AND expr
2229 // | expr T_LOGICAL_OR expr
2230 // | expr T_LOGICAL_AND expr
2231 // | expr T_LOGICAL_XOR expr
2243 // | expr T_IS_IDENTICAL expr
2244 // | expr T_IS_NOT_IDENTICAL expr
2245 // | expr T_IS_EQUAL expr
2246 // | expr T_IS_NOT_EQUAL expr
2248 // | expr T_IS_SMALLER_OR_EQUAL expr
2250 // | expr T_IS_GREATER_OR_EQUAL expr
2253 case TokenNameOR_OR :
2254 case TokenNameAND_AND :
2262 case TokenNamePLUS :
2263 case TokenNameMINUS :
2264 case TokenNameMULTIPLY :
2265 case TokenNameDIVIDE :
2266 case TokenNameREMAINDER :
2267 case TokenNameLEFT_SHIFT :
2268 case TokenNameRIGHT_SHIFT :
2269 case TokenNameEQUAL_EQUAL_EQUAL :
2270 case TokenNameNOT_EQUAL_EQUAL :
2271 case TokenNameEQUAL_EQUAL :
2272 case TokenNameNOT_EQUAL :
2273 case TokenNameLESS :
2274 case TokenNameLESS_EQUAL :
2275 case TokenNameGREATER :
2276 case TokenNameGREATER_EQUAL :
2280 // | expr T_INSTANCEOF class_name_reference
2281 // | expr '?' expr ':' expr
2282 case TokenNameinstanceof :
2284 class_name_reference();
2286 case TokenNameQUESTION :
2289 if (token == TokenNameCOLON) {
2299 private void class_name_reference() {
2300 // class_name_reference:
2302 //| dynamic_class_name_reference
2303 if (Scanner.TRACE) {
2304 System.out.println("TRACE: class_name_reference()");
2306 if (token == TokenNameIdentifier) {
2309 dynamic_class_name_reference();
2312 private void dynamic_class_name_reference() {
2313 //dynamic_class_name_reference:
2314 // base_variable T_OBJECT_OPERATOR object_property
2315 // dynamic_class_name_variable_properties
2317 if (Scanner.TRACE) {
2318 System.out.println("TRACE: dynamic_class_name_reference()");
2321 if (token == TokenNameMINUS_GREATER) {
2324 dynamic_class_name_variable_properties();
2327 private void dynamic_class_name_variable_properties() {
2328 // dynamic_class_name_variable_properties:
2329 // dynamic_class_name_variable_properties
2330 // dynamic_class_name_variable_property
2332 if (Scanner.TRACE) {
2333 System.out.println("TRACE: dynamic_class_name_variable_properties()");
2335 while (token == TokenNameMINUS_GREATER) {
2336 dynamic_class_name_variable_property();
2339 private void dynamic_class_name_variable_property() {
2340 // dynamic_class_name_variable_property:
2341 // T_OBJECT_OPERATOR object_property
2342 if (Scanner.TRACE) {
2343 System.out.println("TRACE: dynamic_class_name_variable_property()");
2345 if (token == TokenNameMINUS_GREATER) {
2350 private void ctor_arguments() {
2353 //| '(' function_call_parameter_list ')'
2354 if (token == TokenNameLPAREN) {
2356 if (token == TokenNameRPAREN) {
2360 non_empty_function_call_parameter_list();
2361 if (token != TokenNameRPAREN) {
2362 throwSyntaxError("')' expected in ctor_arguments.");
2367 private void assignment_list() {
2369 // assignment_list ',' assignment_list_element
2370 //| assignment_list_element
2372 assignment_list_element();
2373 if (token != TokenNameCOMMA) {
2379 private void assignment_list_element() {
2380 //assignment_list_element:
2382 //| T_LIST '(' assignment_list ')'
2384 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2387 if (token == TokenNamelist) {
2389 if (token == TokenNameLPAREN) {
2392 if (token != TokenNameRPAREN) {
2393 throwSyntaxError("')' expected after 'list' keyword.");
2397 throwSyntaxError("'(' expected after 'list' keyword.");
2402 private void array_pair_list() {
2405 //| non_empty_array_pair_list possible_comma
2406 non_empty_array_pair_list();
2407 if (token == TokenNameCOMMA) {
2411 private void non_empty_array_pair_list() {
2412 //non_empty_array_pair_list:
2413 // non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr
2414 //| non_empty_array_pair_list ',' expr
2415 //| expr T_DOUBLE_ARROW expr
2417 //| non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_variable
2418 //| non_empty_array_pair_list ',' '&' w_variable
2419 //| expr T_DOUBLE_ARROW '&' w_variable
2422 if (token == TokenNameAND) {
2427 if (token == TokenNameAND) {
2430 } else if (token == TokenNameEQUAL_GREATER) {
2432 if (token == TokenNameAND) {
2440 if (token != TokenNameCOMMA) {
2444 if (token == TokenNameRPAREN) {
2449 // private void variableList() {
2452 // if (token == TokenNameCOMMA) {
2459 private void variable_without_objects() {
2460 // variable_without_objects:
2461 // reference_variable
2462 // | simple_indirect_reference reference_variable
2463 if (Scanner.TRACE) {
2464 System.out.println("TRACE: variable_without_objects()");
2466 while (token == TokenNameDOLLAR) {
2469 reference_variable();
2471 private void function_call() {
2473 // T_STRING '(' function_call_parameter_list ')'
2474 //| class_constant '(' function_call_parameter_list ')'
2475 //| static_member '(' function_call_parameter_list ')'
2476 //| variable_without_objects '(' function_call_parameter_list ')'
2477 if (Scanner.TRACE) {
2478 System.out.println("TRACE: function_call()");
2480 if (token == TokenNameIdentifier) {
2483 case TokenNamePAAMAYIM_NEKUDOTAYIM :
2486 if (token == TokenNameIdentifier) {
2491 variable_without_objects();
2496 variable_without_objects();
2498 if (token != TokenNameLPAREN) {
2499 // TODO is this ok ?
2501 // throwSyntaxError("'(' expected in function call.");
2504 if (token == TokenNameRPAREN) {
2508 non_empty_function_call_parameter_list();
2509 if (token != TokenNameRPAREN) {
2510 throwSyntaxError("')' expected in function call.");
2514 // private void function_call_parameter_list() {
2515 // function_call_parameter_list:
2516 // non_empty_function_call_parameter_list { $$ = $1; }
2519 private void non_empty_function_call_parameter_list() {
2520 //non_empty_function_call_parameter_list:
2521 // expr_without_variable
2524 // | non_empty_function_call_parameter_list ',' expr_without_variable
2525 // | non_empty_function_call_parameter_list ',' variable
2526 // | non_empty_function_call_parameter_list ',' '&' w_variable
2527 if (Scanner.TRACE) {
2528 System.out.println("TRACE: non_empty_function_call_parameter_list()");
2531 if (token == TokenNameAND) {
2535 // if (token == TokenNameIdentifier || token == TokenNameVariable
2536 // || token == TokenNameDOLLAR) {
2539 expr_without_variable(true);
2542 if (token != TokenNameCOMMA) {
2548 private void fully_qualified_class_name() {
2549 if (token == TokenNameIdentifier) {
2552 throwSyntaxError("Class name expected.");
2555 private void static_member() {
2557 // fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM
2558 // variable_without_objects
2559 if (Scanner.TRACE) {
2560 System.out.println("TRACE: static_member()");
2562 fully_qualified_class_name();
2563 if (token != TokenNamePAAMAYIM_NEKUDOTAYIM) {
2564 throwSyntaxError("'::' expected after class name (static_member).");
2567 variable_without_objects();
2569 private void base_variable_with_function_calls() {
2570 // base_variable_with_function_calls:
2573 boolean functionCall = false;
2574 if (Scanner.TRACE) {
2575 System.out.println("TRACE: base_variable_with_function_calls()");
2577 // if (token == TokenNameIdentifier) {
2578 // functionCall = true;
2579 // } else if (token == TokenNameVariable) {
2580 // int tempToken = token;
2581 // int tempPosition = scanner.currentPosition;
2583 // if (token == TokenNameLPAREN) {
2584 // functionCall = true;
2586 // token = tempToken;
2587 // scanner.currentPosition = tempPosition;
2588 // scanner.phpMode = true;
2590 // if (functionCall) {
2596 private void base_variable() {
2598 // reference_variable
2599 // | simple_indirect_reference reference_variable
2601 if (Scanner.TRACE) {
2602 System.out.println("TRACE: base_variable()");
2604 if (token == TokenNameIdentifier) {
2607 while (token == TokenNameDOLLAR) {
2610 reference_variable();
2613 // private void simple_indirect_reference() {
2614 // // simple_indirect_reference:
2616 // //| simple_indirect_reference '$'
2618 private void reference_variable() {
2619 // reference_variable:
2620 // reference_variable '[' dim_offset ']'
2621 // | reference_variable '{' expr '}'
2622 // | compound_variable
2623 if (Scanner.TRACE) {
2624 System.out.println("TRACE: reference_variable()");
2626 compound_variable();
2628 if (token == TokenNameLBRACE) {
2631 if (token != TokenNameRBRACE) {
2632 throwSyntaxError("'}' expected in reference variable.");
2635 } else if (token == TokenNameLBRACKET) {
2637 if (token != TokenNameRBRACKET) {
2640 if (token != TokenNameRBRACKET) {
2641 throwSyntaxError("']' expected in reference variable.");
2650 private void compound_variable() {
2651 // compound_variable:
2653 // | '$' '{' expr '}'
2654 if (Scanner.TRACE) {
2655 System.out.println("TRACE: compound_variable()");
2657 if (token == TokenNameVariable) {
2660 // because of simple_indirect_reference
2661 while (token == TokenNameDOLLAR) {
2664 if (token != TokenNameLBRACE) {
2665 throwSyntaxError("'{' expected after compound variable token '$'.");
2669 if (token != TokenNameRBRACE) {
2670 throwSyntaxError("'}' expected after compound variable token '$'.");
2675 // private void dim_offset() {
2681 private void object_property() {
2684 //| variable_without_objects
2685 if (Scanner.TRACE) {
2686 System.out.println("TRACE: object_property()");
2688 if (token == TokenNameVariable || token == TokenNameDOLLAR) {
2689 variable_without_objects();
2694 private void object_dim_list() {
2696 // object_dim_list '[' dim_offset ']'
2697 //| object_dim_list '{' expr '}'
2699 if (Scanner.TRACE) {
2700 System.out.println("TRACE: object_dim_list()");
2704 if (token == TokenNameLBRACE) {
2707 if (token != TokenNameRBRACE) {
2708 throwSyntaxError("'}' expected in object_dim_list.");
2711 } else if (token == TokenNameLBRACKET) {
2713 if (token == TokenNameRBRACKET) {
2718 if (token != TokenNameRBRACKET) {
2719 throwSyntaxError("']' expected in object_dim_list.");
2727 private void variable_name() {
2731 if (Scanner.TRACE) {
2732 System.out.println("TRACE: variable_name()");
2734 if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
2735 if (token > TokenNameKEYWORD) {
2736 // TODO show a warning "Keyword used as variable" ?
2740 if (token != TokenNameLBRACE) {
2741 throwSyntaxError("'{' expected in variable name.");
2745 if (token != TokenNameRBRACE) {
2746 throwSyntaxError("'}' expected in variable name.");
2751 private void r_variable() {
2754 private void w_variable() {
2757 private void rw_variable() {
2760 private void variable() {
2762 // base_variable_with_function_calls T_OBJECT_OPERATOR
2763 // object_property method_or_not variable_properties
2764 // | base_variable_with_function_calls
2765 base_variable_with_function_calls();
2766 if (token == TokenNameMINUS_GREATER) {
2770 variable_properties();
2772 // if (token == TokenNameDOLLAR_LBRACE) {
2776 // if (token != TokenNameRBRACE) {
2777 // throwSyntaxError("'}' expected after indirect variable token '${'.");
2781 // if (token == TokenNameVariable) {
2783 // if (token == TokenNameLBRACKET) {
2786 // if (token != TokenNameRBRACKET) {
2787 // throwSyntaxError("']' expected in variable-list.");
2790 // } else if (token == TokenNameEQUAL) {
2795 // throwSyntaxError("$-variable expected in variable-list.");
2799 private void variable_properties() {
2800 // variable_properties:
2801 // variable_properties variable_property
2803 while (token == TokenNameMINUS_GREATER) {
2804 variable_property();
2807 private void variable_property() {
2808 // variable_property:
2809 // T_OBJECT_OPERATOR object_property method_or_not
2810 if (Scanner.TRACE) {
2811 System.out.println("TRACE: variable_property()");
2813 if (token == TokenNameMINUS_GREATER) {
2818 throwSyntaxError("'->' expected in variable_property.");
2821 private void method_or_not() {
2823 // '(' function_call_parameter_list ')'
2825 if (Scanner.TRACE) {
2826 System.out.println("TRACE: method_or_not()");
2828 if (token == TokenNameLPAREN) {
2830 if (token == TokenNameRPAREN) {
2834 non_empty_function_call_parameter_list();
2835 if (token != TokenNameRPAREN) {
2836 throwSyntaxError("')' expected in method_or_not.");
2841 private void exit_expr() {
2845 if (token != TokenNameLPAREN) {
2849 if (token == TokenNameRPAREN) {
2854 if (token != TokenNameRPAREN) {
2855 throwSyntaxError("')' expected after keyword 'exit'");
2859 private void encaps_list() {
2860 // encaps_list encaps_var
2861 // | encaps_list T_STRING
2862 // | encaps_list T_NUM_STRING
2863 // | encaps_list T_ENCAPSED_AND_WHITESPACE
2864 // | encaps_list T_CHARACTER
2865 // | encaps_list T_BAD_CHARACTER
2866 // | encaps_list '['
2867 // | encaps_list ']'
2868 // | encaps_list '{'
2869 // | encaps_list '}'
2870 // | encaps_list T_OBJECT_OPERATOR
2874 case TokenNameSTRING :
2877 case TokenNameLBRACE :
2878 // scanner.encapsedStringStack.pop();
2881 case TokenNameRBRACE :
2882 // scanner.encapsedStringStack.pop();
2885 case TokenNameLBRACKET :
2886 // scanner.encapsedStringStack.pop();
2889 case TokenNameRBRACKET :
2890 // scanner.encapsedStringStack.pop();
2893 case TokenNameMINUS_GREATER :
2894 // scanner.encapsedStringStack.pop();
2897 case TokenNameVariable :
2898 case TokenNameDOLLAR_LBRACE :
2899 case TokenNameCURLY_OPEN :
2902 // case TokenNameDOLLAR :
2904 // if (token == TokenNameLBRACE) {
2905 // token = TokenNameDOLLAR_LBRACE;
2910 char encapsedChar = ((Character) scanner.encapsedStringStack.peek())
2912 if (encapsedChar == '$') {
2913 scanner.encapsedStringStack.pop();
2914 encapsedChar = ((Character) scanner.encapsedStringStack.peek())
2916 switch (encapsedChar) {
2918 if (token == TokenNameEncapsedString0) {
2921 token = TokenNameSTRING;
2924 if (token == TokenNameEncapsedString1) {
2927 token = TokenNameSTRING;
2930 if (token == TokenNameEncapsedString2) {
2933 token = TokenNameSTRING;
2941 private void encaps_var() {
2943 // | T_VARIABLE '[' encaps_var_offset ']'
2944 // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
2945 // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
2946 // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
2947 // | T_CURLY_OPEN variable '}'
2949 case TokenNameVariable :
2951 if (token == TokenNameLBRACKET) {
2953 // if (token == TokenNameRBRACKET) {
2956 expr(); //encaps_var_offset();
2957 if (token != TokenNameRBRACKET) {
2958 throwSyntaxError("']' expected after variable.");
2960 // scanner.encapsedStringStack.pop();
2963 } else if (token == TokenNameMINUS_GREATER) {
2965 if (token != TokenNameIdentifier) {
2966 throwSyntaxError("Identifier expected after '->'.");
2968 // scanner.encapsedStringStack.pop();
2972 // // scanner.encapsedStringStack.pop();
2973 // int tempToken = TokenNameSTRING;
2974 // if (!scanner.encapsedStringStack.isEmpty()
2975 // && (token == TokenNameEncapsedString0
2976 // || token == TokenNameEncapsedString1
2977 // || token == TokenNameEncapsedString2 || token == TokenNameERROR)) {
2978 // char encapsedChar = ((Character) scanner.encapsedStringStack.peek())
2981 // case TokenNameEncapsedString0 :
2982 // if (encapsedChar == '`') {
2983 // tempToken = TokenNameEncapsedString0;
2986 // case TokenNameEncapsedString1 :
2987 // if (encapsedChar == '\'') {
2988 // tempToken = TokenNameEncapsedString1;
2991 // case TokenNameEncapsedString2 :
2992 // if (encapsedChar == '"') {
2993 // tempToken = TokenNameEncapsedString2;
2996 // case TokenNameERROR :
2997 // if (scanner.source[scanner.currentPosition - 1] == '\\') {
2998 // scanner.currentPosition--;
3004 // token = tempToken;
3007 case TokenNameDOLLAR_LBRACE :
3009 if (token == TokenNameIdentifier) {
3011 if (token == TokenNameLBRACKET) {
3013 // if (token == TokenNameRBRACKET) {
3017 if (token != TokenNameRBRACKET) {
3018 throwSyntaxError("']' expected after '${'.");
3023 if (token != TokenNameRBRACE) {
3024 throwSyntaxError("'}' expected after '${'.");
3026 // scanner.encapsedStringStack.pop();
3030 if (token != TokenNameRBRACE) {
3031 throwSyntaxError("'}' expected.");
3033 // scanner.encapsedStringStack.pop();
3037 case TokenNameCURLY_OPEN :
3039 if (token == TokenNameIdentifier||token>TokenNameKEYWORD) {
3041 if (token == TokenNameLBRACKET) {
3043 // if (token == TokenNameRBRACKET) {
3047 if (token != TokenNameRBRACKET) {
3048 throwSyntaxError("']' expected after '{$'.");
3052 } else if (token == TokenNameMINUS_GREATER) {
3054 if (token != TokenNameIdentifier) {
3055 throwSyntaxError("String token expected.");
3059 // if (token != TokenNameRBRACE) {
3060 // throwSyntaxError("'}' expected after '{$'.");
3062 // // scanner.encapsedStringStack.pop();
3066 if (token != TokenNameRBRACE) {
3067 throwSyntaxError("'}' expected.");
3069 // scanner.encapsedStringStack.pop();
3075 private void encaps_var_offset() {
3080 case TokenNameSTRING :
3083 case TokenNameIntegerLiteral :
3086 case TokenNameVariable :
3089 case TokenNameIdentifier :
3093 throwSyntaxError("Variable or String token expected.");
3097 private void internal_functions_in_yacc() {
3099 case TokenNameisset :
3100 // T_ISSET '(' isset_variables ')'
3102 if (token != TokenNameLPAREN) {
3103 throwSyntaxError("'(' expected after keyword 'isset'");
3107 if (token != TokenNameRPAREN) {
3108 throwSyntaxError("')' expected after keyword 'isset'");
3112 case TokenNameempty :
3113 // T_EMPTY '(' variable ')'
3115 if (token != TokenNameLPAREN) {
3116 throwSyntaxError("'(' expected after keyword 'empty'");
3120 if (token != TokenNameRPAREN) {
3121 throwSyntaxError("')' expected after keyword 'empty'");
3125 case TokenNameinclude :
3130 case TokenNameinclude_once :
3131 // T_INCLUDE_ONCE expr
3135 case TokenNameeval :
3136 // T_EVAL '(' expr ')'
3138 if (token != TokenNameLPAREN) {
3139 throwSyntaxError("'(' expected after keyword 'eval'");
3143 if (token != TokenNameRPAREN) {
3144 throwSyntaxError("')' expected after keyword 'eval'");
3148 case TokenNamerequire :
3153 case TokenNamerequire_once :
3154 // T_REQUIRE_ONCE expr
3160 private void isset_variables() {
3162 // | isset_variables ','
3163 if (token == TokenNameRPAREN) {
3164 throwSyntaxError("Variable expected after keyword 'isset'");
3168 if (token == TokenNameCOMMA) {
3175 private boolean common_scalar() {
3179 // | T_CONSTANT_ENCAPSED_STRING
3186 case TokenNameIntegerLiteral :
3189 case TokenNameDoubleLiteral :
3192 case TokenNameStringLiteral :
3195 case TokenNameStringConstant :
3198 case TokenNameStringInterpolated :
3201 case TokenNameFILE :
3204 case TokenNameLINE :
3207 case TokenNameCLASS_C :
3210 case TokenNameMETHOD_C :
3213 case TokenNameFUNC_C :
3219 private void scalar() {
3222 //| T_STRING_VARNAME
3225 //| '"' encaps_list '"'
3226 //| '\'' encaps_list '\''
3227 //| T_START_HEREDOC encaps_list T_END_HEREDOC
3228 throwSyntaxError("Not yet implemented (scalar).");
3230 private void static_scalar() {
3231 // static_scalar: /* compile-time evaluated scalars */
3234 // | '+' static_scalar
3235 // | '-' static_scalar
3236 // | T_ARRAY '(' static_array_pair_list ')'
3237 // | static_class_constant
3238 if (common_scalar()) {
3242 case TokenNameIdentifier :
3244 // static_class_constant:
3245 // T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING
3246 if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) {
3248 if (token == TokenNameIdentifier) {
3251 throwSyntaxError("Identifier expected after '::' operator.");
3255 case TokenNameEncapsedString0 :
3257 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3258 while (scanner.currentCharacter != '`') {
3259 if (scanner.currentCharacter == '\\') {
3260 scanner.currentPosition++;
3262 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3265 } catch (IndexOutOfBoundsException e) {
3266 throwSyntaxError("'`' expected at end of static string.");
3269 case TokenNameEncapsedString1 :
3271 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3272 while (scanner.currentCharacter != '\'') {
3273 if (scanner.currentCharacter == '\\') {
3274 scanner.currentPosition++;
3276 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3279 } catch (IndexOutOfBoundsException e) {
3280 throwSyntaxError("'\'' expected at end of static string.");
3283 case TokenNameEncapsedString2 :
3285 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3286 while (scanner.currentCharacter != '"') {
3287 if (scanner.currentCharacter == '\\') {
3288 scanner.currentPosition++;
3290 scanner.currentCharacter = scanner.source[scanner.currentPosition++];
3293 } catch (IndexOutOfBoundsException e) {
3294 throwSyntaxError("'\"' expected at end of static string.");
3297 case TokenNamePLUS :
3301 case TokenNameMINUS :
3305 case TokenNamearray :
3307 if (token != TokenNameLPAREN) {
3308 throwSyntaxError("'(' expected after keyword 'array'");
3311 if (token == TokenNameRPAREN) {
3315 non_empty_static_array_pair_list();
3316 if (token != TokenNameRPAREN) {
3317 throwSyntaxError("')' expected after keyword 'array'");
3321 // case TokenNamenull :
3324 // case TokenNamefalse :
3327 // case TokenNametrue :
3331 throwSyntaxError("Static scalar/constant expected.");
3334 private void non_empty_static_array_pair_list() {
3335 // non_empty_static_array_pair_list:
3336 // non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW
3338 //| non_empty_static_array_pair_list ',' static_scalar
3339 //| static_scalar T_DOUBLE_ARROW static_scalar
3343 if (token == TokenNameEQUAL_GREATER) {
3347 if (token != TokenNameCOMMA) {
3351 if (token == TokenNameRPAREN) {
3356 public void reportSyntaxError() { //int act, int currentKind, int
3358 /* remember current scanner position */
3359 int startPos = scanner.startPosition;
3360 int currentPos = scanner.currentPosition;
3361 // String[] expectings;
3362 // String tokenName = name[symbol_index[currentKind]];
3363 //fetch all "accurate" possible terminals that could recover the error
3364 // int start, end = start = asi(stack[stateStackTop]);
3365 // while (asr[end] != 0)
3367 // int length = end - start;
3368 // expectings = new String[length];
3369 // if (length != 0) {
3370 // char[] indexes = new char[length];
3371 // System.arraycopy(asr, start, indexes, 0, length);
3372 // for (int i = 0; i < length; i++) {
3373 // expectings[i] = name[symbol_index[indexes[i]]];
3376 //if the pb is an EOF, try to tell the user that they are some
3377 // if (tokenName.equals(UNEXPECTED_EOF)) {
3378 // if (!this.checkAndReportBracketAnomalies(problemReporter())) {
3379 // char[] tokenSource;
3381 // tokenSource = this.scanner.getCurrentTokenSource();
3382 // } catch (Exception e) {
3383 // tokenSource = new char[] {};
3385 // problemReporter().parseError(
3386 // this.scanner.startPosition,
3387 // this.scanner.currentPosition - 1,
3392 // } else { //the next test is HEAVILY grammar DEPENDENT.
3393 // if ((length == 14)
3394 // && (expectings[0] == "=") //$NON-NLS-1$
3395 // && (expectings[1] == "*=") //$NON-NLS-1$
3396 // && (expressionPtr > -1)) {
3397 // switch(currentKind) {
3398 // case TokenNameSEMICOLON:
3399 // case TokenNamePLUS:
3400 // case TokenNameMINUS:
3401 // case TokenNameDIVIDE:
3402 // case TokenNameREMAINDER:
3403 // case TokenNameMULTIPLY:
3404 // case TokenNameLEFT_SHIFT:
3405 // case TokenNameRIGHT_SHIFT:
3406 //// case TokenNameUNSIGNED_RIGHT_SHIFT:
3407 // case TokenNameLESS:
3408 // case TokenNameGREATER:
3409 // case TokenNameLESS_EQUAL:
3410 // case TokenNameGREATER_EQUAL:
3411 // case TokenNameEQUAL_EQUAL:
3412 // case TokenNameNOT_EQUAL:
3413 // case TokenNameXOR:
3414 // case TokenNameAND:
3415 // case TokenNameOR:
3416 // case TokenNameOR_OR:
3417 // case TokenNameAND_AND:
3418 // // the ; is not the expected token ==> it ends a statement when an
3419 // expression is not ended
3420 // problemReporter().invalidExpressionAsStatement(expressionStack[expressionPtr]);
3422 // case TokenNameRBRACE :
3423 // problemReporter().missingSemiColon(expressionStack[expressionPtr]);
3426 // char[] tokenSource;
3428 // tokenSource = this.scanner.getCurrentTokenSource();
3429 // } catch (Exception e) {
3430 // tokenSource = new char[] {};
3432 // problemReporter().parseError(
3433 // this.scanner.startPosition,
3434 // this.scanner.currentPosition - 1,
3438 // this.checkAndReportBracketAnomalies(problemReporter());
3443 tokenSource = this.scanner.getCurrentTokenSource();
3444 } catch (Exception e) {
3445 tokenSource = new char[]{};
3447 // problemReporter().parseError(
3448 // this.scanner.startPosition,
3449 // this.scanner.currentPosition - 1,
3453 this.checkAndReportBracketAnomalies(problemReporter());
3456 /* reset scanner where it was */
3457 scanner.startPosition = startPos;
3458 scanner.currentPosition = currentPos;
3460 public static final int RoundBracket = 0;
3461 public static final int SquareBracket = 1;
3462 public static final int CurlyBracket = 2;
3463 public static final int BracketKinds = 3;
3464 protected int[] nestedMethod; //the ptr is nestedType
3465 protected int nestedType, dimensions;
3467 final static int AstStackIncrement = 100;
3468 protected int astPtr;
3469 protected AstNode[] astStack = new AstNode[AstStackIncrement];
3470 protected int astLengthPtr;
3471 protected int[] astLengthStack;
3472 AstNode[] noAstNodes = new AstNode[AstStackIncrement];
3473 public CompilationUnitDeclaration compilationUnit; /*
3474 * the result from parse()
3476 protected ReferenceContext referenceContext;
3477 protected ProblemReporter problemReporter;
3478 protected CompilerOptions options;
3479 // protected CompilationResult compilationResult;
3481 * Returns this parser's problem reporter initialized with its reference
3482 * context. Also it is assumed that a problem is going to be reported, so
3483 * initializes the compilation result's line positions.
3485 public ProblemReporter problemReporter() {
3486 if (scanner.recordLineSeparator) {
3487 compilationUnit.compilationResult.lineSeparatorPositions = scanner
3490 problemReporter.referenceContext = referenceContext;
3491 return problemReporter;
3494 * Reconsider the entire source looking for inconsistencies in {} () []
3496 public boolean checkAndReportBracketAnomalies(ProblemReporter problemReporter) {
3497 scanner.wasAcr = false;
3498 boolean anomaliesDetected = false;
3500 char[] source = scanner.source;
3501 int[] leftCount = {0, 0, 0};
3502 int[] rightCount = {0, 0, 0};
3503 int[] depths = {0, 0, 0};
3504 int[][] leftPositions = new int[][]{new int[10], new int[10], new int[10]};
3505 int[][] leftDepths = new int[][]{new int[10], new int[10], new int[10]};
3506 int[][] rightPositions = new int[][]{new int[10], new int[10],
3508 int[][] rightDepths = new int[][]{new int[10], new int[10], new int[10]};
3509 scanner.currentPosition = scanner.initialPosition; //starting
3511 // (first-zero-based
3513 while (scanner.currentPosition < scanner.eofPosition) { //loop for
3518 // ---------Consume white space and handles
3519 // startPosition---------
3520 boolean isWhiteSpace;
3522 scanner.startPosition = scanner.currentPosition;
3523 // if (((scanner.currentCharacter =
3524 // source[scanner.currentPosition++]) == '\\') &&
3525 // (source[scanner.currentPosition] == 'u')) {
3526 // isWhiteSpace = scanner.jumpOverUnicodeWhiteSpace();
3528 if (scanner.recordLineSeparator
3529 && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3530 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3531 // only record line positions we have not
3533 scanner.pushLineSeparator();
3536 isWhiteSpace = CharOperation.isWhitespace(scanner.currentCharacter);
3538 } while (isWhiteSpace
3539 && (scanner.currentPosition < scanner.eofPosition));
3540 // -------consume token until } is found---------
3541 switch (scanner.currentCharacter) {
3544 int index = leftCount[CurlyBracket]++;
3545 if (index == leftPositions[CurlyBracket].length) {
3546 System.arraycopy(leftPositions[CurlyBracket], 0,
3547 (leftPositions[CurlyBracket] = new int[index * 2]), 0,
3550 .arraycopy(leftDepths[CurlyBracket], 0,
3551 (leftDepths[CurlyBracket] = new int[index * 2]), 0,
3554 leftPositions[CurlyBracket][index] = scanner.startPosition;
3555 leftDepths[CurlyBracket][index] = depths[CurlyBracket]++;
3560 int index = rightCount[CurlyBracket]++;
3561 if (index == rightPositions[CurlyBracket].length) {
3562 System.arraycopy(rightPositions[CurlyBracket], 0,
3563 (rightPositions[CurlyBracket] = new int[index * 2]), 0,
3565 System.arraycopy(rightDepths[CurlyBracket], 0,
3566 (rightDepths[CurlyBracket] = new int[index * 2]), 0,
3569 rightPositions[CurlyBracket][index] = scanner.startPosition;
3570 rightDepths[CurlyBracket][index] = --depths[CurlyBracket];
3575 int index = leftCount[RoundBracket]++;
3576 if (index == leftPositions[RoundBracket].length) {
3577 System.arraycopy(leftPositions[RoundBracket], 0,
3578 (leftPositions[RoundBracket] = new int[index * 2]), 0,
3581 .arraycopy(leftDepths[RoundBracket], 0,
3582 (leftDepths[RoundBracket] = new int[index * 2]), 0,
3585 leftPositions[RoundBracket][index] = scanner.startPosition;
3586 leftDepths[RoundBracket][index] = depths[RoundBracket]++;
3591 int index = rightCount[RoundBracket]++;
3592 if (index == rightPositions[RoundBracket].length) {
3593 System.arraycopy(rightPositions[RoundBracket], 0,
3594 (rightPositions[RoundBracket] = new int[index * 2]), 0,
3596 System.arraycopy(rightDepths[RoundBracket], 0,
3597 (rightDepths[RoundBracket] = new int[index * 2]), 0,
3600 rightPositions[RoundBracket][index] = scanner.startPosition;
3601 rightDepths[RoundBracket][index] = --depths[RoundBracket];
3606 int index = leftCount[SquareBracket]++;
3607 if (index == leftPositions[SquareBracket].length) {
3608 System.arraycopy(leftPositions[SquareBracket], 0,
3609 (leftPositions[SquareBracket] = new int[index * 2]), 0,
3611 System.arraycopy(leftDepths[SquareBracket], 0,
3612 (leftDepths[SquareBracket] = new int[index * 2]), 0,
3615 leftPositions[SquareBracket][index] = scanner.startPosition;
3616 leftDepths[SquareBracket][index] = depths[SquareBracket]++;
3621 int index = rightCount[SquareBracket]++;
3622 if (index == rightPositions[SquareBracket].length) {
3623 System.arraycopy(rightPositions[SquareBracket], 0,
3624 (rightPositions[SquareBracket] = new int[index * 2]), 0,
3626 System.arraycopy(rightDepths[SquareBracket], 0,
3627 (rightDepths[SquareBracket] = new int[index * 2]), 0,
3630 rightPositions[SquareBracket][index] = scanner.startPosition;
3631 rightDepths[SquareBracket][index] = --depths[SquareBracket];
3636 if (scanner.getNextChar('\\')) {
3637 scanner.scanEscapeCharacter();
3638 } else { // consume next character
3639 scanner.unicodeAsBackSlash = false;
3640 // if (((scanner.currentCharacter =
3641 // source[scanner.currentPosition++]) ==
3643 // (source[scanner.currentPosition] ==
3645 // scanner.getNextUnicodeChar();
3647 if (scanner.withoutUnicodePtr != 0) {
3648 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3652 scanner.getNextChar('\'');
3656 // consume next character
3657 scanner.unicodeAsBackSlash = false;
3658 // if (((scanner.currentCharacter =
3659 // source[scanner.currentPosition++]) == '\\') &&
3660 // (source[scanner.currentPosition] == 'u')) {
3661 // scanner.getNextUnicodeChar();
3663 if (scanner.withoutUnicodePtr != 0) {
3664 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3667 while (scanner.currentCharacter != '"') {
3668 if (scanner.currentCharacter == '\r') {
3669 if (source[scanner.currentPosition] == '\n')
3670 scanner.currentPosition++;
3671 break; // the string cannot go further that
3674 if (scanner.currentCharacter == '\n') {
3675 break; // the string cannot go further that
3678 if (scanner.currentCharacter == '\\') {
3679 scanner.scanEscapeCharacter();
3681 // consume next character
3682 scanner.unicodeAsBackSlash = false;
3683 // if (((scanner.currentCharacter =
3684 // source[scanner.currentPosition++]) == '\\')
3685 // && (source[scanner.currentPosition] == 'u'))
3687 // scanner.getNextUnicodeChar();
3689 if (scanner.withoutUnicodePtr != 0) {
3690 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3698 if ((test = scanner.getNextChar('/', '*')) == 0) { //line
3701 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3702 && (source[scanner.currentPosition] == 'u')) {
3703 //-------------unicode traitement
3705 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3706 scanner.currentPosition++;
3707 while (source[scanner.currentPosition] == 'u') {
3708 scanner.currentPosition++;
3711 .getNumericValue(source[scanner.currentPosition++])) > 15
3714 .getNumericValue(source[scanner.currentPosition++])) > 15
3717 .getNumericValue(source[scanner.currentPosition++])) > 15
3720 .getNumericValue(source[scanner.currentPosition++])) > 15
3721 || c4 < 0) { //error don't
3724 scanner.currentCharacter = 'A';
3725 } //something different from \n and \r
3727 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3730 while (scanner.currentCharacter != '\r'
3731 && scanner.currentCharacter != '\n') {
3733 scanner.startPosition = scanner.currentPosition;
3734 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3735 && (source[scanner.currentPosition] == 'u')) {
3736 //-------------unicode traitement
3738 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3739 scanner.currentPosition++;
3740 while (source[scanner.currentPosition] == 'u') {
3741 scanner.currentPosition++;
3744 .getNumericValue(source[scanner.currentPosition++])) > 15
3747 .getNumericValue(source[scanner.currentPosition++])) > 15
3750 .getNumericValue(source[scanner.currentPosition++])) > 15
3753 .getNumericValue(source[scanner.currentPosition++])) > 15
3754 || c4 < 0) { //error don't
3757 scanner.currentCharacter = 'A';
3758 } //something different from \n
3761 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3765 if (scanner.recordLineSeparator
3766 && ((scanner.currentCharacter == '\r') || (scanner.currentCharacter == '\n'))) {
3767 if (scanner.lineEnds[scanner.linePtr] < scanner.startPosition) {
3768 // only record line positions we
3769 // have not recorded yet
3770 scanner.pushLineSeparator();
3771 if (this.scanner.taskTags != null) {
3772 this.scanner.checkTaskTag(this.scanner
3773 .getCurrentTokenStartPosition(), this.scanner
3774 .getCurrentTokenEndPosition());
3780 if (test > 0) { //traditional and annotation
3782 boolean star = false;
3783 // consume next character
3784 scanner.unicodeAsBackSlash = false;
3785 // if (((scanner.currentCharacter =
3786 // source[scanner.currentPosition++]) ==
3788 // (source[scanner.currentPosition] ==
3790 // scanner.getNextUnicodeChar();
3792 if (scanner.withoutUnicodePtr != 0) {
3793 scanner.withoutUnicodeBuffer[++scanner.withoutUnicodePtr] = scanner.currentCharacter;
3796 if (scanner.currentCharacter == '*') {
3800 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3801 && (source[scanner.currentPosition] == 'u')) {
3802 //-------------unicode traitement
3804 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3805 scanner.currentPosition++;
3806 while (source[scanner.currentPosition] == 'u') {
3807 scanner.currentPosition++;
3810 .getNumericValue(source[scanner.currentPosition++])) > 15
3813 .getNumericValue(source[scanner.currentPosition++])) > 15
3816 .getNumericValue(source[scanner.currentPosition++])) > 15
3819 .getNumericValue(source[scanner.currentPosition++])) > 15
3820 || c4 < 0) { //error don't
3823 scanner.currentCharacter = 'A';
3824 } //something different from * and /
3826 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3829 //loop until end of comment */
3830 while ((scanner.currentCharacter != '/') || (!star)) {
3831 star = scanner.currentCharacter == '*';
3833 if (((scanner.currentCharacter = source[scanner.currentPosition++]) == '\\')
3834 && (source[scanner.currentPosition] == 'u')) {
3835 //-------------unicode traitement
3837 int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
3838 scanner.currentPosition++;
3839 while (source[scanner.currentPosition] == 'u') {
3840 scanner.currentPosition++;
3843 .getNumericValue(source[scanner.currentPosition++])) > 15
3846 .getNumericValue(source[scanner.currentPosition++])) > 15
3849 .getNumericValue(source[scanner.currentPosition++])) > 15
3852 .getNumericValue(source[scanner.currentPosition++])) > 15
3853 || c4 < 0) { //error don't
3856 scanner.currentCharacter = 'A';
3857 } //something different from * and
3860 scanner.currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
3864 if (this.scanner.taskTags != null) {
3865 this.scanner.checkTaskTag(this.scanner
3866 .getCurrentTokenStartPosition(), this.scanner
3867 .getCurrentTokenEndPosition());
3874 if (Scanner.isPHPIdentifierStart(scanner.currentCharacter)) {
3875 scanner.scanIdentifierOrKeyword(false);
3878 if (Character.isDigit(scanner.currentCharacter)) {
3879 scanner.scanNumber(false);
3883 //-----------------end switch while
3884 // try--------------------
3885 } catch (IndexOutOfBoundsException e) {
3886 break; // read until EOF
3887 } catch (InvalidInputException e) {
3888 return false; // no clue
3891 if (scanner.recordLineSeparator) {
3892 // compilationUnit.compilationResult.lineSeparatorPositions =
3893 // scanner.getLineEnds();
3895 // check placement anomalies against other kinds of brackets
3896 for (int kind = 0; kind < BracketKinds; kind++) {
3897 for (int leftIndex = leftCount[kind] - 1; leftIndex >= 0; leftIndex--) {
3898 int start = leftPositions[kind][leftIndex]; // deepest
3900 // find matching closing bracket
3901 int depth = leftDepths[kind][leftIndex];
3903 for (int i = 0; i < rightCount[kind]; i++) {
3904 int pos = rightPositions[kind][i];
3905 // want matching bracket further in source with same
3907 if ((pos > start) && (depth == rightDepths[kind][i])) {
3912 if (end < 0) { // did not find a good closing match
3913 problemReporter.unmatchedBracket(start, referenceContext,
3914 compilationUnit.compilationResult);
3917 // check if even number of opening/closing other brackets
3918 // in between this pair of brackets
3920 for (int otherKind = 0; (balance == 0) && (otherKind < BracketKinds); otherKind++) {
3921 for (int i = 0; i < leftCount[otherKind]; i++) {
3922 int pos = leftPositions[otherKind][i];
3923 if ((pos > start) && (pos < end))
3926 for (int i = 0; i < rightCount[otherKind]; i++) {
3927 int pos = rightPositions[otherKind][i];
3928 if ((pos > start) && (pos < end))
3932 problemReporter.unmatchedBracket(start, referenceContext,
3933 compilationUnit.compilationResult); //bracket
3939 // too many opening brackets ?
3940 for (int i = rightCount[kind]; i < leftCount[kind]; i++) {
3941 anomaliesDetected = true;
3942 problemReporter.unmatchedBracket(leftPositions[kind][leftCount[kind]
3943 - i - 1], referenceContext, compilationUnit.compilationResult);
3945 // too many closing brackets ?
3946 for (int i = leftCount[kind]; i < rightCount[kind]; i++) {
3947 anomaliesDetected = true;
3948 problemReporter.unmatchedBracket(rightPositions[kind][i],
3949 referenceContext, compilationUnit.compilationResult);
3951 if (anomaliesDetected)
3954 return anomaliesDetected;
3955 } catch (ArrayStoreException e) { // jdk1.2.2 jit bug
3956 return anomaliesDetected;
3957 } catch (NullPointerException e) { // jdk1.2.2 jit bug
3958 return anomaliesDetected;
3961 protected void pushOnAstLengthStack(int pos) {
3963 astLengthStack[++astLengthPtr] = pos;
3964 } catch (IndexOutOfBoundsException e) {
3965 int oldStackLength = astLengthStack.length;
3966 int[] oldPos = astLengthStack;
3967 astLengthStack = new int[oldStackLength + StackIncrement];
3968 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
3969 astLengthStack[astLengthPtr] = pos;
3972 protected void pushOnAstStack(AstNode node) {
3974 * add a new obj on top of the ast stack
3977 astStack[++astPtr] = node;
3978 } catch (IndexOutOfBoundsException e) {
3979 int oldStackLength = astStack.length;
3980 AstNode[] oldStack = astStack;
3981 astStack = new AstNode[oldStackLength + AstStackIncrement];
3982 System.arraycopy(oldStack, 0, astStack, 0, oldStackLength);
3983 astPtr = oldStackLength;
3984 astStack[astPtr] = node;
3987 astLengthStack[++astLengthPtr] = 1;
3988 } catch (IndexOutOfBoundsException e) {
3989 int oldStackLength = astLengthStack.length;
3990 int[] oldPos = astLengthStack;
3991 astLengthStack = new int[oldStackLength + AstStackIncrement];
3992 System.arraycopy(oldPos, 0, astLengthStack, 0, oldStackLength);
3993 astLengthStack[astLengthPtr] = 1;