3 CHOICE_AMBIGUITY_CHECK = 2;
4 OTHER_AMBIGUITY_CHECK = 1;
7 DEBUG_LOOKAHEAD = false;
8 DEBUG_TOKEN_MANAGER = false;
9 OPTIMIZE_TOKEN_MANAGER = false;
10 ERROR_REPORTING = true;
11 JAVA_UNICODE_ESCAPE = false;
12 UNICODE_INPUT = false;
14 USER_TOKEN_MANAGER = false;
15 USER_CHAR_STREAM = false;
17 BUILD_TOKEN_MANAGER = true;
19 FORCE_LA_CHECK = false;
22 PARSER_BEGIN(PHPParser)
25 import org.eclipse.core.resources.IFile;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29 import org.eclipse.jface.preference.IPreferenceStore;
31 import java.util.Hashtable;
32 import java.io.StringReader;
33 import java.text.MessageFormat;
35 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
36 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
37 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
38 import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren;
39 import net.sourceforge.phpdt.internal.compiler.parser.PHPFunctionDeclaration;
40 import net.sourceforge.phpdt.internal.compiler.parser.PHPClassDeclaration;
41 import net.sourceforge.phpdt.internal.compiler.parser.PHPVarDeclaration;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
51 public class PHPParser extends PHPParserSuperclass {
53 private static IFile fileToParse;
55 /** The current segment */
56 private static PHPSegmentWithChildren currentSegment;
58 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
59 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
60 PHPOutlineInfo outlineInfo;
61 private static int errorLevel = ERROR;
62 private static String errorMessage;
67 public void setFileToParse(IFile fileToParse) {
68 this.fileToParse = fileToParse;
71 public PHPParser(IFile fileToParse) {
72 this(new StringReader(""));
73 this.fileToParse = fileToParse;
76 public void phpParserTester(String strEval) throws CoreException, ParseException {
77 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
78 StringReader stream = new StringReader(strEval);
79 if (jj_input_stream == null) {
80 jj_input_stream = new SimpleCharStream(stream, 1, 1);
82 ReInit(new StringReader(strEval));
86 public void htmlParserTester(String strEval) throws CoreException, ParseException {
87 StringReader stream = new StringReader(strEval);
88 if (jj_input_stream == null) {
89 jj_input_stream = new SimpleCharStream(stream, 1, 1);
95 public PHPOutlineInfo parseInfo(Object parent, String s) {
96 outlineInfo = new PHPOutlineInfo(parent);
97 currentSegment = outlineInfo.getDeclarations();
98 StringReader stream = new StringReader(s);
99 if (jj_input_stream == null) {
100 jj_input_stream = new SimpleCharStream(stream, 1, 1);
105 } catch (ParseException e) {
106 processParseException(e);
112 * This method will process the parse exception.
113 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
114 * @param e the ParseException
116 private static void processParseException(final ParseException e) {
117 if (errorMessage == null) {
118 PHPeclipsePlugin.log(e);
119 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
126 * Create marker for the parse error
128 private static void setMarker(ParseException e) {
130 setMarker(fileToParse,
132 jj_input_stream.tokenBegin,
133 jj_input_stream.tokenBegin + e.currentToken.image.length(),
135 "Line " + e.currentToken.beginLine);
136 } catch (CoreException e2) {
137 PHPeclipsePlugin.log(e2);
142 * Create markers according to the external parser output
144 private static void createMarkers(String output, IFile file) throws CoreException {
145 // delete all markers
146 file.deleteMarkers(IMarker.PROBLEM, false, 0);
151 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
152 // newer php error output (tested with 4.2.3)
153 scanLine(output, file, indx, brIndx);
158 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
159 // older php error output (tested with 4.2.3)
160 scanLine(output, file, indx, brIndx);
166 private static void scanLine(String output, IFile file, int indx, int brIndx) throws CoreException {
168 StringBuffer lineNumberBuffer = new StringBuffer(10);
170 current = output.substring(indx, brIndx);
172 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
173 int onLine = current.indexOf("on line <b>");
175 lineNumberBuffer.delete(0, lineNumberBuffer.length());
176 for (int i = onLine; i < current.length(); i++) {
177 ch = current.charAt(i);
178 if ('0' <= ch && '9' >= ch) {
179 lineNumberBuffer.append(ch);
183 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
185 Hashtable attributes = new Hashtable();
187 current = current.replaceAll("\n", "");
188 current = current.replaceAll("<b>", "");
189 current = current.replaceAll("</b>", "");
190 MarkerUtilities.setMessage(attributes, current);
192 if (current.indexOf(PARSE_ERROR_STRING) != -1)
193 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
194 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
195 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
197 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
198 MarkerUtilities.setLineNumber(attributes, lineNumber);
199 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
204 public void parse(String s) throws CoreException {
205 StringReader stream = new StringReader(s);
206 if (jj_input_stream == null) {
207 jj_input_stream = new SimpleCharStream(stream, 1, 1);
212 } catch (ParseException e) {
213 processParseException(e);
218 * Call the php parse command ( php -l -f <filename> )
219 * and create markers according to the external parser output
221 public static void phpExternalParse(IFile file) {
222 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
223 String filename = file.getLocation().toString();
225 String[] arguments = { filename };
226 MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
227 String command = form.format(arguments);
229 String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
232 // parse the buffer to find the errors and warnings
233 createMarkers(parserResult, file);
234 } catch (CoreException e) {
235 PHPeclipsePlugin.log(e);
239 public void parse() throws ParseException {
244 PARSER_END(PHPParser)
248 <PHPSTART : "<?php" | "<?"> : PHPPARSING
253 <PHPEND :"?>"> : DEFAULT
277 "//" : IN_SINGLE_LINE_COMMENT
279 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
281 "/*" : IN_MULTI_LINE_COMMENT
284 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
286 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
289 <IN_SINGLE_LINE_COMMENT> TOKEN :
291 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
297 <FORMAL_COMMENT: "*/" > : PHPPARSING
300 <IN_MULTI_LINE_COMMENT>
303 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
306 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
316 | <FUNCTION : "function">
319 | <ELSEIF : "elseif">
324 /* LANGUAGE CONSTRUCT */
329 | <INCLUDE : "include">
330 | <REQUIRE : "require">
331 | <INCLUDE_ONCE : "include_once">
332 | <REQUIRE_ONCE : "require_once">
333 | <GLOBAL : "global">
334 | <STATIC : "static">
335 | <CLASSACCESS: "->">
336 | <STATICCLASSACCESS: "::">
337 | <ARRAYASSIGN: "=>">
340 /* RESERVED WORDS AND LITERALS */
347 | < CONTINUE: "continue" >
348 | < _DEFAULT: "default" >
350 | < EXTENDS: "extends" >
356 | < RETURN: "return" >
358 | < SWITCH: "switch" >
362 | < ENDWHILE : "endwhile" >
364 | <ENDFOR : "endfor" >
365 | <FOREACH : "foreach" >
374 | <OBJECT : "object">
376 | <BOOLEAN : "boolean">
378 | <DOUBLE : "double">
381 | <INTEGER : "integer">
395 <DECIMAL_LITERAL> (["l","L"])?
396 | <HEX_LITERAL> (["l","L"])?
397 | <OCTAL_LITERAL> (["l","L"])?
400 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
402 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
404 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
406 < FLOATING_POINT_LITERAL:
407 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
408 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
409 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
410 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
413 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
415 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
450 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
453 ["a"-"z"] | ["A"-"Z"]
461 "_" | ["\u007f"-"\u00ff"]
510 | <RSIGNEDSHIFT: ">>" >
511 | <RUNSIGNEDSHIFT: ">>>" >
512 | <PLUSASSIGN: "+=" >
513 | <MINUSASSIGN: "-=" >
514 | <STARASSIGN: "*=" >
515 | <SLASHASSIGN: "/=" >
521 | <LSHIFTASSIGN: "<<=" >
522 | <RSIGNEDSHIFTASSIGN: ">>=" >
523 | <BANGDOUBLEEQUAL: "!==" >
524 | <TRIPLEEQUAL: "===" >
525 | <TILDEEQUAL: "~=" >
530 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
533 /*****************************************
534 * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
535 *****************************************/
538 * Program structuring syntax follows.
552 (<PHPSTART> Php() <PHPEND>)*
554 } catch (TokenMgrError e) {
555 errorMessage = e.getMessage();
557 throw generateParseException();
567 void ClassDeclaration() :
569 PHPClassDeclaration classDeclaration;
571 int pos = jj_input_stream.bufpos;
574 <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
576 if (currentSegment != null) {
577 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
578 currentSegment.add(classDeclaration);
579 currentSegment = classDeclaration;
584 if (currentSegment != null) {
585 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
595 } catch (ParseException e) {
596 errorMessage = "'{' expected";
600 ( ClassBodyDeclaration() )*
603 } catch (ParseException e) {
604 errorMessage = "'var', 'function' or '}' expected";
610 void ClassBodyDeclaration() :
618 void FieldDeclaration() :
620 PHPVarDeclaration variableDeclaration;
623 <VAR> variableDeclaration = VariableDeclarator()
625 if (currentSegment != null) {
626 currentSegment.add(variableDeclaration);
630 variableDeclaration = VariableDeclarator()
632 if (currentSegment != null) {
633 currentSegment.add(variableDeclaration);
639 } catch (ParseException e) {
640 errorMessage = "';' expected after variable declaration";
646 PHPVarDeclaration VariableDeclarator() :
649 String varValue = null;
650 int pos = jj_input_stream.bufpos;
653 varName = VariableDeclaratorId()
657 varValue = VariableInitializer()
658 } catch (ParseException e) {
659 errorMessage = "Literal expression expected in variable initializer";
665 if (varValue == null) {
666 return new PHPVarDeclaration(currentSegment,varName,pos);
668 return new PHPVarDeclaration(currentSegment,varName,pos,varValue);
672 String VariableDeclaratorId() :
675 StringBuffer buff = new StringBuffer();
681 ( LOOKAHEAD(2) expr = VariableSuffix()
684 {return buff.toString();}
685 } catch (ParseException e) {
686 errorMessage = "'$' expected for variable identifier";
698 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
703 return token + "{" + expr + "}";
706 <DOLLAR> expr = VariableName()
710 String VariableName():
716 <LBRACE> expr = Expression() <RBRACE>
717 {return "{"+expr+"}";}
719 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
724 return token + "{" + expr + "}";
727 <DOLLAR> expr = VariableName()
730 token = <DOLLAR_ID> [expr = VariableName()]
735 return token.image + expr;
739 String VariableInitializer() :
748 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
749 {return "-" + token.image;}
751 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
752 {return "+" + token.image;}
754 expr = ArrayDeclarator()
758 {return token.image;}
761 String ArrayVariable() :
764 StringBuffer buff = new StringBuffer();
769 [<ARRAYASSIGN> expr = Expression()
770 {buff.append("=>").append(expr);}]
771 {return buff.toString();}
774 String ArrayInitializer() :
777 StringBuffer buff = new StringBuffer("(");
780 <LPAREN> [ expr = ArrayVariable()
782 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
783 {buff.append(",").append(expr);}
788 return buff.toString();
792 void MethodDeclaration() :
794 PHPFunctionDeclaration functionDeclaration;
797 <FUNCTION> functionDeclaration = MethodDeclarator()
799 if (currentSegment != null) {
800 currentSegment.add(functionDeclaration);
801 currentSegment = functionDeclaration;
806 if (currentSegment != null) {
807 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
812 PHPFunctionDeclaration MethodDeclarator() :
815 StringBuffer methodDeclaration = new StringBuffer();
816 String formalParameters;
817 int pos = jj_input_stream.bufpos;
820 [ <BIT_AND> {methodDeclaration.append("&");} ]
821 identifier = <IDENTIFIER>
822 {methodDeclaration.append(identifier);}
823 formalParameters = FormalParameters()
825 methodDeclaration.append(formalParameters);
826 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
830 String FormalParameters() :
833 final StringBuffer buff = new StringBuffer("(");
838 } catch (ParseException e) {
839 errorMessage = "Formal parameter expected after function identifier";
841 jj_consume_token(token.kind);
843 [ expr = FormalParameter()
846 <COMMA> expr = FormalParameter()
847 {buff.append(",").append(expr);}
852 } catch (ParseException e) {
853 errorMessage = "')' expected";
859 return buff.toString();
863 String FormalParameter() :
865 PHPVarDeclaration variableDeclaration;
866 StringBuffer buff = new StringBuffer();
869 [<BIT_AND> {buff.append("&");}] variableDeclaration = VariableDeclarator()
871 buff.append(variableDeclaration.toString());
872 return buff.toString();
907 String Expression() :
910 String assignOperator = null;
914 expr = PrintExpression()
917 expr = ConditionalExpression()
919 assignOperator = AssignmentOperator()
922 } catch (ParseException e) {
923 errorMessage = "expression expected";
932 return expr + assignOperator + expr2;
937 String AssignmentOperator() :
954 | <RSIGNEDSHIFTASSIGN>
968 String ConditionalExpression() :
975 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
980 return expr + "?" + expr2 + ":" + expr3;
985 String ConditionalOrExpression() :
990 StringBuffer buff = new StringBuffer();
993 expr = ConditionalAndExpression()
998 (operator = <SC_OR> | operator = <_ORL>) expr2 = ConditionalAndExpression()
1000 buff.append(operator.image);
1005 return buff.toString();
1009 String ConditionalAndExpression() :
1013 String expr2 = null;
1014 StringBuffer buff = new StringBuffer();
1017 expr = ConcatExpression()
1022 (operator = <SC_AND> | operator = <_ANDL>) expr2 = ConcatExpression()
1024 buff.append(operator.image);
1029 return buff.toString();
1033 String ConcatExpression() :
1036 String expr2 = null;
1037 StringBuffer buff = new StringBuffer();
1040 expr = InclusiveOrExpression()
1045 <DOT> expr2 = InclusiveOrExpression()
1052 return buff.toString();
1056 String InclusiveOrExpression() :
1059 String expr2 = null;
1060 StringBuffer buff = new StringBuffer();
1063 expr = ExclusiveOrExpression()
1068 <BIT_OR> expr2 = ExclusiveOrExpression()
1075 return buff.toString();
1079 String ExclusiveOrExpression() :
1082 String expr2 = null;
1083 StringBuffer buff = new StringBuffer();
1086 expr = AndExpression()
1091 <XOR> expr2 = AndExpression()
1098 return buff.toString();
1102 String AndExpression() :
1105 String expr2 = null;
1106 StringBuffer buff = new StringBuffer();
1109 expr = EqualityExpression()
1114 <BIT_AND> expr2 = EqualityExpression()
1121 return buff.toString();
1125 String EqualityExpression() :
1130 StringBuffer buff = new StringBuffer();
1133 expr = RelationalExpression()
1134 {buff.append(expr);}
1139 | operator = <BANGDOUBLEEQUAL>
1140 | operator = <TRIPLEEQUAL>
1142 expr2 = RelationalExpression()
1144 buff.append(operator.image);
1148 {return buff.toString();}
1151 String RelationalExpression() :
1156 StringBuffer buff = new StringBuffer();
1159 expr = ShiftExpression()
1160 {buff.append(expr);}
1162 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr2 = ShiftExpression()
1164 buff.append(operator.image);
1168 {return buff.toString();}
1171 String ShiftExpression() :
1176 StringBuffer buff = new StringBuffer();
1179 expr = AdditiveExpression()
1180 {buff.append(expr);}
1182 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr2 = AdditiveExpression()
1184 buff.append(operator.image);
1188 {return buff.toString();}
1191 String AdditiveExpression() :
1196 StringBuffer buff = new StringBuffer();
1199 expr = MultiplicativeExpression()
1200 {buff.append(expr);}
1202 ( operator = <PLUS> | operator = <MINUS> ) expr2 = MultiplicativeExpression()
1204 buff.append(operator.image);
1208 {return buff.toString();}
1211 String MultiplicativeExpression() :
1215 final StringBuffer buff = new StringBuffer();}
1217 expr = UnaryExpression()
1218 {buff.append(expr);}
1220 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr2 = UnaryExpression()
1222 buff.append(operator.image);
1226 {return buff.toString();}
1230 * An unary expression starting with @, & or nothing
1232 String UnaryExpression() :
1236 final StringBuffer buff = new StringBuffer();
1239 token = <BIT_AND> expr = UnaryExpressionNoPrefix()
1241 if (token == null) {
1244 return token.image + expr;
1247 (<AT> {buff.append("@");})* expr = UnaryExpressionNoPrefix()
1248 {return buff.append(expr).toString();}
1251 String UnaryExpressionNoPrefix() :
1257 ( token = <PLUS> | token = <MINUS> ) expr = UnaryExpression()
1259 return token.image + expr;
1262 expr = PreIncrementExpression()
1265 expr = PreDecrementExpression()
1268 expr = UnaryExpressionNotPlusMinus()
1273 String PreIncrementExpression() :
1278 <INCR> expr = PrimaryExpression()
1282 String PreDecrementExpression() :
1287 <DECR> expr = PrimaryExpression()
1291 String UnaryExpressionNotPlusMinus() :
1296 <BANG> expr = UnaryExpression()
1297 {return "!" + expr;}
1299 LOOKAHEAD( <LPAREN> Type() <RPAREN> )
1300 expr = CastExpression()
1303 expr = PostfixExpression()
1309 <LPAREN> expr = Expression()<RPAREN>
1310 {return "("+expr+")";}
1313 String CastExpression() :
1319 <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
1320 {return "(" + type + ")" + expr;}
1323 String PostfixExpression() :
1326 Token operator = null;
1329 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1331 if (operator == null) {
1334 return expr + operator.image;
1338 String PrimaryExpression() :
1342 final StringBuffer buff = new StringBuffer();
1346 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1347 {buff.append(identifier.image).append("::").append(expr);}
1349 expr = PrimarySuffix()
1350 {buff.append(expr);}
1352 {return buff.toString();}
1354 expr = PrimaryPrefix() {buff.append(expr);}
1355 ( expr = PrimarySuffix() {buff.append(expr);} )*
1356 {return buff.toString();}
1358 expr = ArrayDeclarator()
1359 {return "array" + expr;}
1362 String ArrayDeclarator() :
1367 <ARRAY> expr = ArrayInitializer()
1368 {return "array" + expr;}
1371 String PrimaryPrefix() :
1377 token = <IDENTIFIER>
1378 {return token.image;}
1380 <NEW> expr = ClassIdentifier()
1382 return "new " + expr;
1385 expr = VariableDeclaratorId()
1389 String ClassIdentifier():
1395 token = <IDENTIFIER>
1396 {return token.image;}
1398 expr = VariableDeclaratorId()
1402 String PrimarySuffix() :
1410 expr = VariableSuffix()
1414 String VariableSuffix() :
1419 <CLASSACCESS> expr = VariableName()
1420 {return "->" + expr;}
1422 <LBRACKET> [ expr = Expression() ]
1425 } catch (ParseException e) {
1426 errorMessage = "']' expected";
1434 return "[" + expr + "]";
1444 token = <INTEGER_LITERAL>
1445 {return token.image;}
1447 token = <FLOATING_POINT_LITERAL>
1448 {return token.image;}
1450 token = <STRING_LITERAL>
1451 {return token.image;}
1453 expr = BooleanLiteral()
1456 expr = NullLiteral()
1460 String BooleanLiteral() :
1470 String NullLiteral() :
1477 String Arguments() :
1482 <LPAREN> [ expr = ArgumentList() ]
1485 } catch (ParseException e) {
1486 errorMessage = "')' expected to close the argument list";
1494 return "(" + expr + ")";
1498 String ArgumentList() :
1501 StringBuffer buff = new StringBuffer();
1505 {buff.append(expr);}
1509 } catch (ParseException e) {
1510 errorMessage = "expression expected after a comma in argument list";
1515 buff.append(",").append("expr");
1518 {return buff.toString();}
1522 * Statement syntax follows.
1531 (<SEMICOLON> | "?>")
1532 } catch (ParseException e) {
1533 errorMessage = "';' expected";
1545 StatementExpression()
1548 } catch (ParseException e) {
1549 errorMessage = "';' expected after expression";
1574 [<AT>] IncludeStatement()
1581 void IncludeStatement() :
1584 int pos = jj_input_stream.bufpos;
1590 if (currentSegment != null) {
1591 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));
1595 (<SEMICOLON> | "?>")
1596 } catch (ParseException e) {
1597 errorMessage = "';' expected";
1605 if (currentSegment != null) {
1606 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));
1610 (<SEMICOLON> | "?>")
1611 } catch (ParseException e) {
1612 errorMessage = "';' expected";
1620 if (currentSegment != null) {
1621 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));
1625 (<SEMICOLON> | "?>")
1626 } catch (ParseException e) {
1627 errorMessage = "';' expected";
1635 if (currentSegment != null) {
1636 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));
1640 (<SEMICOLON> | "?>")
1641 } catch (ParseException e) {
1642 errorMessage = "';' expected";
1648 String PrintExpression() :
1650 StringBuffer buff = new StringBuffer("print ");
1654 <PRINT> expr = Expression()
1657 return buff.toString();
1661 void EchoStatement() :
1664 <ECHO> Expression() (<COMMA> Expression())*
1666 (<SEMICOLON> | "?>")
1667 } catch (ParseException e) {
1668 errorMessage = "';' expected after 'echo' statement";
1674 void GlobalStatement() :
1677 <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())*
1679 (<SEMICOLON> | "?>")
1680 } catch (ParseException e) {
1681 errorMessage = "';' expected";
1687 void StaticStatement() :
1690 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
1692 (<SEMICOLON> | "?>")
1693 } catch (ParseException e) {
1694 errorMessage = "';' expected";
1700 void LabeledStatement() :
1703 <IDENTIFIER> <COLON> Statement()
1711 } catch (ParseException e) {
1712 errorMessage = "'{' expected";
1716 ( BlockStatement() )*
1720 void BlockStatement() :
1730 void LocalVariableDeclaration() :
1733 VariableDeclarator() ( <COMMA> VariableDeclarator() )*
1736 void EmptyStatement() :
1742 void StatementExpression() :
1745 PreIncrementExpression()
1747 PreDecrementExpression()
1755 AssignmentOperator() Expression()
1759 void SwitchStatement() :
1762 <SWITCH> <LPAREN> Expression() <RPAREN> <LBRACE>
1763 ( SwitchLabel() ( BlockStatement() )* )*
1767 void SwitchLabel() :
1770 <CASE> Expression() <COLON>
1775 void IfStatement() :
1777 * The disambiguating algorithm of JavaCC automatically binds dangling
1778 * else's to the innermost if statement. The LOOKAHEAD specification
1779 * is to tell JavaCC that we know what we are doing.
1783 <IF> Condition("if") IfStatement0()
1786 void Condition(String keyword) :
1791 } catch (ParseException e) {
1792 errorMessage = "'(' expected after " + keyword + " keyword";
1799 } catch (ParseException e) {
1800 errorMessage = "')' expected after " + keyword + " keyword";
1806 void IfStatement0() :
1809 <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] <ENDIF>
1812 } catch (ParseException e) {
1813 errorMessage = "';' expected 'endif' keyword";
1818 Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
1821 void ElseIfStatementColon() :
1824 <ELSEIF> Condition("elseif") <COLON> (Statement())*
1827 void ElseStatement() :
1833 void ElseStatementColon() :
1836 <ELSE> <COLON> (Statement())*
1839 void ElseIfStatement() :
1842 <ELSEIF> Condition("elseif") Statement()
1845 void WhileStatement() :
1848 <WHILE> Condition("while") WhileStatement0()
1851 void WhileStatement0() :
1854 <COLON> (Statement())* <ENDWHILE>
1856 (<SEMICOLON> | "?>")
1857 } catch (ParseException e) {
1858 errorMessage = "';' expected after 'endwhile' keyword";
1866 void DoStatement() :
1869 <DO> Statement() <WHILE> Condition("while")
1871 (<SEMICOLON> | "?>")
1872 } catch (ParseException e) {
1873 errorMessage = "';' expected";
1879 void ForeachStatement() :
1882 <FOREACH> <LPAREN> Variable() <AS> Variable() [ <ARRAYASSIGN> Expression() ] <RPAREN> Statement()
1885 void ForStatement() :
1888 <FOR> <LPAREN> [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ ForUpdate() ] <RPAREN>
1892 <COLON> (Statement())* <ENDFOR>
1895 } catch (ParseException e) {
1896 errorMessage = "';' expected 'endfor' keyword";
1906 LOOKAHEAD(LocalVariableDeclaration())
1907 LocalVariableDeclaration()
1909 StatementExpressionList()
1912 void StatementExpressionList() :
1915 StatementExpression() ( <COMMA> StatementExpression() )*
1921 StatementExpressionList()
1924 void BreakStatement() :
1927 <BREAK> [ <IDENTIFIER> ] <SEMICOLON>
1930 void ContinueStatement() :
1933 <CONTINUE> [ <IDENTIFIER> ] <SEMICOLON>
1936 void ReturnStatement() :
1939 <RETURN> [ Expression() ] <SEMICOLON>