1 /**********************************************************************
2 Copyright (c) 2002 Klaus Hartlage - www.eclipseproject.de
3 All rights reserved. This program and the accompanying materials
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;
13 import java.util.ArrayList;
15 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import net.sourceforge.phpeclipse.phpeditor.PHPString;
20 import org.eclipse.core.resources.IFile;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.jface.preference.IPreferenceStore;
24 import test.PHPParserSuperclass;
26 public class Parser extends PHPParserSuperclass implements ITerminalSymbols {
29 public Scanner scanner;
31 private ArrayList phpList;
33 private int currentPHPString;
34 private boolean phpEnd;
36 // private static HashMap keywordMap = null;
44 // row counter for syntax errors:
46 // column counter for syntax errors:
51 // // current identifier
57 private String stringValue;
59 /** Contains the current expression. */
60 // private StringBuffer expression;
62 private boolean phpMode;
64 // final static int TokenNameEOF = 0;
65 // final static int TokenNameERROR = 1;
66 // final static int TokenNameHTML = 2;
68 // final static int TokenNameREMAINDER = 30;
69 // final static int TokenNameNOT = 31;
70 // final static int TokenNameDOT = 32;
71 // final static int TokenNameXOR = 33;
72 // final static int TokenNameDIVIDE = 34;
73 // final static int TokenNameMULTIPLY = 35;
74 // final static int TokenNameMINUS = 36;
75 // final static int TokenNamePLUS = 37;
76 // final static int TokenNameEQUAL_EQUAL = 38;
77 // final static int TokenNameNOT_EQUAL = 39;
78 // final static int TokenNameGREATER = 40;
79 // final static int TokenNameGREATER_EQUAL = 41;
80 // final static int TokenNameLESS = 42;
81 // final static int TokenNameLESS_EQUAL = 43;
82 // final static int TokenNameAND_AND = 44;
83 // final static int TokenNameOR_OR = 45;
84 // // final static int TokenNameHASH = 46;
85 // final static int TokenNameCOLON = 47;
86 // final static int TokenNameDOT_EQUAL = 48;
88 // final static int TokenNameEQUAL = 49;
89 // final static int TokenNameMINUS_GREATER = 50; // ->
90 // final static int TokenNameFOREACH = 51;
91 // final static int TokenNameAND = 52;
92 // //final static int TokenNameDOLLARLISTOPEN = 53;
93 // final static int TokenNameTWIDDLE = 54;
94 // final static int TokenNameTWIDDLE_EQUAL = 55;
95 // final static int TokenNameREMAINDER_EQUAL = 56;
96 // final static int TokenNameXOR_EQUAL = 57;
97 // final static int TokenNameRIGHT_SHIFT_EQUAL = 58;
98 // final static int TokenNameLEFT_SHIFT_EQUAL = 59;
99 // final static int TokenNameAND_EQUAL = 60;
100 // final static int TokenNameOR_EQUAL = 61;
101 // final static int TokenNameQUESTION = 62;
102 // final static int TokenNameCOLON_COLON = 63;
103 // final static int TokenNameAT = 63;
104 // // final static int TokenNameHEREDOC = 64;
106 // final static int TokenNameDOLLAROPEN = 127;
107 // final static int TokenNameLPAREN = 128;
108 // final static int TokenNameRPAREN = 129;
109 // final static int TokenNameLBRACE = 130;
110 // final static int TokenNameRBRACE = 131;
111 // final static int TokenNameLBRACKET = 132;
112 // final static int TokenNameRBRACKET = 133;
113 // final static int TokenNameCOMMA = 134;
115 // final static int TokenNameStringLiteral = 136;
116 // final static int TokenNameIdentifier = 138;
117 // // final static int TokenNameDIGIT = 139;
118 // final static int TokenNameSEMICOLON = 140;
119 // // final static int TokenNameSLOT = 141;
120 // // final static int TokenNameSLOTSEQUENCE = 142;
121 // final static int TokenNameMINUS_MINUS = 144;
122 // final static int TokenNamePLUS_PLUS = 145;
123 // final static int TokenNamePLUS_EQUAL = 146;
124 // final static int TokenNameDIVIDE_EQUAL = 147;
125 // final static int TokenNameMINUS_EQUAL = 148;
126 // final static int TokenNameMULTIPLY_EQUAL = 149;
127 // final static int TokenNameVariable = 150;
128 // final static int TokenNameIntegerLiteral = 151;
129 // final static int TokenNameDoubleLiteral = 152;
130 // final static int TokenNameStringInterpolated = 153;
131 // final static int TokenNameStringConstant = 154;
133 // final static int TokenNameLEFT_SHIFT = 155;
134 // final static int TokenNameRIGHT_SHIFT = 156;
135 // final static int TokenNameEQUAL_EQUAL_EQUAL = 157;
136 // final static int TokenNameNOT_EQUAL_EQUAL = 158;
137 // final static int TokenNameOR = 159;
138 // final static int TokenNameAT = 153; // @
143 public void setFileToParse(IFile fileToParse) {
144 this.currentPHPString = 0;
145 PHPParserSuperclass.fileToParse = fileToParse;
148 this.token = TokenNameEOF;
150 this.initializeScanner();
153 * ClassDeclaration Constructor.
156 *@param sess Description of Parameter
159 public Parser(IFile fileToParse) {
160 // if (keywordMap == null) {
161 // keywordMap = new HashMap();
162 // for (int i = 0; i < PHP_KEYWORS.length; i++) {
163 // keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i]));
166 this.currentPHPString = 0;
167 PHPParserSuperclass.fileToParse = fileToParse;
170 this.token = TokenNameEOF;
172 // this.rowCount = 1;
173 // this.columnCount = 0;
177 this.initializeScanner();
180 public void initializeScanner() {
181 this.scanner = new Scanner(false, false, false, false);
184 * Create marker for the parse error
186 private void setMarker(String message, int charStart, int charEnd, int errorLevel) throws CoreException {
187 setMarker(fileToParse, message, charStart, charEnd, errorLevel);
191 * This method will throw the SyntaxError.
192 * It will add the good lines and columns to the Error
193 * @param error the error message
194 * @throws SyntaxError the error raised
196 private void throwSyntaxError(String error) {
198 // if (str.length() < chIndx) {
201 // // read until end-of-line
203 // while (str.length() > eol) {
204 // ch = str.charAt(eol++);
210 // throw new SyntaxError(
212 // chIndx - columnCount + 1,
213 // str.substring(columnCount, eol),
215 throw new SyntaxError(1, 1, "", error);
219 * This method will throw the SyntaxError.
220 * It will add the good lines and columns to the Error
221 * @param error the error message
222 * @throws SyntaxError the error raised
224 private void throwSyntaxError(String error, int startRow) {
225 throw new SyntaxError(startRow, 0, " ", error);
229 * Method Declaration.
233 // private void getChar() {
234 // if (str.length() > chIndx) {
235 // ch = str.charAt(chIndx++);
240 // chIndx = str.length() + 1;
242 // // token = TokenNameEOF;
247 * gets the next token from input
249 private void getNextToken() throws CoreException {
251 token = scanner.getNextToken();
253 int currentEndPosition = scanner.getCurrentTokenEndPosition();
254 int currentStartPosition = scanner.getCurrentTokenStartPosition();
256 System.out.print(currentStartPosition + "," + currentEndPosition + ": ");
257 System.out.println(scanner.toStringAction(token));
259 } catch (InvalidInputException e) {
260 token = TokenNameERROR;
268 * if it's a <code>double</code> the number will be stored in <code>doubleNumber</code> and the token will have the
269 * value {@link Parser#TokenNameDOUBLE_NUMBER}<br />
270 * if it's a <code>double</code> the number will be stored in <code>longNumber</code> and the token will have the
271 * value {@link Parser#TokenNameINT_NUMBER}
273 // private void getNumber() {
274 // StringBuffer inum = new StringBuffer();
276 // int numFormat = 10;
278 // // save first digit
279 // char firstCh = ch;
283 // // determine number conversions:
284 // if (firstCh == '0') {
313 // if (numFormat == 16) {
314 // while ((ch >= '0' && ch <= '9')
315 // || (ch >= 'a' && ch <= 'f')
316 // || (ch >= 'A' && ch <= 'F')) {
321 // while ((ch >= '0' && ch <= '9')
325 // if ((ch == '.') || (ch == 'E') || (ch == 'e')) {
326 // if (ch == '.' && dFlag != ' ') {
329 // if ((dFlag == 'E') || (dFlag == 'e')) {
335 // if ((ch == '-') || (ch == '+')) {
348 // if (dFlag != ' ') {
349 // doubleNumber = new Double(inum.toString());
350 // token = TokenNameDoubleLiteral;
353 // longNumber = Long.valueOf(inum.toString(), numFormat);
354 // token = TokenNameIntegerLiteral;
358 // } catch (Throwable e) {
359 // throwSyntaxError("Number format error: " + inum.toString());
365 // * @param openChar the opening char ('\'', '"', '`')
366 // * @param typeString the type of string {@link #TokenNameSTRING_CONSTANT},{@link #TokenNameINTERPOLATED_STRING}
367 // * @param errorMsg the error message in case of parse error in the string
369 // private void getString(
370 // final char openChar,
371 // final int typeString,
372 // final String errorMsg) {
373 // StringBuffer sBuffer = new StringBuffer();
374 // boolean openString = true;
375 // int startRow = rowCount;
376 // while (str.length() > chIndx) {
377 // ch = str.charAt(chIndx++);
379 // sBuffer.append(ch);
380 // if (str.length() > chIndx) {
381 // ch = str.charAt(chIndx++);
382 // sBuffer.append(ch);
384 // } else if (ch == openChar) {
385 // openString = false;
387 // } else if (ch == '\n') {
389 // columnCount = chIndx;
391 // sBuffer.append(ch);
395 // if (typeString == TokenNameStringConstant) {
396 // throwSyntaxError(errorMsg, startRow);
398 // throwSyntaxError(errorMsg);
401 // token = typeString;
402 // stringValue = sBuffer.toString();
405 // public void htmlParserTester(String input) {
406 // int lineNumber = 1;
407 // int startLineNumber = 1;
408 // int startIndex = 0;
411 // boolean phpMode = false;
412 // boolean phpFound = false;
414 // phpList = new ArrayList();
415 // currentPHPString = 0;
419 // while (i < input.length()) {
420 // ch = input.charAt(i++);
424 // if ((!phpMode) && ch == '<') {
425 // ch2 = input.charAt(i++);
427 // ch2 = input.charAt(i++);
428 // if (Character.isWhitespace(ch2)) {
433 // startLineNumber = lineNumber;
435 // } else if (ch2 == 'p') {
436 // ch2 = input.charAt(i++);
438 // ch2 = input.charAt(i++);
443 // startLineNumber = lineNumber;
449 // } else if (ch2 == 'P') {
450 // ch2 = input.charAt(i++);
452 // ch2 = input.charAt(i++);
457 // startLineNumber = lineNumber;
470 // if (ch == '/' && i < input.length()) {
471 // ch2 = input.charAt(i++);
473 // while (i < input.length()) {
474 // ch = input.charAt(i++);
475 // if (ch == '?' && i < input.length()) {
476 // ch2 = input.charAt(i++);
485 // startLineNumber));
489 // } else if (ch == '\n') {
495 // } else if (ch2 == '*') {
496 // // multi-line comment
497 // while (i < input.length()) {
498 // ch = input.charAt(i++);
501 // } else if (ch == '*' && i < input.length()) {
502 // ch2 = input.charAt(i++);
513 // } else if (ch == '#') {
514 // while (i < input.length()) {
515 // ch = input.charAt(i++);
516 // if (ch == '?' && i < input.length()) {
517 // ch2 = input.charAt(i++);
523 // input.substring(startIndex, i - 2),
524 // startLineNumber));
528 // } else if (ch == '\n') {
534 // } else if (ch == '"') {
536 // while (i < input.length()) {
537 // ch = input.charAt(i++);
541 // ch == '\\' && i < input.length()) { // escape
543 // } else if (ch == '"') {
548 // } else if (ch == '\'') {
550 // while (i < input.length()) {
551 // ch = input.charAt(i++);
555 // ch == '\\' && i < input.length()) { // escape
557 // } else if (ch == '\'') {
564 // if (ch == '?' && i < input.length()) {
565 // ch2 = input.charAt(i++);
571 // input.substring(startIndex, i - 2),
572 // startLineNumber));
582 // "No PHP source code found.",
588 // "Open PHP tag at end of file.",
593 // input.substring(startIndex, i - 2),
594 // startLineNumber));
596 // // for (int j=0;j<phpList.size();j++) {
597 // // String temp = ((PHPString)phpList.get(j)).getPHPString();
598 // // int startIndx = temp.length()-10;
599 // // if (startIndx<0) {
602 // // System.out.println(temp.substring(startIndx)+"?>");
604 // phpParserTester(null, 1);
605 // // PHPString temp;
606 // // for(int j=0;j<phpList.size();j++) {
607 // // temp = (PHPString) phpList.get(j);
608 // // parser.start(temp.getPHPString(), temp.getLineNumber());
611 // } catch (CoreException e) {
615 public void phpParserTester(String s, int rowCount) throws CoreException {
618 if (phpList.size() != 0) {
619 this.str = ((PHPString) phpList.get(currentPHPString++)).getPHPString();
622 this.token = TokenNameEOF;
624 // this.rowCount = rowCount;
625 // this.columnCount = 0;
628 scanner.setSource(s.toCharArray());
629 scanner.setPHPMode(true);
633 if (token != TokenNameEOF && token != TokenNameERROR) {
636 if (token != TokenNameEOF) {
637 if (token == TokenNameERROR) {
638 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
640 if (token == TokenNameRPAREN) {
641 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
643 if (token == TokenNameRBRACE) {
644 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
646 if (token == TokenNameRBRACKET) {
647 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
650 if (token == TokenNameLPAREN) {
651 throwSyntaxError("Read character '('; end-of-file not reached.");
653 if (token == TokenNameLBRACE) {
654 throwSyntaxError("Read character '{'; end-of-file not reached.");
656 if (token == TokenNameLBRACKET) {
657 throwSyntaxError("Read character '['; end-of-file not reached.");
660 throwSyntaxError("End-of-file not reached.");
663 } catch (SyntaxError err) {
667 // setMarker(err.getMessage(), err.getLine(), ERROR);
668 setMarker(err.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR);
670 // if an error occured,
671 // try to find keywords 'class' or 'function'
672 // to parse the rest of the string
673 while (token != TokenNameEOF && token != TokenNameERROR) {
674 if (token == TokenNameclass || token == TokenNamefunction) {
679 if (token == TokenNameEOF || token == TokenNameERROR) {
688 * Parses a string with php tags
689 * i.e. '<body> <?php phpinfo() ?> </body>'
691 public void parse(String s) throws CoreException {
693 this.token = TokenNameEOF;
695 // this.rowCount = 1;
696 // this.columnCount = 0;
698 this.phpMode = false;
699 /* scanner initialization */
700 scanner.setSource(s.toCharArray());
701 scanner.setPHPMode(false);
705 if (token != TokenNameEOF && token != TokenNameERROR) {
708 if (token != TokenNameEOF) {
709 if (token == TokenNameERROR) {
710 throwSyntaxError("Scanner error (Found unknown token: " + scanner.toStringAction(token) + ")");
712 if (token == TokenNameRPAREN) {
713 throwSyntaxError("Too many closing ')'; end-of-file not reached.");
715 if (token == TokenNameRBRACE) {
716 throwSyntaxError("Too many closing '}'; end-of-file not reached.");
718 if (token == TokenNameRBRACKET) {
719 throwSyntaxError("Too many closing ']'; end-of-file not reached.");
722 if (token == TokenNameLPAREN) {
723 throwSyntaxError("Read character '('; end-of-file not reached.");
725 if (token == TokenNameLBRACE) {
726 throwSyntaxError("Read character '{'; end-of-file not reached.");
728 if (token == TokenNameLBRACKET) {
729 throwSyntaxError("Read character '['; end-of-file not reached.");
732 throwSyntaxError("End-of-file not reached.");
735 } catch (SyntaxError sytaxErr1) {
736 // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(), ERROR);
737 setMarker(sytaxErr1.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR);
739 // if an error occured,
740 // try to find keywords 'class' or 'function'
741 // to parse the rest of the string
742 while (token != TokenNameEOF && token != TokenNameERROR) {
743 if (token == TokenNameclass || token == TokenNamefunction) {
748 if (token == TokenNameEOF || token == TokenNameERROR) {
751 } catch (SyntaxError sytaxErr2) {
752 // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(), ERROR);
753 setMarker(sytaxErr2.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR);
761 public PHPOutlineInfo parseInfo(Object parent, String s) {
762 PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
763 // Stack stack = new Stack();
764 // stack.push(outlineInfo.getDeclarations());
767 this.token = TokenNameEOF;
769 // this.rowCount = 1;
770 // this.columnCount = 0;
772 this.phpMode = false;
773 scanner.setSource(s.toCharArray());
774 scanner.setPHPMode(false);
778 parseDeclarations(outlineInfo, outlineInfo.getDeclarations(), false);
779 } catch (CoreException e) {
784 private boolean isVariable() {
785 return token == TokenNameVariable || token == TokenNamethis;
788 private void parseDeclarations(PHPOutlineInfo outlineInfo, OutlineableWithChildren current, boolean goBack) {
790 // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
791 PHPSegmentWithChildren temp;
794 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
796 while (token != TokenNameEOF && token != TokenNameERROR) {
797 if (token == TokenNameVariable) {
798 ident = scanner.getCurrentIdentifierSource();
799 outlineInfo.addVariable(new String(ident));
801 } else if (token == TokenNamevar) {
803 if (token == TokenNameVariable && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
804 ident = scanner.getCurrentIdentifierSource();
805 //substring(1) added because PHPVarDeclaration doesn't need the $ anymore
806 String variableName = new String(ident).substring(1);
807 outlineInfo.addVariable(variableName);
809 if (token != TokenNameSEMICOLON) {
812 ident = scanner.getCurrentTokenSource();
813 if (token > TokenNameKEYWORD) {
814 current.add(new PHPVarDeclaration(current, variableName,
815 // chIndx - ident.length,
816 scanner.getCurrentTokenStartPosition(), new String(ident)));
819 case TokenNameVariable :
821 current.add(new PHPVarDeclaration(current, variableName,
822 // chIndx - ident.length,
823 scanner.getCurrentTokenStartPosition(), new String(ident)));
825 case TokenNameIdentifier :
826 current.add(new PHPVarDeclaration(current, variableName,
827 // chIndx - ident.length,
828 scanner.getCurrentTokenStartPosition(), new String(ident)));
830 case TokenNameDoubleLiteral :
831 current.add(new PHPVarDeclaration(current, variableName + doubleNumber,
832 // chIndx - ident.length,
833 scanner.getCurrentTokenStartPosition(), new String(ident)));
835 case TokenNameIntegerLiteral :
836 current.add(new PHPVarDeclaration(current, variableName,
837 // chIndx - ident.length,
838 scanner.getCurrentTokenStartPosition(), new String(ident)));
840 case TokenNameStringInterpolated :
841 case TokenNameStringLiteral :
842 current.add(new PHPVarDeclaration(current, variableName,
843 // chIndx - ident.length,
844 scanner.getCurrentTokenStartPosition(), new String(ident)));
846 case TokenNameStringConstant :
847 current.add(new PHPVarDeclaration(current, variableName,
848 // chIndx - ident.length,
849 scanner.getCurrentTokenStartPosition(), new String(ident)));
852 current.add(new PHPVarDeclaration(current, variableName,
853 // chIndx - ident.length
854 scanner.getCurrentTokenStartPosition()));
860 ident = scanner.getCurrentIdentifierSource();
862 current.add(new PHPVarDeclaration(current, variableName,
863 // chIndx - ident.length
864 scanner.getCurrentTokenStartPosition()));
867 } else if (token == TokenNamefunction) {
869 if (token == TokenNameAND) {
872 if (token == TokenNameIdentifier && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) {
873 ident = scanner.getCurrentIdentifierSource();
874 outlineInfo.addVariable(new String(ident));
875 temp = new PHPFunctionDeclaration(current, new String(ident),
876 // chIndx - ident.length
877 scanner.getCurrentTokenStartPosition());
880 parseDeclarations(outlineInfo, temp, true);
882 } else if (token == TokenNameclass) {
884 if (token == TokenNameIdentifier && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) {
885 ident = scanner.getCurrentIdentifierSource();
886 outlineInfo.addVariable(new String(ident));
887 temp = new PHPClassDeclaration(current, new String(ident),
888 // chIndx - ident.len
889 scanner.getCurrentTokenStartPosition());
894 //skip tokens for classname, extends and others until we have the opening '{'
895 while (token != TokenNameLBRACE && token != TokenNameEOF && token != TokenNameERROR) {
898 parseDeclarations(outlineInfo, temp, true);
901 } else if ((token == TokenNameLBRACE) || (token == TokenNameDOLLAR_LBRACE)) {
904 } else if (token == TokenNameRBRACE) {
907 if (counter == 0 && goBack) {
911 token == TokenNamerequire
912 || token == TokenNamerequire_once
913 || token == TokenNameinclude
914 || token == TokenNameinclude_once) {
915 ident = scanner.getCurrentTokenSource();
918 int startPosition = scanner.getCurrentTokenStartPosition();
920 char[] expr = scanner.getCurrentTokenSource(startPosition);
921 outlineInfo.addVariable(new String(ident));
922 current.add(new PHPReqIncDeclaration(current, new String(ident),
923 // chIndx - ident.length,
924 startPosition, new String(expr)));
930 } catch (CoreException e) {
931 } catch (SyntaxError sytaxErr) {
933 // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
934 setMarker(sytaxErr.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR);
935 } catch (CoreException e) {
940 private void statementList() throws CoreException {
942 statement(TokenNameEOF);
943 if ((token == TokenNameRBRACE)
944 || (token == TokenNamecase)
945 || (token == TokenNamedefault)
946 || (token == TokenNameelse)
947 || (token == TokenNameelseif)
948 || (token == TokenNameendif)
949 || (token == TokenNameendfor)
950 || (token == TokenNameendforeach)
951 || (token == TokenNameendwhile)
952 || (token == TokenNameendswitch)
953 || (token == TokenNameEOF)
954 || (token == TokenNameERROR)) {
960 private void compoundStatement() throws CoreException {
961 // '{' [statement-list] '}'
962 if (token == TokenNameLBRACE) {
965 throwSyntaxError("'{' expected in compound-statement.");
967 if (token != TokenNameRBRACE) {
970 if (token == TokenNameRBRACE) {
973 throwSyntaxError("'}' expected in compound-statement.");
977 private void statement(int previousToken) throws CoreException {
978 // if (token > TokenNameKEYWORD && token != TokenNamelist && token != TokenNamenew) {
979 // char[] ident = scanner.getCurrentIdentifierSource();
980 // String keyword = new String(ident);
981 if (token == TokenNameinclude || token == TokenNameinclude_once) {
983 if (token == TokenNameLPAREN) {
985 if (token == TokenNameSEMICOLON) {
988 if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
989 throwSyntaxError("';' expected after 'include' or 'include_once'.");
994 concatenationExpression();
998 } else if (token == TokenNamerequire || token == TokenNamerequire_once) {
1001 if (token == TokenNameLPAREN) {
1003 if (token == TokenNameSEMICOLON) {
1006 if (previousToken != TokenNameAT && token != TokenNameStopPHP) {
1007 throwSyntaxError("';' expected after 'require' or 'require_once'.");
1012 concatenationExpression();
1015 } else if (token == TokenNameif) {
1017 if (token == TokenNameLPAREN) {
1020 throwSyntaxError("'(' expected after 'if' keyword.");
1023 if (token == TokenNameRPAREN) {
1026 throwSyntaxError("')' expected after 'if' condition.");
1031 } else if (token == TokenNameswitch) {
1033 if (token == TokenNameLPAREN) {
1036 throwSyntaxError("'(' expected after 'switch' keyword.");
1039 if (token == TokenNameRPAREN) {
1042 throwSyntaxError("')' expected after 'switch' condition.");
1046 } else if (token == TokenNamefor) {
1048 if (token == TokenNameLPAREN) {
1051 throwSyntaxError("'(' expected after 'for' keyword.");
1053 if (token == TokenNameSEMICOLON) {
1057 if (token == TokenNameSEMICOLON) {
1060 throwSyntaxError("';' expected after 'for'.");
1063 if (token == TokenNameSEMICOLON) {
1067 if (token == TokenNameSEMICOLON) {
1070 throwSyntaxError("';' expected after 'for'.");
1073 if (token == TokenNameRPAREN) {
1077 if (token == TokenNameRPAREN) {
1080 throwSyntaxError("')' expected after 'for'.");
1085 } else if (token == TokenNamewhile) {
1087 if (token == TokenNameLPAREN) {
1090 throwSyntaxError("'(' expected after 'while' keyword.");
1093 if (token == TokenNameRPAREN) {
1096 throwSyntaxError("')' expected after 'while' condition.");
1100 } else if (token == TokenNamedo) {
1102 if (token == TokenNameLBRACE) {
1105 throwSyntaxError("'{' expected after 'do' keyword.");
1107 if (token != TokenNameRBRACE) {
1110 if (token == TokenNameRBRACE) {
1113 throwSyntaxError("'}' expected after 'do' keyword.");
1115 if (token == TokenNamewhile) {
1117 if (token == TokenNameLPAREN) {
1120 throwSyntaxError("'(' expected after 'while' keyword.");
1123 if (token == TokenNameRPAREN) {
1126 throwSyntaxError("')' expected after 'while' condition.");
1129 throwSyntaxError("'while' expected after 'do' keyword.");
1131 if (token == TokenNameSEMICOLON) {
1134 if (token != TokenNameStopPHP) {
1135 throwSyntaxError("';' expected after do-while statement.");
1140 } else if (token == TokenNameforeach) {
1142 if (token == TokenNameLPAREN) {
1145 throwSyntaxError("'(' expected after 'foreach' keyword.");
1148 if (token == TokenNameas) {
1151 throwSyntaxError("'as' expected after 'foreach' exxpression.");
1154 if (token == TokenNameEQUAL_GREATER) {
1158 if (token == TokenNameRPAREN) {
1161 throwSyntaxError("')' expected after 'foreach' expression.");
1166 } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) {
1168 if (token != TokenNameSEMICOLON) {
1171 if (token == TokenNameSEMICOLON) {
1174 if (token != TokenNameStopPHP) {
1175 throwSyntaxError("';' expected after 'continue', 'break' or 'return'.");
1181 } else if (token == TokenNameecho) {
1184 if (token == TokenNameSEMICOLON) {
1187 if (token != TokenNameStopPHP) {
1188 throwSyntaxError("';' expected after 'echo' statement.");
1193 // } else if (token == TokenNameprint) {
1196 // if (token == TokenNameSEMICOLON) {
1199 // if (token != TokenNameStopPHP) {
1200 // throwSyntaxError("';' expected after 'print' statement.");
1206 } else if (token == TokenNameglobal || token == TokenNamestatic) {
1209 if (token == TokenNameSEMICOLON) {
1212 if (token != TokenNameStopPHP) {
1213 throwSyntaxError("';' expected after 'global' or 'static' statement.");
1219 // } else if (token == TokenNameunset) {
1221 // if (token == TokenNameARGOPEN) {
1224 // throwSyntaxError("'(' expected after 'unset' keyword.");
1227 // if (token == TokenNameARGCLOSE) {
1230 // throwSyntaxError("')' expected after 'unset' statement.");
1232 // if (token == TokenNameSEMICOLON) {
1235 // if (token != TokenNameStopPHP) {
1236 // throwSyntaxError("';' expected after 'unset' statement.");
1242 // } else if (token == TokenNameexit || token == TokenNamedie) {
1244 // if (token != TokenNameSEMICOLON) {
1247 // if (token == TokenNameSEMICOLON) {
1250 // if (token != TokenNameStopPHP) {
1251 // throwSyntaxError("';' expected after 'exit' or 'die' statement.");
1257 } else if (token == TokenNamedefine) {
1259 if (token == TokenNameLPAREN) {
1262 throwSyntaxError("'(' expected after 'define' keyword.");
1265 if (token == TokenNameCOMMA) {
1268 throwSyntaxError("',' expected after first 'define' constant.");
1271 if (token == TokenNameCOMMA) {
1275 if (token == TokenNameRPAREN) {
1278 throwSyntaxError("')' expected after 'define' statement.");
1280 if (token == TokenNameSEMICOLON) {
1283 if (token != TokenNameStopPHP) {
1284 throwSyntaxError("';' expected after 'define' statement.");
1289 } else if (token == TokenNamefunction) {
1291 functionDefinition();
1293 } else if (token == TokenNameclass) {
1299 // throwSyntaxError("Unexpected keyword '" + keyword + "'");
1300 } else if (token == TokenNameLBRACE) {
1301 // compoundStatement
1303 if (token != TokenNameRBRACE) {
1306 if (token == TokenNameRBRACE) {
1310 throwSyntaxError("'}' expected.");
1313 if (token != TokenNameSEMICOLON) {
1316 if (token == TokenNameSEMICOLON) {
1320 if (token != TokenNameStopPHP && token != TokenNameEOF) {
1321 throwSyntaxError("';' expected after expression (Found token: " + scanner.toStringAction(token) + ")");
1328 private void classDeclarator() throws CoreException {
1330 //identifier 'extends' identifier
1331 if (token == TokenNameIdentifier) {
1333 if (token == TokenNameextends) {
1336 if (token == TokenNameIdentifier) {
1339 throwSyntaxError("ClassDeclaration name expected after keyword 'extends'.");
1341 } while (token == TokenNameCOMMA);
1344 if (token > TokenNameKEYWORD) {
1345 throwSyntaxError("Don't use keyword for class declaration [" + token + "].");
1347 throwSyntaxError("ClassDeclaration name expected after keyword 'class'.");
1351 private void classBody() throws CoreException {
1352 //'{' [class-element-list] '}'
1353 if (token == TokenNameLBRACE) {
1355 if (token != TokenNameRBRACE) {
1358 if (token == TokenNameRBRACE) {
1361 throwSyntaxError("'}' expected at end of class body.");
1364 throwSyntaxError("'{' expected at start of class body.");
1368 private void classElementList() throws CoreException {
1371 } while (token == TokenNamefunction || token == TokenNamevar);
1374 private void classElement() throws CoreException {
1376 //function-definition
1377 if (token == TokenNamefunction) {
1379 functionDefinition();
1380 } else if (token == TokenNamevar) {
1384 throwSyntaxError("'function' or 'var' expected.");
1388 private void classProperty() throws CoreException {
1389 //'var' variable ';'
1390 //'var' variable '=' constant ';'
1392 if (token == TokenNameVariable) {
1394 if (token == TokenNameEQUAL) {
1399 if (token == TokenNamethis) {
1400 throwSyntaxError("Reserved word '$this' not allowed after keyword 'var'.");
1402 throwSyntaxError("Variable expected after keyword 'var'.");
1404 if (token != TokenNameCOMMA) {
1409 if (token == TokenNameSEMICOLON) {
1412 throwSyntaxError("';' expected after variable declaration.");
1416 private void functionDefinition() throws CoreException {
1417 functionDeclarator();
1418 compoundStatement();
1421 private void functionDeclarator() throws CoreException {
1422 //identifier '(' [parameter-list] ')'
1423 if (token == TokenNameAND) {
1426 if (token == TokenNameIdentifier) {
1428 if (token == TokenNameLPAREN) {
1431 throwSyntaxError("'(' expected in function declaration.");
1433 if (token != TokenNameRPAREN) {
1436 if (token != TokenNameRPAREN) {
1437 throwSyntaxError("')' expected in function declaration.");
1442 if (token > TokenNameKEYWORD) {
1443 throwSyntaxError("Don't use keyword for function declaration [" + token + "].");
1445 throwSyntaxError("Function name expected after keyword 'function'.");
1449 private void parameterList() throws CoreException {
1450 //parameter-declaration
1451 //parameter-list ',' parameter-declaration
1453 parameterDeclaration();
1454 if (token != TokenNameCOMMA) {
1461 private void parameterDeclaration() throws CoreException {
1463 //variable-reference
1464 if (token == TokenNameAND) {
1469 throwSyntaxError("Variable expected after reference operator '&'.");
1472 //variable '=' constant
1473 if (token == TokenNameVariable) {
1475 if (token == TokenNameEQUAL) {
1481 if (token == TokenNamethis) {
1482 throwSyntaxError("Reserved word '$this' not allowed in parameter declaration.");
1486 private void labeledStatementList() throws CoreException {
1487 if (token != TokenNamecase && token != TokenNamedefault) {
1488 throwSyntaxError("'case' or 'default' expected.");
1491 if (token == TokenNamecase) {
1493 expression(); //constant();
1494 if (token == TokenNameCOLON) {
1496 if (token == TokenNamecase || token == TokenNamedefault) { // empty case statement ?
1500 } else if (token == TokenNameSEMICOLON) {
1502 // "':' expected after 'case' keyword (Found token: "
1503 // + scanner.toStringAction(token)
1508 "':' expected after 'case' keyword (Found token: " + scanner.toStringAction(token) + ")",
1509 scanner.getCurrentTokenStartPosition(),
1510 scanner.getCurrentTokenEndPosition(),
1513 if (token == TokenNamecase) { // empty case statement ?
1518 throwSyntaxError("':' character after 'case' constant expected (Found token: " + scanner.toStringAction(token) + ")");
1520 } else { // TokenNamedefault
1522 if (token == TokenNameCOLON) {
1526 throwSyntaxError("':' character after 'default' expected.");
1529 } while (token == TokenNamecase || token == TokenNamedefault);
1532 // public void labeledStatement() {
1533 // if (token == TokenNamecase) {
1536 // if (token == TokenNameDDOT) {
1540 // throwSyntaxError("':' character after 'case' constant expected.");
1543 // } else if (token == TokenNamedefault) {
1545 // if (token == TokenNameDDOT) {
1549 // throwSyntaxError("':' character after 'default' expected.");
1555 // public void expressionStatement() {
1558 // private void inclusionStatement() {
1561 // public void compoundStatement() {
1564 // public void selectionStatement() {
1567 // public void iterationStatement() {
1570 // public void jumpStatement() {
1573 // public void outputStatement() {
1576 // public void scopeStatement() {
1579 // public void flowStatement() {
1582 // public void definitionStatement() {
1585 private void ifStatement() throws CoreException {
1586 // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';'
1587 if (token == TokenNameCOLON) {
1589 if (token != TokenNameendif) {
1592 case TokenNameelse :
1594 if (token == TokenNameCOLON) {
1596 if (token != TokenNameendif) {
1600 if (token == TokenNameif) { //'else if'
1602 elseifStatementList();
1604 throwSyntaxError("':' expected after 'else'.");
1608 case TokenNameelseif :
1610 elseifStatementList();
1615 if (token != TokenNameendif) {
1616 throwSyntaxError("'endif' expected.");
1619 if (token != TokenNameSEMICOLON) {
1620 throwSyntaxError("';' expected after if-statement.");
1624 // statement [else-statement]
1625 statement(TokenNameEOF);
1626 if (token == TokenNameelseif) {
1628 if (token == TokenNameLPAREN) {
1631 throwSyntaxError("'(' expected after 'elseif' keyword.");
1634 if (token == TokenNameRPAREN) {
1637 throwSyntaxError("')' expected after 'elseif' condition.");
1640 } else if (token == TokenNameelse) {
1642 statement(TokenNameEOF);
1647 private void elseifStatementList() throws CoreException {
1651 case TokenNameelse :
1653 if (token == TokenNameCOLON) {
1655 if (token != TokenNameendif) {
1660 if (token == TokenNameif) { //'else if'
1663 throwSyntaxError("':' expected after 'else'.");
1667 case TokenNameelseif :
1676 private void elseifStatement() throws CoreException {
1677 if (token == TokenNameLPAREN) {
1680 if (token != TokenNameRPAREN) {
1681 throwSyntaxError("')' expected in else-if-statement.");
1684 if (token != TokenNameCOLON) {
1685 throwSyntaxError("':' expected in else-if-statement.");
1688 if (token != TokenNameendif) {
1694 private void switchStatement() throws CoreException {
1695 if (token == TokenNameCOLON) {
1696 // ':' [labeled-statement-list] 'endswitch' ';'
1698 labeledStatementList();
1699 if (token != TokenNameendswitch) {
1700 throwSyntaxError("'endswitch' expected.");
1703 if (token != TokenNameSEMICOLON) {
1704 throwSyntaxError("';' expected after switch-statement.");
1708 // '{' [labeled-statement-list] '}'
1709 if (token != TokenNameLBRACE) {
1710 throwSyntaxError("'{' expected in switch statement.");
1713 if (token != TokenNameRBRACE) {
1714 labeledStatementList();
1716 if (token != TokenNameRBRACE) {
1717 throwSyntaxError("'}' expected in switch statement.");
1724 private void forStatement() throws CoreException {
1725 if (token == TokenNameCOLON) {
1728 if (token != TokenNameendfor) {
1729 throwSyntaxError("'endfor' expected.");
1732 if (token != TokenNameSEMICOLON) {
1733 throwSyntaxError("';' expected after for-statement.");
1737 statement(TokenNameEOF);
1741 private void whileStatement() throws CoreException {
1742 // ':' statement-list 'endwhile' ';'
1743 if (token == TokenNameCOLON) {
1746 if (token != TokenNameendwhile) {
1747 throwSyntaxError("'endwhile' expected.");
1750 if (token != TokenNameSEMICOLON) {
1751 throwSyntaxError("';' expected after while-statement.");
1755 statement(TokenNameEOF);
1759 private void foreachStatement() throws CoreException {
1760 if (token == TokenNameCOLON) {
1763 if (token != TokenNameendforeach) {
1764 throwSyntaxError("'endforeach' expected.");
1767 if (token != TokenNameSEMICOLON) {
1768 throwSyntaxError("';' expected after foreach-statement.");
1772 statement(TokenNameEOF);
1776 private void exitStatus() throws CoreException {
1777 if (token == TokenNameLPAREN) {
1780 throwSyntaxError("'(' expected in 'exit-status'.");
1782 if (token != TokenNameRPAREN) {
1785 if (token == TokenNameRPAREN) {
1788 throwSyntaxError("')' expected after 'exit-status'.");
1792 private void expressionList() throws CoreException {
1795 if (token == TokenNameCOMMA) {
1803 private void expression() throws CoreException {
1804 //todo: find a better way to get the expression
1805 // expression = new StringBuffer();
1806 // for (int i = chIndx; i < str.length(); i++) {
1807 // if (str.charAt(i) == ';') {
1810 // expression.append(str.charAt(i));
1813 // if (token == TokenNameSTRING_CONSTANT || token == TokenNameINTERPOLATED_STRING) {
1816 logicalinclusiveorExpression();
1817 // while (token != TokenNameSEMICOLON) {
1823 private void postfixExpression() throws CoreException {
1826 boolean castFlag = false;
1827 boolean arrayFlag = false;
1833 case TokenNamenull :
1836 case TokenNamefalse :
1839 case TokenNametrue :
1842 case TokenNameStringConstant :
1845 case TokenNameHEREDOC :
1846 case TokenNameStringInterpolated :
1847 case TokenNameStringLiteral :
1850 case TokenNameLPAREN :
1853 if (token == TokenNameIdentifier) {
1854 // check if identifier is a type:
1855 // ident = identifier;
1856 ident = scanner.getCurrentIdentifierSource();
1857 String str = new String(ident).toLowerCase();
1858 for (int i = 0; i < PHP_TYPES.length; i++) {
1859 if (PHP_TYPES[i].equals(str)) {
1861 if (PHP_TYPES[i].equals("array")) {
1871 if (arrayFlag && token == TokenNameLPAREN) {
1873 if (token == TokenNameRPAREN) {
1877 if (token != TokenNameRPAREN) {
1878 throwSyntaxError(") expected after 'array('.");
1882 if (token != TokenNameRPAREN) {
1883 throwSyntaxError(") expected after cast-type '" + str + "'.");
1891 if (token != TokenNameRPAREN) {
1892 throwSyntaxError(") expected in postfix-expression.");
1896 case TokenNameDoubleLiteral :
1899 case TokenNameIntegerLiteral :
1902 case TokenNameDOLLAR_LBRACE :
1905 if (token != TokenNameRBRACE) {
1906 throwSyntaxError("'}' expected after indirect variable token '${'.");
1910 case TokenNameVariable :
1911 case TokenNamethis :
1912 ident = scanner.getCurrentIdentifierSource();
1914 if (token == TokenNameLBRACE) {
1917 if (token != TokenNameRBRACE) {
1918 throwSyntaxError("'}' expected after variable '" + new String(ident) + "' in variable-expression.");
1921 } else if (token == TokenNameLPAREN) {
1923 if (token != TokenNameRPAREN) {
1925 if (token != TokenNameRPAREN) {
1926 throwSyntaxError("')' expected after variable '" + new String(ident) + "' in postfix-expression.");
1932 case TokenNameIdentifier :
1933 ident = scanner.getCurrentIdentifierSource();
1935 if (token == TokenNameLPAREN) {
1937 if (token != TokenNameRPAREN) {
1939 if (token != TokenNameRPAREN) {
1941 "')' expected after identifier '"
1943 + "' in postfix-expression."
1945 + scanner.toStringAction(token)
1952 case TokenNameprint :
1955 // if (token == TokenNameSEMICOLON) {
1958 // if (token != TokenNameStopPHP) {
1959 // throwSyntaxError("';' expected after 'print' statement.");
1964 case TokenNamelist :
1966 if (token == TokenNameLPAREN) {
1968 if (token == TokenNameCOMMA) {
1972 if (token != TokenNameRPAREN) {
1973 throwSyntaxError("')' expected after 'list' keyword.");
1976 // if (token == TokenNameSET) {
1978 // logicalinclusiveorExpression();
1981 throwSyntaxError("'(' expected after 'list' keyword.");
1984 // case TokenNameexit :
1986 // if (token != TokenNameSEMICOLON) {
1989 // if (token == TokenNameSEMICOLON) {
1992 // if (token != TokenNameStopPHP) {
1993 // throwSyntaxError("';' expected after 'exit' expression.");
1998 // case TokenNamedie :
2000 // if (token != TokenNameSEMICOLON) {
2003 // if (token == TokenNameSEMICOLON) {
2006 // if (token != TokenNameStopPHP) {
2007 // throwSyntaxError("';' expected after 'die' expression.");
2012 // case TokenNamearray :
2014 // if (token == TokenNameARGOPEN) {
2016 // if (token == TokenNameCOMMA) {
2019 // expressionList();
2020 // if (token != TokenNameARGCLOSE) {
2021 // throwSyntaxError("')' expected after 'list' keyword.");
2024 // if (token == TokenNameSET) {
2026 // logicalinclusiveorExpression();
2029 // throwSyntaxError("'(' expected after 'list' keyword.");
2033 boolean while_flag = true;
2036 case TokenNameLBRACKET :
2039 if (token != TokenNameRBRACKET) {
2040 throwSyntaxError("] expected in postfix-expression.");
2044 case TokenNameCOLON_COLON : // ::
2045 case TokenNameMINUS_GREATER : // ->
2047 if (token > TokenNameKEYWORD) {
2048 ident = scanner.getCurrentIdentifierSource();
2050 // "Avoid using keyword '"
2051 // + new String(ident)
2052 // + "' as variable name.",
2056 "Avoid using keyword '" + new String(ident) + "' as variable name.",
2057 scanner.getCurrentTokenStartPosition(),
2058 scanner.getCurrentTokenEndPosition(),
2062 case TokenNameVariable :
2063 ident = scanner.getCurrentIdentifierSource();
2065 // if (token == TokenNameARGOPEN) {
2067 // expressionList();
2068 // if (token != TokenNameARGCLOSE) {
2069 // throwSyntaxError(") expected after variable '" + ident + "'.");
2074 case TokenNameIdentifier :
2075 //ident = scanner.getCurrentIdentifierSource();
2078 case TokenNameLBRACE :
2081 if (token != TokenNameRBRACE) {
2082 throwSyntaxError("} expected in postfix-expression.");
2087 throwSyntaxError("Syntax error after '->' token.");
2088 } while (token == TokenNameLBRACKET || token == TokenNameLPAREN || token == TokenNameLBRACE) {
2089 if (token == TokenNameLBRACKET) {
2092 if (token != TokenNameRBRACKET) {
2093 throwSyntaxError("] expected after '->'.");
2096 } else if (token == TokenNameLPAREN) {
2099 if (token != TokenNameRPAREN) {
2100 throwSyntaxError(") expected after '->'.");
2103 } else if (token == TokenNameLBRACE) {
2106 if (token != TokenNameRBRACE) {
2107 throwSyntaxError("} expected after '->'.");
2113 case TokenNamePLUS_PLUS :
2116 case TokenNameMINUS_MINUS :
2127 private void unaryExpression() throws CoreException {
2129 case TokenNamePLUS_PLUS :
2133 case TokenNameMINUS_MINUS :
2137 // '@' '&' '*' '+' '-' '~' '!'
2140 if (token == TokenNameinclude
2141 || token == TokenNameinclude_once
2142 || token == TokenNamerequire
2143 || token == TokenNamerequire_once) {
2144 statement(TokenNameAT);
2146 postfixExpression(); // castExpression();
2153 case TokenNameMULTIPLY :
2157 case TokenNamePLUS :
2161 case TokenNameMINUS :
2165 case TokenNameTWIDDLE :
2174 postfixExpression();
2178 private void castExpression() throws CoreException {
2179 // if (token == TokenNameARGOPEN) {
2182 // if (token != TokenNameARGCLOSE) {
2183 // throwSyntaxError(") expected after cast-expression.");
2190 private void assignExpression() throws CoreException {
2192 if (token == TokenNameEQUAL) { // =
2194 logicalinclusiveorExpression();
2195 } else if (token == TokenNameDOT_EQUAL) { // .=
2197 logicalinclusiveorExpression();
2198 } else if (token == TokenNameEQUAL_GREATER) { // =>
2200 logicalinclusiveorExpression();
2201 } else if (token == TokenNamePLUS_EQUAL) { // +=
2203 logicalinclusiveorExpression();
2204 } else if (token == TokenNameMINUS_EQUAL) { // -=
2206 logicalinclusiveorExpression();
2207 } else if (token == TokenNameMULTIPLY_EQUAL) { // *=
2209 logicalinclusiveorExpression();
2210 } else if (token == TokenNameDIVIDE_EQUAL) { // *=
2212 logicalinclusiveorExpression();
2213 } else if (token == TokenNameREMAINDER_EQUAL) { // %=
2215 logicalinclusiveorExpression();
2216 } else if (token == TokenNameAND_EQUAL) { // &=
2218 logicalinclusiveorExpression();
2219 } else if (token == TokenNameOR_EQUAL) { // |=
2221 logicalinclusiveorExpression();
2222 } else if (token == TokenNameXOR_EQUAL) { // ^=
2224 logicalinclusiveorExpression();
2225 } else if (token == TokenNameLEFT_SHIFT_EQUAL) { // <<=
2227 logicalinclusiveorExpression();
2228 } else if (token == TokenNameRIGHT_SHIFT_EQUAL) { // >>=
2230 logicalinclusiveorExpression();
2231 } else if (token == TokenNameTWIDDLE_EQUAL) { // ~=
2233 logicalinclusiveorExpression();
2237 private void multiplicativeExpression() throws CoreException {
2240 if (token != TokenNameMULTIPLY && token != TokenNameDIVIDE && token != TokenNameREMAINDER) {
2247 private void concatenationExpression() throws CoreException {
2249 multiplicativeExpression();
2250 if (token != TokenNameDOT) {
2257 private void additiveExpression() throws CoreException {
2259 concatenationExpression();
2260 if (token != TokenNamePLUS && token != TokenNameMINUS) {
2267 private void shiftExpression() throws CoreException {
2269 additiveExpression();
2270 if (token != TokenNameLEFT_SHIFT && token != TokenNameRIGHT_SHIFT) {
2277 private void relationalExpression() throws CoreException {
2280 if (token != TokenNameLESS && token != TokenNameGREATER && token != TokenNameLESS_EQUAL && token != TokenNameGREATER_EQUAL) {
2287 private void identicalExpression() throws CoreException {
2289 relationalExpression();
2290 if (token != TokenNameEQUAL_EQUAL_EQUAL && token != TokenNameNOT_EQUAL_EQUAL) {
2297 private void equalityExpression() throws CoreException {
2299 identicalExpression();
2300 if (token != TokenNameEQUAL_EQUAL && token != TokenNameNOT_EQUAL) {
2307 private void ternaryExpression() throws CoreException {
2308 equalityExpression();
2309 if (token == TokenNameQUESTION) {
2312 if (token == TokenNameCOLON) {
2316 throwSyntaxError("':' expected in ternary operator '? :'.");
2321 private void andExpression() throws CoreException {
2323 ternaryExpression();
2324 if (token != TokenNameAND) {
2331 private void exclusiveorExpression() throws CoreException {
2334 if (token != TokenNameXOR) {
2341 private void inclusiveorExpression() throws CoreException {
2343 exclusiveorExpression();
2344 if (token != TokenNameOR) {
2351 private void booleanandExpression() throws CoreException {
2353 inclusiveorExpression();
2354 if (token != TokenNameAND_AND) {
2361 private void booleanorExpression() throws CoreException {
2363 booleanandExpression();
2364 if (token != TokenNameOR_OR) {
2371 private void logicalandExpression() throws CoreException {
2373 booleanorExpression();
2374 if (token != TokenNameAND) {
2381 private void logicalexclusiveorExpression() throws CoreException {
2383 logicalandExpression();
2384 if (token != TokenNameXOR) {
2391 private void logicalinclusiveorExpression() throws CoreException {
2393 logicalexclusiveorExpression();
2394 if (token != TokenNameOR) {
2401 // public void assignmentExpression() {
2402 // if (token == TokenNameVARIABLE) {
2404 // if (token == TokenNameSET) {
2406 // logicalinclusiveorExpression();
2409 // logicalinclusiveorExpression();
2413 private void variableList() throws CoreException {
2416 if (token == TokenNameCOMMA) {
2424 private void variable() throws CoreException {
2425 if (token == TokenNameDOLLAR_LBRACE) {
2429 if (token != TokenNameRBRACE) {
2430 throwSyntaxError("'}' expected after indirect variable token '${'.");
2434 if (token == TokenNameVariable) {
2436 if (token == TokenNameLBRACKET) {
2439 if (token != TokenNameRBRACKET) {
2440 throwSyntaxError("']' expected in variable-list.");
2443 } else if (token == TokenNameEQUAL) {
2448 throwSyntaxError("$-variable expected in variable-list.");
2454 * It will look for a value (after a '=' for example)
2455 * @throws CoreException
2457 private void constant() throws CoreException {
2460 case TokenNamePLUS :
2463 case TokenNameDoubleLiteral :
2466 case TokenNameIntegerLiteral :
2470 throwSyntaxError("Constant expected after '+' presign.");
2473 case TokenNameMINUS :
2476 case TokenNameDoubleLiteral :
2479 case TokenNameIntegerLiteral :
2483 throwSyntaxError("Constant expected after '-' presign.");
2486 case TokenNamenull :
2489 case TokenNamefalse :
2492 case TokenNametrue :
2495 case TokenNameIdentifier :
2496 // ident = identifier;
2497 char[] ident = scanner.getCurrentIdentifierSource();
2499 if (token == TokenNameLPAREN) {
2501 if (token != TokenNameRPAREN) {
2503 if (token != TokenNameRPAREN) {
2504 throwSyntaxError("')' expected after identifier '" + new String(ident) + "' in postfix-expression.");
2510 case TokenNameStringLiteral :
2513 case TokenNameStringConstant :
2516 case TokenNameStringInterpolated :
2519 case TokenNameDoubleLiteral :
2522 case TokenNameIntegerLiteral :
2526 throwSyntaxError("Constant expected.");