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.util.Enumeration;
33 import java.util.ArrayList;
34 import java.io.StringReader;
36 import java.text.MessageFormat;
38 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
40 import net.sourceforge.phpdt.internal.compiler.ast.*;
41 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
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 final class PHPParser extends PHPParserSuperclass {
53 /** The file that is parsed. */
54 private static IFile fileToParse;
56 /** The current segment. */
57 private static OutlineableWithChildren currentSegment;
59 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
60 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
61 static PHPOutlineInfo outlineInfo;
63 public static MethodDeclaration currentFunction;
64 private static boolean assigning;
66 /** The error level of the current ParseException. */
67 private static int errorLevel = ERROR;
68 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
69 private static String errorMessage;
71 private static int errorStart = -1;
72 private static int errorEnd = -1;
73 private static PHPDocument phpDocument;
75 * The point where html starts.
76 * It will be used by the token manager to create HTMLCode objects
78 public static int htmlStart;
81 private final static int AstStackIncrement = 100;
82 /** The stack of node. */
83 private static AstNode[] nodes;
84 /** The cursor in expression stack. */
85 private static int nodePtr;
87 public final void setFileToParse(final IFile fileToParse) {
88 this.fileToParse = fileToParse;
94 public PHPParser(final IFile fileToParse) {
95 this(new StringReader(""));
96 this.fileToParse = fileToParse;
100 * Reinitialize the parser.
102 private static final void init() {
103 nodes = new AstNode[AstStackIncrement];
109 * Add an php node on the stack.
110 * @param node the node that will be added to the stack
112 private static final void pushOnAstNodes(AstNode node) {
114 nodes[++nodePtr] = node;
115 } catch (IndexOutOfBoundsException e) {
116 int oldStackLength = nodes.length;
117 AstNode[] oldStack = nodes;
118 nodes = new AstNode[oldStackLength + AstStackIncrement];
119 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
120 nodePtr = oldStackLength;
121 nodes[nodePtr] = node;
125 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
126 currentSegment = new PHPDocument(parent);
127 outlineInfo = new PHPOutlineInfo(parent);
128 final StringReader stream = new StringReader(s);
129 if (jj_input_stream == null) {
130 jj_input_stream = new SimpleCharStream(stream, 1, 1);
136 phpDocument = new PHPDocument(null);
137 phpDocument.nodes = new AstNode[nodes.length];
138 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
139 PHPeclipsePlugin.log(1,phpDocument.toString());
140 } catch (ParseException e) {
141 processParseException(e);
147 * This method will process the parse exception.
148 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
149 * @param e the ParseException
151 private static void processParseException(final ParseException e) {
152 if (errorMessage == null) {
153 PHPeclipsePlugin.log(e);
154 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
155 errorStart = jj_input_stream.getPosition();
156 errorEnd = errorStart + 1;
163 * Create marker for the parse error
164 * @param e the ParseException
166 private static void setMarker(final ParseException e) {
168 if (errorStart == -1) {
169 setMarker(fileToParse,
171 jj_input_stream.tokenBegin,
172 jj_input_stream.tokenBegin + e.currentToken.image.length(),
174 "Line " + e.currentToken.beginLine);
176 setMarker(fileToParse,
181 "Line " + e.currentToken.beginLine);
185 } catch (CoreException e2) {
186 PHPeclipsePlugin.log(e2);
191 * Create markers according to the external parser output
193 private static void createMarkers(final String output, final IFile file) throws CoreException {
194 // delete all markers
195 file.deleteMarkers(IMarker.PROBLEM, false, 0);
200 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
201 // newer php error output (tested with 4.2.3)
202 scanLine(output, file, indx, brIndx);
207 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
208 // older php error output (tested with 4.2.3)
209 scanLine(output, file, indx, brIndx);
215 private static void scanLine(final String output,
218 final int brIndx) throws CoreException {
220 StringBuffer lineNumberBuffer = new StringBuffer(10);
222 current = output.substring(indx, brIndx);
224 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
225 int onLine = current.indexOf("on line <b>");
227 lineNumberBuffer.delete(0, lineNumberBuffer.length());
228 for (int i = onLine; i < current.length(); i++) {
229 ch = current.charAt(i);
230 if ('0' <= ch && '9' >= ch) {
231 lineNumberBuffer.append(ch);
235 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
237 Hashtable attributes = new Hashtable();
239 current = current.replaceAll("\n", "");
240 current = current.replaceAll("<b>", "");
241 current = current.replaceAll("</b>", "");
242 MarkerUtilities.setMessage(attributes, current);
244 if (current.indexOf(PARSE_ERROR_STRING) != -1)
245 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
246 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
247 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
249 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
250 MarkerUtilities.setLineNumber(attributes, lineNumber);
251 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
256 public final void parse(final String s) throws CoreException {
257 final StringReader stream = new StringReader(s);
258 if (jj_input_stream == null) {
259 jj_input_stream = new SimpleCharStream(stream, 1, 1);
265 } catch (ParseException e) {
266 processParseException(e);
271 * Call the php parse command ( php -l -f <filename> )
272 * and create markers according to the external parser output
274 public static void phpExternalParse(final IFile file) {
275 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
276 final String filename = file.getLocation().toString();
278 final String[] arguments = { filename };
279 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
280 final String command = form.format(arguments);
282 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
285 // parse the buffer to find the errors and warnings
286 createMarkers(parserResult, file);
287 } catch (CoreException e) {
288 PHPeclipsePlugin.log(e);
293 * Put a new html block in the stack.
295 public static final void createNewHTMLCode() {
296 final int currentPosition = SimpleCharStream.getPosition();
297 if (currentPosition == htmlStart) {
300 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
301 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
304 private static final void parse() throws ParseException {
309 PARSER_END(PHPParser)
313 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
314 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
315 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
320 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
323 /* Skip any character if we are not in php mode */
341 <PHPPARSING> SPECIAL_TOKEN :
343 "//" : IN_SINGLE_LINE_COMMENT
345 "#" : IN_SINGLE_LINE_COMMENT
347 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
349 "/*" : IN_MULTI_LINE_COMMENT
352 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
354 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
357 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
359 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
365 <FORMAL_COMMENT: "*/" > : PHPPARSING
368 <IN_MULTI_LINE_COMMENT>
371 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
374 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
384 | <FUNCTION : "function">
387 | <ELSEIF : "elseif">
394 /* LANGUAGE CONSTRUCT */
399 | <INCLUDE : "include">
400 | <REQUIRE : "require">
401 | <INCLUDE_ONCE : "include_once">
402 | <REQUIRE_ONCE : "require_once">
403 | <GLOBAL : "global">
404 | <STATIC : "static">
405 | <CLASSACCESS : "->">
406 | <STATICCLASSACCESS : "::">
407 | <ARRAYASSIGN : "=>">
410 /* RESERVED WORDS AND LITERALS */
416 | <CONTINUE : "continue">
417 | <_DEFAULT : "default">
419 | <EXTENDS : "extends">
424 | <RETURN : "return">
426 | <SWITCH : "switch">
431 | <ENDWHILE : "endwhile">
432 | <ENDSWITCH: "endswitch">
434 | <ENDFOR : "endfor">
435 | <FOREACH : "foreach">
443 | <OBJECT : "object">
445 | <BOOLEAN : "boolean">
447 | <DOUBLE : "double">
450 | <INTEGER : "integer">
480 | <RSIGNEDSHIFT : ">>">
481 | <RUNSIGNEDSHIFT : ">>>">
490 <DECIMAL_LITERAL> (["l","L"])?
491 | <HEX_LITERAL> (["l","L"])?
492 | <OCTAL_LITERAL> (["l","L"])?
495 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
497 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
499 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
501 <FLOATING_POINT_LITERAL:
502 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
503 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
504 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
505 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
508 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
510 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
543 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
546 ["a"-"z"] | ["A"-"Z"]
554 "_" | ["\u007f"-"\u00ff"]
579 | <EQUAL_EQUAL : "==">
584 | <BANGDOUBLEEQUAL : "!==">
585 | <TRIPLEEQUAL : "===">
592 | <PLUSASSIGN : "+=">
593 | <MINUSASSIGN : "-=">
594 | <STARASSIGN : "*=">
595 | <SLASHASSIGN : "/=">
601 | <TILDEEQUAL : "~=">
602 | <LSHIFTASSIGN : "<<=">
603 | <RSIGNEDSHIFTASSIGN : ">>=">
608 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
617 } catch (TokenMgrError e) {
618 PHPeclipsePlugin.log(e);
619 errorStart = SimpleCharStream.getPosition();
620 errorEnd = errorStart + 1;
621 errorMessage = e.getMessage();
623 throw generateParseException();
628 * A php block is a <?= expression [;]?>
629 * or <?php somephpcode ?>
630 * or <? somephpcode ?>
634 final int start = jj_input_stream.getPosition();
642 setMarker(fileToParse,
643 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
645 jj_input_stream.getPosition(),
647 "Line " + token.beginLine);
648 } catch (CoreException e) {
649 PHPeclipsePlugin.log(e);
655 } catch (ParseException e) {
656 errorMessage = "'?>' expected";
658 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
659 errorEnd = jj_input_stream.getPosition() + 1;
664 PHPEchoBlock phpEchoBlock() :
666 final Expression expr;
667 final int pos = SimpleCharStream.getPosition();
668 PHPEchoBlock echoBlock;
671 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
673 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
674 pushOnAstNodes(echoBlock);
684 ClassDeclaration ClassDeclaration() :
686 final ClassDeclaration classDeclaration;
687 final Token className;
688 Token superclassName = null;
694 {pos = jj_input_stream.getPosition();}
695 className = <IDENTIFIER>
696 } catch (ParseException e) {
697 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
699 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
700 errorEnd = jj_input_stream.getPosition() + 1;
706 superclassName = <IDENTIFIER>
707 } catch (ParseException e) {
708 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
710 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
711 errorEnd = jj_input_stream.getPosition() + 1;
716 if (superclassName == null) {
717 classDeclaration = new ClassDeclaration(currentSegment,
718 className.image.toCharArray(),
722 classDeclaration = new ClassDeclaration(currentSegment,
723 className.image.toCharArray(),
724 superclassName.image.toCharArray(),
728 currentSegment.add(classDeclaration);
729 currentSegment = classDeclaration;
731 ClassBody(classDeclaration)
732 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
733 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
734 pushOnAstNodes(classDeclaration);
735 return classDeclaration;}
738 void ClassBody(ClassDeclaration classDeclaration) :
743 } catch (ParseException e) {
744 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
746 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
747 errorEnd = SimpleCharStream.getPosition() + 1;
750 ( ClassBodyDeclaration(classDeclaration) )*
753 } catch (ParseException e) {
754 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
756 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
757 errorEnd = SimpleCharStream.getPosition() + 1;
763 * A class can contain only methods and fields.
765 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
767 MethodDeclaration method;
768 FieldDeclaration field;
771 method = MethodDeclaration() {classDeclaration.addMethod(method);}
772 | field = FieldDeclaration() {classDeclaration.addVariable(field);}
776 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
778 FieldDeclaration FieldDeclaration() :
780 VariableDeclaration variableDeclaration;
781 VariableDeclaration[] list;
782 final ArrayList arrayList = new ArrayList();
783 final int pos = SimpleCharStream.getPosition();
786 <VAR> variableDeclaration = VariableDeclarator()
787 {arrayList.add(variableDeclaration);
788 outlineInfo.addVariable(new String(variableDeclaration.name));
789 currentSegment.add(variableDeclaration);}
790 ( <COMMA> variableDeclaration = VariableDeclarator()
791 {arrayList.add(variableDeclaration);
792 outlineInfo.addVariable(new String(variableDeclaration.name));
793 currentSegment.add(variableDeclaration);}
797 } catch (ParseException e) {
798 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
800 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
801 errorEnd = SimpleCharStream.getPosition() + 1;
805 {list = new VariableDeclaration[arrayList.size()];
806 arrayList.toArray(list);
807 return new FieldDeclaration(list,
809 SimpleCharStream.getPosition());}
812 VariableDeclaration VariableDeclarator() :
814 final String varName;
815 Expression initializer = null;
816 final int pos = jj_input_stream.getPosition();
819 varName = VariableDeclaratorId()
823 initializer = VariableInitializer()
824 } catch (ParseException e) {
825 errorMessage = "Literal expression expected in variable initializer";
827 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
828 errorEnd = jj_input_stream.getPosition() + 1;
833 if (initializer == null) {
834 return new VariableDeclaration(currentSegment,
835 varName.toCharArray(),
837 jj_input_stream.getPosition());
839 return new VariableDeclaration(currentSegment,
840 varName.toCharArray(),
848 * @return the variable name (with suffix)
850 String VariableDeclaratorId() :
853 Expression expression;
854 final StringBuffer buff = new StringBuffer();
855 final int pos = SimpleCharStream.getPosition();
856 ConstantIdentifier ex;
860 expr = Variable() {buff.append(expr);}
862 {ex = new ConstantIdentifier(expr.toCharArray(),
864 SimpleCharStream.getPosition());}
865 expression = VariableSuffix(ex)
866 {buff.append(expression.toStringExpression());}
868 {return buff.toString();}
869 } catch (ParseException e) {
870 errorMessage = "'$' expected for variable identifier";
872 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
873 errorEnd = jj_input_stream.getPosition() + 1;
880 final StringBuffer buff;
881 Expression expression = null;
886 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
888 if (expression == null && !assigning) {
889 return token.image.substring(1);
891 buff = new StringBuffer(token.image);
893 buff.append(expression.toStringExpression());
895 return buff.toString();
898 <DOLLAR> expr = VariableName()
902 String VariableName():
904 final StringBuffer buff;
906 Expression expression = null;
910 <LBRACE> expression = Expression() <RBRACE>
911 {buff = new StringBuffer('{');
912 buff.append(expression.toStringExpression());
914 return buff.toString();}
916 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
918 if (expression == null) {
921 buff = new StringBuffer(token.image);
923 buff.append(expression.toStringExpression());
925 return buff.toString();
928 <DOLLAR> expr = VariableName()
930 buff = new StringBuffer('$');
932 return buff.toString();
935 token = <DOLLAR_ID> {return token.image;}
938 Expression VariableInitializer() :
940 final Expression expr;
942 final int pos = SimpleCharStream.getPosition();
948 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
949 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
951 SimpleCharStream.getPosition()),
955 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
956 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
958 SimpleCharStream.getPosition()),
962 expr = ArrayDeclarator()
966 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
969 ArrayVariableDeclaration ArrayVariable() :
971 Expression expr,expr2;
975 [<ARRAYASSIGN> expr2 = Expression()
976 {return new ArrayVariableDeclaration(expr,expr2);}
978 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
981 ArrayVariableDeclaration[] ArrayInitializer() :
983 ArrayVariableDeclaration expr;
984 final ArrayList list = new ArrayList();
987 <LPAREN> [ expr = ArrayVariable()
989 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
993 [<COMMA> {list.add(null);}]
996 ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1002 * A Method Declaration.
1003 * <b>function</b> MetodDeclarator() Block()
1005 MethodDeclaration MethodDeclaration() :
1007 final MethodDeclaration functionDeclaration;
1013 functionDeclaration = MethodDeclarator()
1014 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1015 } catch (ParseException e) {
1016 if (errorMessage != null) throw e;
1017 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1019 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1020 errorEnd = jj_input_stream.getPosition() + 1;
1024 if (currentSegment != null) {
1025 currentSegment.add(functionDeclaration);
1026 currentSegment = functionDeclaration;
1028 currentFunction = functionDeclaration;
1032 functionDeclaration.statements = block.statements;
1033 currentFunction = null;
1034 if (currentSegment != null) {
1035 currentSegment = (OutlineableWithChildren) currentSegment.getParent();
1037 return functionDeclaration;
1042 * A MethodDeclarator.
1043 * [&] IDENTIFIER(parameters ...).
1044 * @return a function description for the outline
1046 MethodDeclaration MethodDeclarator() :
1048 final Token identifier;
1049 Token reference = null;
1050 final Hashtable formalParameters;
1051 final int pos = SimpleCharStream.getPosition();
1054 [reference = <BIT_AND>] identifier = <IDENTIFIER>
1055 formalParameters = FormalParameters()
1056 {return new MethodDeclaration(currentSegment,
1057 identifier.image.toCharArray(),
1061 SimpleCharStream.getPosition());}
1065 * FormalParameters follows method identifier.
1066 * (FormalParameter())
1068 Hashtable FormalParameters() :
1070 VariableDeclaration var;
1071 final Hashtable parameters = new Hashtable();
1076 } catch (ParseException e) {
1077 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1079 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1080 errorEnd = jj_input_stream.getPosition() + 1;
1083 [ var = FormalParameter()
1084 {parameters.put(new String(var.name),var);}
1086 <COMMA> var = FormalParameter()
1087 {parameters.put(new String(var.name),var);}
1092 } catch (ParseException e) {
1093 errorMessage = "')' expected";
1095 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1096 errorEnd = jj_input_stream.getPosition() + 1;
1099 {return parameters;}
1103 * A formal parameter.
1104 * $varname[=value] (,$varname[=value])
1106 VariableDeclaration FormalParameter() :
1108 final VariableDeclaration variableDeclaration;
1112 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1114 if (token != null) {
1115 variableDeclaration.setReference(true);
1117 return variableDeclaration;}
1120 ConstantIdentifier Type() :
1123 <STRING> {pos = SimpleCharStream.getPosition();
1124 return new ConstantIdentifier(Types.STRING,
1126 | <BOOL> {pos = SimpleCharStream.getPosition();
1127 return new ConstantIdentifier(Types.BOOL,
1129 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1130 return new ConstantIdentifier(Types.BOOLEAN,
1132 | <REAL> {pos = SimpleCharStream.getPosition();
1133 return new ConstantIdentifier(Types.REAL,
1135 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1136 return new ConstantIdentifier(Types.DOUBLE,
1138 | <FLOAT> {pos = SimpleCharStream.getPosition();
1139 return new ConstantIdentifier(Types.FLOAT,
1141 | <INT> {pos = SimpleCharStream.getPosition();
1142 return new ConstantIdentifier(Types.INT,
1144 | <INTEGER> {pos = SimpleCharStream.getPosition();
1145 return new ConstantIdentifier(Types.INTEGER,
1147 | <OBJECT> {pos = SimpleCharStream.getPosition();
1148 return new ConstantIdentifier(Types.OBJECT,
1152 Expression Expression() :
1154 final Expression expr;
1157 expr = PrintExpression() {return expr;}
1158 | expr = ListExpression() {return expr;}
1159 | LOOKAHEAD(varAssignation())
1160 expr = varAssignation() {return expr;}
1161 | expr = ConditionalExpression() {return expr;}
1165 * A Variable assignation.
1166 * varName (an assign operator) any expression
1168 VarAssignation varAssignation() :
1171 final Expression expression;
1172 final int assignOperator;
1173 final int pos = SimpleCharStream.getPosition();
1176 varName = VariableDeclaratorId()
1177 assignOperator = AssignmentOperator()
1179 expression = Expression()
1180 } catch (ParseException e) {
1181 if (errorMessage != null) {
1184 errorMessage = "expression expected";
1186 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1187 errorEnd = jj_input_stream.getPosition() + 1;
1190 {return new VarAssignation(varName.toCharArray(),
1194 SimpleCharStream.getPosition());}
1197 int AssignmentOperator() :
1200 <ASSIGN> {return VarAssignation.EQUAL;}
1201 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1202 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1203 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1204 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1205 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1206 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1207 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1208 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1209 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1210 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1211 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1212 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1215 Expression ConditionalExpression() :
1217 final Expression expr;
1218 Expression expr2 = null;
1219 Expression expr3 = null;
1222 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1224 if (expr3 == null) {
1227 return new ConditionalExpression(expr,expr2,expr3);
1231 Expression ConditionalOrExpression() :
1233 Expression expr,expr2;
1237 expr = ConditionalAndExpression()
1240 <OR_OR> {operator = OperatorIds.OR_OR;}
1241 | <_ORL> {operator = OperatorIds.ORL;}
1242 ) expr2 = ConditionalAndExpression()
1244 expr = new BinaryExpression(expr,expr2,operator);
1250 Expression ConditionalAndExpression() :
1252 Expression expr,expr2;
1256 expr = ConcatExpression()
1258 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1259 | <_ANDL> {operator = OperatorIds.ANDL;})
1260 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1265 Expression ConcatExpression() :
1267 Expression expr,expr2;
1270 expr = InclusiveOrExpression()
1272 <DOT> expr2 = InclusiveOrExpression()
1273 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1278 Expression InclusiveOrExpression() :
1280 Expression expr,expr2;
1283 expr = ExclusiveOrExpression()
1284 (<BIT_OR> expr2 = ExclusiveOrExpression()
1285 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1290 Expression ExclusiveOrExpression() :
1292 Expression expr,expr2;
1295 expr = AndExpression()
1297 <XOR> expr2 = AndExpression()
1298 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1303 Expression AndExpression() :
1305 Expression expr,expr2;
1308 expr = EqualityExpression()
1310 <BIT_AND> expr2 = EqualityExpression()
1311 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1316 Expression EqualityExpression() :
1318 Expression expr,expr2;
1322 expr = RelationalExpression()
1324 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1325 | <DIF> {operator = OperatorIds.DIF;}
1326 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1327 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1328 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1331 expr2 = RelationalExpression()
1332 } catch (ParseException e) {
1333 if (errorMessage != null) {
1336 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1338 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1339 errorEnd = jj_input_stream.getPosition() + 1;
1343 expr = new BinaryExpression(expr,expr2,operator);
1349 Expression RelationalExpression() :
1351 Expression expr,expr2;
1355 expr = ShiftExpression()
1357 ( <LT> {operator = OperatorIds.LESS;}
1358 | <GT> {operator = OperatorIds.GREATER;}
1359 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1360 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1361 expr2 = ShiftExpression()
1362 {expr = new BinaryExpression(expr,expr2,operator);}
1367 Expression ShiftExpression() :
1369 Expression expr,expr2;
1373 expr = AdditiveExpression()
1375 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1376 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1377 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1378 expr2 = AdditiveExpression()
1379 {expr = new BinaryExpression(expr,expr2,operator);}
1384 Expression AdditiveExpression() :
1386 Expression expr,expr2;
1390 expr = MultiplicativeExpression()
1392 ( <PLUS> {operator = OperatorIds.PLUS;}
1393 | <MINUS> {operator = OperatorIds.MINUS;} )
1394 expr2 = MultiplicativeExpression()
1395 {expr = new BinaryExpression(expr,expr2,operator);}
1400 Expression MultiplicativeExpression() :
1402 Expression expr,expr2;
1407 expr = UnaryExpression()
1408 } catch (ParseException e) {
1409 if (errorMessage != null) throw e;
1410 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1412 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1413 errorEnd = jj_input_stream.getPosition() + 1;
1417 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1418 | <SLASH> {operator = OperatorIds.DIVIDE;}
1419 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1420 expr2 = UnaryExpression()
1421 {expr = new BinaryExpression(expr,expr2,operator);}
1427 * An unary expression starting with @, & or nothing
1429 Expression UnaryExpression() :
1432 final int pos = SimpleCharStream.getPosition();
1435 <BIT_AND> expr = UnaryExpressionNoPrefix()
1436 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1438 expr = AtUnaryExpression() {return expr;}
1441 Expression AtUnaryExpression() :
1444 final int pos = SimpleCharStream.getPosition();
1448 expr = AtUnaryExpression()
1449 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1451 expr = UnaryExpressionNoPrefix()
1456 Expression UnaryExpressionNoPrefix() :
1460 final int pos = SimpleCharStream.getPosition();
1463 ( <PLUS> {operator = OperatorIds.PLUS;}
1464 | <MINUS> {operator = OperatorIds.MINUS;})
1465 expr = UnaryExpression()
1466 {return new PrefixedUnaryExpression(expr,operator,pos);}
1468 expr = PreIncDecExpression()
1471 expr = UnaryExpressionNotPlusMinus()
1476 Expression PreIncDecExpression() :
1478 final Expression expr;
1480 final int pos = SimpleCharStream.getPosition();
1483 ( <INCR> {operator = OperatorIds.PLUS_PLUS;}
1484 | <DECR> {operator = OperatorIds.MINUS_MINUS;})
1485 expr = PrimaryExpression()
1486 {return new PrefixedUnaryExpression(expr,operator,pos);}
1489 Expression UnaryExpressionNotPlusMinus() :
1492 final int pos = SimpleCharStream.getPosition();
1495 <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1496 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1497 expr = CastExpression() {return expr;}
1498 | expr = PostfixExpression() {return expr;}
1499 | expr = Literal() {return expr;}
1500 | <LPAREN> expr = Expression()
1503 } catch (ParseException e) {
1504 errorMessage = "')' expected";
1506 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1507 errorEnd = jj_input_stream.getPosition() + 1;
1513 CastExpression CastExpression() :
1515 final ConstantIdentifier type;
1516 final Expression expr;
1517 final int pos = SimpleCharStream.getPosition();
1522 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1523 <RPAREN> expr = UnaryExpression()
1524 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1527 Expression PostfixExpression() :
1531 final int pos = SimpleCharStream.getPosition();
1534 expr = PrimaryExpression()
1535 [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
1536 | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
1538 if (operator == -1) {
1541 return new PostfixedUnaryExpression(expr,operator,pos);
1545 Expression PrimaryExpression() :
1547 final Token identifier;
1549 final int pos = SimpleCharStream.getPosition();
1553 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1554 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1556 SimpleCharStream.getPosition()),
1558 ClassAccess.STATIC);}
1559 (expr = PrimarySuffix(expr))*
1562 expr = PrimaryPrefix()
1563 (expr = PrimarySuffix(expr))*
1566 expr = ArrayDeclarator()
1570 ArrayInitializer ArrayDeclarator() :
1572 final ArrayVariableDeclaration[] vars;
1573 final int pos = SimpleCharStream.getPosition();
1576 <ARRAY> vars = ArrayInitializer()
1577 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1580 Expression PrimaryPrefix() :
1582 final Expression expr;
1585 final int pos = SimpleCharStream.getPosition();
1588 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1590 SimpleCharStream.getPosition());}
1591 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1594 | var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
1596 SimpleCharStream.getPosition());}
1599 PrefixedUnaryExpression classInstantiation() :
1602 final StringBuffer buff;
1603 final int pos = SimpleCharStream.getPosition();
1606 <NEW> expr = ClassIdentifier()
1608 {buff = new StringBuffer(expr.toStringExpression());}
1609 expr = PrimaryExpression()
1610 {buff.append(expr.toStringExpression());
1611 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1613 SimpleCharStream.getPosition());}
1615 {return new PrefixedUnaryExpression(expr,
1620 ConstantIdentifier ClassIdentifier():
1624 final int pos = SimpleCharStream.getPosition();
1627 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1629 SimpleCharStream.getPosition());}
1630 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1632 SimpleCharStream.getPosition());}
1635 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1637 final AbstractSuffixExpression expr;
1640 expr = Arguments(prefix) {return expr;}
1641 | expr = VariableSuffix(prefix) {return expr;}
1644 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1647 final int pos = SimpleCharStream.getPosition();
1648 Expression expression = null;
1653 expr = VariableName()
1654 } catch (ParseException e) {
1655 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1657 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1658 errorEnd = jj_input_stream.getPosition() + 1;
1661 {return new ClassAccess(prefix,
1662 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1663 ClassAccess.NORMAL);}
1665 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1668 } catch (ParseException e) {
1669 errorMessage = "']' expected";
1671 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1672 errorEnd = jj_input_stream.getPosition() + 1;
1675 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1684 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1685 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1686 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1687 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1688 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1689 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1690 | <TRUE> {pos = SimpleCharStream.getPosition();
1691 return new TrueLiteral(pos-4,pos);}
1692 | <FALSE> {pos = SimpleCharStream.getPosition();
1693 return new FalseLiteral(pos-4,pos);}
1694 | <NULL> {pos = SimpleCharStream.getPosition();
1695 return new NullLiteral(pos-4,pos);}
1698 FunctionCall Arguments(Expression func) :
1700 Expression[] args = null;
1703 <LPAREN> [ args = ArgumentList() ]
1706 } catch (ParseException e) {
1707 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1709 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1710 errorEnd = jj_input_stream.getPosition() + 1;
1713 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1717 * An argument list is a list of arguments separated by comma :
1718 * argumentDeclaration() (, argumentDeclaration)*
1719 * @return an array of arguments
1721 Expression[] ArgumentList() :
1724 final ArrayList list = new ArrayList();
1733 } catch (ParseException e) {
1734 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1736 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1737 errorEnd = jj_input_stream.getPosition() + 1;
1742 Expression[] arguments = new Expression[list.size()];
1743 list.toArray(arguments);
1748 * A Statement without break.
1750 Statement StatementNoBreak() :
1752 final Statement statement;
1757 statement = Expression()
1760 } catch (ParseException e) {
1761 if (e.currentToken.next.kind != 4) {
1762 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1764 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1765 errorEnd = jj_input_stream.getPosition() + 1;
1771 statement = LabeledStatement() {return statement;}
1772 | statement = Block() {return statement;}
1773 | statement = EmptyStatement() {return statement;}
1774 | statement = StatementExpression()
1777 } catch (ParseException e) {
1778 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1780 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1781 errorEnd = jj_input_stream.getPosition() + 1;
1785 | statement = SwitchStatement() {return statement;}
1786 | statement = IfStatement() {return statement;}
1787 | statement = WhileStatement() {return statement;}
1788 | statement = DoStatement() {return statement;}
1789 | statement = ForStatement() {return statement;}
1790 | statement = ForeachStatement() {return statement;}
1791 | statement = ContinueStatement() {return statement;}
1792 | statement = ReturnStatement() {return statement;}
1793 | statement = EchoStatement() {return statement;}
1794 | [token=<AT>] statement = IncludeStatement()
1795 {if (token != null) {
1796 ((InclusionStatement)statement).silent = true;
1799 | statement = StaticStatement() {return statement;}
1800 | statement = GlobalStatement() {return statement;}
1804 * A Normal statement.
1806 Statement Statement() :
1808 final Statement statement;
1811 statement = StatementNoBreak() {return statement;}
1812 | statement = BreakStatement() {return statement;}
1816 * An html block inside a php syntax.
1818 HTMLBlock htmlBlock() :
1820 final int startIndex = nodePtr;
1821 AstNode[] blockNodes;
1825 <PHPEND> (phpEchoBlock())*
1827 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1828 } catch (ParseException e) {
1829 errorMessage = "End of file unexpected, '<?php' expected";
1831 errorStart = jj_input_stream.getPosition();
1832 errorEnd = jj_input_stream.getPosition();
1836 nbNodes = nodePtr-startIndex - 1;
1837 blockNodes = new AstNode[nbNodes];
1838 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1839 return new HTMLBlock(nodes);}
1843 * An include statement. It's "include" an expression;
1845 InclusionStatement IncludeStatement() :
1847 final Expression expr;
1849 final int pos = jj_input_stream.getPosition();
1850 final InclusionStatement inclusionStatement;
1853 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1854 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1855 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1856 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1859 } catch (ParseException e) {
1860 if (errorMessage != null) {
1863 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1865 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1866 errorEnd = jj_input_stream.getPosition() + 1;
1869 {inclusionStatement = new InclusionStatement(currentSegment,
1873 currentSegment.add(inclusionStatement);
1877 } catch (ParseException e) {
1878 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1880 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1881 errorEnd = jj_input_stream.getPosition() + 1;
1884 {return inclusionStatement;}
1887 PrintExpression PrintExpression() :
1889 final Expression expr;
1890 final int pos = SimpleCharStream.getPosition();
1893 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1896 ListExpression ListExpression() :
1899 Expression expression = null;
1900 ArrayList list = new ArrayList();
1901 final int pos = SimpleCharStream.getPosition();
1907 } catch (ParseException e) {
1908 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1910 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1911 errorEnd = jj_input_stream.getPosition() + 1;
1915 expr = VariableDeclaratorId()
1918 {if (expr == null) list.add(null);}
1922 } catch (ParseException e) {
1923 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1925 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1926 errorEnd = jj_input_stream.getPosition() + 1;
1929 expr = VariableDeclaratorId()
1934 } catch (ParseException e) {
1935 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1937 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1938 errorEnd = jj_input_stream.getPosition() + 1;
1941 [ <ASSIGN> expression = Expression()
1943 String[] strings = new String[list.size()];
1944 list.toArray(strings);
1945 return new ListExpression(strings,
1948 SimpleCharStream.getPosition());}
1951 String[] strings = new String[list.size()];
1952 list.toArray(strings);
1953 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
1957 * An echo statement.
1958 * echo anyexpression (, otherexpression)*
1960 EchoStatement EchoStatement() :
1962 final ArrayList expressions = new ArrayList();
1964 final int pos = SimpleCharStream.getPosition();
1967 <ECHO> expr = Expression()
1968 {expressions.add(expr);}
1970 <COMMA> expr = Expression()
1971 {expressions.add(expr);}
1976 Expression[] exprs = new Expression[expressions.size()];
1977 expressions.toArray(exprs);
1978 return new EchoStatement(exprs,pos);}
1979 } catch (ParseException e) {
1980 if (e.currentToken.next.kind != 4) {
1981 errorMessage = "';' expected after 'echo' statement";
1983 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1984 errorEnd = jj_input_stream.getPosition() + 1;
1990 GlobalStatement GlobalStatement() :
1992 final int pos = jj_input_stream.getPosition();
1994 ArrayList vars = new ArrayList();
1995 GlobalStatement global;
1999 expr = VariableDeclaratorId()
2002 expr = VariableDeclaratorId()
2008 String[] strings = new String[vars.size()];
2009 vars.toArray(strings);
2010 global = new GlobalStatement(currentSegment,
2013 SimpleCharStream.getPosition());
2014 currentSegment.add(global);
2016 } catch (ParseException e) {
2017 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2019 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2020 errorEnd = jj_input_stream.getPosition() + 1;
2025 StaticStatement StaticStatement() :
2027 final int pos = SimpleCharStream.getPosition();
2028 final ArrayList vars = new ArrayList();
2029 VariableDeclaration expr;
2032 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2033 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2037 String[] strings = new String[vars.size()];
2038 vars.toArray(strings);
2039 return new StaticStatement(strings,
2041 SimpleCharStream.getPosition());}
2042 } catch (ParseException e) {
2043 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2045 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2046 errorEnd = jj_input_stream.getPosition() + 1;
2051 LabeledStatement LabeledStatement() :
2053 final int pos = SimpleCharStream.getPosition();
2055 final Statement statement;
2058 label = <IDENTIFIER> <COLON> statement = Statement()
2059 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2071 final int pos = SimpleCharStream.getPosition();
2072 final ArrayList list = new ArrayList();
2073 Statement statement;
2078 } catch (ParseException e) {
2079 errorMessage = "'{' expected";
2081 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2082 errorEnd = jj_input_stream.getPosition() + 1;
2085 ( statement = BlockStatement() {list.add(statement);}
2086 | statement = htmlBlock() {list.add(statement);})*
2089 } catch (ParseException e) {
2090 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2092 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2093 errorEnd = jj_input_stream.getPosition() + 1;
2097 Statement[] statements = new Statement[list.size()];
2098 list.toArray(statements);
2099 return new Block(statements,pos,SimpleCharStream.getPosition());}
2102 Statement BlockStatement() :
2104 final Statement statement;
2107 statement = Statement() {return statement;}
2108 | statement = ClassDeclaration() {return statement;}
2109 | statement = MethodDeclaration() {return statement;}
2113 * A Block statement that will not contain any 'break'
2115 Statement BlockStatementNoBreak() :
2117 final Statement statement;
2120 statement = StatementNoBreak() {return statement;}
2121 | statement = ClassDeclaration() {return statement;}
2122 | statement = MethodDeclaration() {return statement;}
2125 VariableDeclaration[] LocalVariableDeclaration() :
2127 final ArrayList list = new ArrayList();
2128 VariableDeclaration var;
2131 var = LocalVariableDeclarator()
2133 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2135 VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2140 VariableDeclaration LocalVariableDeclarator() :
2142 final String varName;
2143 Expression initializer = null;
2144 final int pos = SimpleCharStream.getPosition();
2147 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2149 if (initializer == null) {
2150 return new VariableDeclaration(currentSegment,
2151 varName.toCharArray(),
2153 jj_input_stream.getPosition());
2155 return new VariableDeclaration(currentSegment,
2156 varName.toCharArray(),
2162 EmptyStatement EmptyStatement() :
2168 {pos = SimpleCharStream.getPosition();
2169 return new EmptyStatement(pos-1,pos);}
2172 Statement StatementExpression() :
2174 Expression expr,expr2;
2178 expr = PreIncDecExpression() {return expr;}
2180 expr = PrimaryExpression()
2181 [ <INCR> {return new PostfixedUnaryExpression(expr,
2182 OperatorIds.PLUS_PLUS,
2183 SimpleCharStream.getPosition());}
2184 | <DECR> {return new PostfixedUnaryExpression(expr,
2185 OperatorIds.MINUS_MINUS,
2186 SimpleCharStream.getPosition());}
2187 | operator = AssignmentOperator() expr2 = Expression()
2188 {return new BinaryExpression(expr,expr2,operator);}
2193 SwitchStatement SwitchStatement() :
2195 final Expression variable;
2196 final AbstractCase[] cases;
2197 final int pos = SimpleCharStream.getPosition();
2203 } catch (ParseException e) {
2204 errorMessage = "'(' expected after 'switch'";
2206 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2207 errorEnd = jj_input_stream.getPosition() + 1;
2211 variable = Expression()
2212 } catch (ParseException e) {
2213 if (errorMessage != null) {
2216 errorMessage = "expression expected";
2218 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2219 errorEnd = jj_input_stream.getPosition() + 1;
2224 } catch (ParseException e) {
2225 errorMessage = "')' expected";
2227 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2228 errorEnd = jj_input_stream.getPosition() + 1;
2231 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2232 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2235 AbstractCase[] switchStatementBrace() :
2238 final ArrayList cases = new ArrayList();
2242 ( cas = switchLabel0() {cases.add(cas);})*
2246 AbstractCase[] abcase = new AbstractCase[cases.size()];
2247 cases.toArray(abcase);
2249 } catch (ParseException e) {
2250 errorMessage = "'}' expected";
2252 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2253 errorEnd = jj_input_stream.getPosition() + 1;
2258 * A Switch statement with : ... endswitch;
2259 * @param start the begin offset of the switch
2260 * @param end the end offset of the switch
2262 AbstractCase[] switchStatementColon(final int start, final int end) :
2265 final ArrayList cases = new ArrayList();
2270 setMarker(fileToParse,
2271 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2275 "Line " + token.beginLine);
2276 } catch (CoreException e) {
2277 PHPeclipsePlugin.log(e);
2279 ( cas = switchLabel0() {cases.add(cas);})*
2282 } catch (ParseException e) {
2283 errorMessage = "'endswitch' expected";
2285 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2286 errorEnd = jj_input_stream.getPosition() + 1;
2292 AbstractCase[] abcase = new AbstractCase[cases.size()];
2293 cases.toArray(abcase);
2295 } catch (ParseException e) {
2296 errorMessage = "';' expected after 'endswitch' keyword";
2298 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2299 errorEnd = jj_input_stream.getPosition() + 1;
2304 AbstractCase switchLabel0() :
2306 final Expression expr;
2307 Statement statement;
2308 final ArrayList stmts = new ArrayList();
2309 final int pos = SimpleCharStream.getPosition();
2312 expr = SwitchLabel()
2313 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2314 | statement = htmlBlock() {stmts.add(statement);})*
2315 [ statement = BreakStatement() {stmts.add(statement);}]
2317 Statement[] stmtsArray = new Statement[stmts.size()];
2318 stmts.toArray(stmtsArray);
2319 if (expr == null) {//it's a default
2320 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2322 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2327 * case Expression() :
2329 * @return the if it was a case and null if not
2331 Expression SwitchLabel() :
2333 final Expression expr;
2339 } catch (ParseException e) {
2340 if (errorMessage != null) throw e;
2341 errorMessage = "expression expected after 'case' keyword";
2343 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2344 errorEnd = jj_input_stream.getPosition() + 1;
2350 } catch (ParseException e) {
2351 errorMessage = "':' expected after case expression";
2353 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2354 errorEnd = jj_input_stream.getPosition() + 1;
2362 } catch (ParseException e) {
2363 errorMessage = "':' expected after 'default' keyword";
2365 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2366 errorEnd = jj_input_stream.getPosition() + 1;
2371 Break BreakStatement() :
2373 Expression expression = null;
2374 final int start = SimpleCharStream.getPosition();
2377 <BREAK> [ expression = Expression() ]
2380 } catch (ParseException e) {
2381 errorMessage = "';' expected after 'break' keyword";
2383 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2384 errorEnd = jj_input_stream.getPosition() + 1;
2387 {return new Break(expression, start, SimpleCharStream.getPosition());}
2390 IfStatement IfStatement() :
2392 final int pos = jj_input_stream.getPosition();
2393 Expression condition;
2394 IfStatement ifStatement;
2397 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2398 {return ifStatement;}
2402 Expression Condition(final String keyword) :
2404 final Expression condition;
2409 } catch (ParseException e) {
2410 errorMessage = "'(' expected after " + keyword + " keyword";
2412 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
2413 errorEnd = errorStart +1;
2414 processParseException(e);
2416 condition = Expression()
2420 } catch (ParseException e) {
2421 errorMessage = "')' expected after " + keyword + " keyword";
2423 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2424 errorEnd = jj_input_stream.getPosition() + 1;
2429 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2431 Statement statement;
2433 final Statement[] statementsArray;
2434 ElseIf elseifStatement;
2435 Else elseStatement = null;
2437 final ArrayList elseIfList = new ArrayList();
2439 int pos = SimpleCharStream.getPosition();
2444 {stmts = new ArrayList();}
2445 ( statement = Statement() {stmts.add(statement);}
2446 | statement = htmlBlock() {stmts.add(statement);})*
2447 {endStatements = SimpleCharStream.getPosition();}
2448 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2449 [elseStatement = ElseStatementColon()]
2452 setMarker(fileToParse,
2453 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2457 "Line " + token.beginLine);
2458 } catch (CoreException e) {
2459 PHPeclipsePlugin.log(e);
2463 } catch (ParseException e) {
2464 errorMessage = "'endif' expected";
2466 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2467 errorEnd = jj_input_stream.getPosition() + 1;
2472 } catch (ParseException e) {
2473 errorMessage = "';' expected after 'endif' keyword";
2475 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2476 errorEnd = jj_input_stream.getPosition() + 1;
2480 elseIfs = new ElseIf[elseIfList.size()];
2481 elseIfList.toArray(elseIfs);
2482 if (stmts.size() == 1) {
2483 return new IfStatement(condition,
2484 (Statement) stmts.get(0),
2488 SimpleCharStream.getPosition());
2490 statementsArray = new Statement[stmts.size()];
2491 stmts.toArray(statementsArray);
2492 return new IfStatement(condition,
2493 new Block(statementsArray,pos,endStatements),
2497 SimpleCharStream.getPosition());
2502 (stmt = Statement() | stmt = htmlBlock())
2503 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2507 {pos = SimpleCharStream.getPosition();}
2508 statement = Statement()
2509 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2510 } catch (ParseException e) {
2511 if (errorMessage != null) {
2514 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2516 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2517 errorEnd = jj_input_stream.getPosition() + 1;
2522 elseIfs = new ElseIf[elseIfList.size()];
2523 elseIfList.toArray(elseIfs);
2524 return new IfStatement(condition,
2529 SimpleCharStream.getPosition());}
2532 ElseIf ElseIfStatementColon() :
2534 Expression condition;
2535 Statement statement;
2536 final ArrayList list = new ArrayList();
2537 final int pos = SimpleCharStream.getPosition();
2540 <ELSEIF> condition = Condition("elseif")
2541 <COLON> ( statement = Statement() {list.add(statement);}
2542 | statement = htmlBlock() {list.add(statement);})*
2544 Statement[] stmtsArray = new Statement[list.size()];
2545 list.toArray(stmtsArray);
2546 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2549 Else ElseStatementColon() :
2551 Statement statement;
2552 final ArrayList list = new ArrayList();
2553 final int pos = SimpleCharStream.getPosition();
2556 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2557 | statement = htmlBlock() {list.add(statement);})*
2559 Statement[] stmtsArray = new Statement[list.size()];
2560 list.toArray(stmtsArray);
2561 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2564 ElseIf ElseIfStatement() :
2566 Expression condition;
2567 Statement statement;
2568 final ArrayList list = new ArrayList();
2569 final int pos = SimpleCharStream.getPosition();
2572 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2574 Statement[] stmtsArray = new Statement[list.size()];
2575 list.toArray(stmtsArray);
2576 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2579 WhileStatement WhileStatement() :
2581 final Expression condition;
2582 final Statement action;
2583 final int pos = SimpleCharStream.getPosition();
2587 condition = Condition("while")
2588 action = WhileStatement0(pos,pos + 5)
2589 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2592 Statement WhileStatement0(final int start, final int end) :
2594 Statement statement;
2595 final ArrayList stmts = new ArrayList();
2596 final int pos = SimpleCharStream.getPosition();
2599 <COLON> (statement = Statement() {stmts.add(statement);})*
2601 setMarker(fileToParse,
2602 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2606 "Line " + token.beginLine);
2607 } catch (CoreException e) {
2608 PHPeclipsePlugin.log(e);
2612 } catch (ParseException e) {
2613 errorMessage = "'endwhile' expected";
2615 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2616 errorEnd = jj_input_stream.getPosition() + 1;
2622 Statement[] stmtsArray = new Statement[stmts.size()];
2623 stmts.toArray(stmtsArray);
2624 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2625 } catch (ParseException e) {
2626 errorMessage = "';' expected after 'endwhile' keyword";
2628 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2629 errorEnd = jj_input_stream.getPosition() + 1;
2633 statement = Statement()
2637 DoStatement DoStatement() :
2639 final Statement action;
2640 final Expression condition;
2641 final int pos = SimpleCharStream.getPosition();
2644 <DO> action = Statement() <WHILE> condition = Condition("while")
2647 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2648 } catch (ParseException e) {
2649 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2651 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2652 errorEnd = jj_input_stream.getPosition() + 1;
2657 ForeachStatement ForeachStatement() :
2659 Statement statement;
2660 Expression expression;
2661 final int pos = SimpleCharStream.getPosition();
2662 ArrayVariableDeclaration variable;
2668 } catch (ParseException e) {
2669 errorMessage = "'(' expected after 'foreach' keyword";
2671 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2672 errorEnd = jj_input_stream.getPosition() + 1;
2676 expression = Expression()
2677 } catch (ParseException e) {
2678 errorMessage = "variable expected";
2680 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2681 errorEnd = jj_input_stream.getPosition() + 1;
2686 } catch (ParseException e) {
2687 errorMessage = "'as' expected";
2689 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2690 errorEnd = jj_input_stream.getPosition() + 1;
2694 variable = ArrayVariable()
2695 } catch (ParseException e) {
2696 errorMessage = "variable expected";
2698 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2699 errorEnd = jj_input_stream.getPosition() + 1;
2704 } catch (ParseException e) {
2705 errorMessage = "')' expected after 'foreach' keyword";
2707 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2708 errorEnd = jj_input_stream.getPosition() + 1;
2712 statement = Statement()
2713 } catch (ParseException e) {
2714 if (errorMessage != null) throw e;
2715 errorMessage = "statement expected";
2717 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2718 errorEnd = jj_input_stream.getPosition() + 1;
2721 {return new ForeachStatement(expression,
2725 SimpleCharStream.getPosition());}
2729 ForStatement ForStatement() :
2732 final int pos = SimpleCharStream.getPosition();
2733 Statement[] initializations = null;
2734 Expression condition = null;
2735 Statement[] increments = null;
2737 final ArrayList list = new ArrayList();
2738 final int startBlock, endBlock;
2744 } catch (ParseException e) {
2745 errorMessage = "'(' expected after 'for' keyword";
2747 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2748 errorEnd = jj_input_stream.getPosition() + 1;
2751 [ initializations = ForInit() ] <SEMICOLON>
2752 [ condition = Expression() ] <SEMICOLON>
2753 [ increments = StatementExpressionList() ] <RPAREN>
2755 action = Statement()
2756 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2759 {startBlock = SimpleCharStream.getPosition();}
2760 (action = Statement() {list.add(action);})*
2763 setMarker(fileToParse,
2764 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2766 pos+token.image.length(),
2768 "Line " + token.beginLine);
2769 } catch (CoreException e) {
2770 PHPeclipsePlugin.log(e);
2773 {endBlock = SimpleCharStream.getPosition();}
2776 } catch (ParseException e) {
2777 errorMessage = "'endfor' expected";
2779 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2780 errorEnd = jj_input_stream.getPosition() + 1;
2786 Statement[] stmtsArray = new Statement[list.size()];
2787 list.toArray(stmtsArray);
2788 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2789 } catch (ParseException e) {
2790 errorMessage = "';' expected after 'endfor' keyword";
2792 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2793 errorEnd = jj_input_stream.getPosition() + 1;
2799 Statement[] ForInit() :
2801 Statement[] statements;
2804 LOOKAHEAD(LocalVariableDeclaration())
2805 statements = LocalVariableDeclaration()
2806 {return statements;}
2808 statements = StatementExpressionList()
2809 {return statements;}
2812 Statement[] StatementExpressionList() :
2814 final ArrayList list = new ArrayList();
2818 expr = StatementExpression() {list.add(expr);}
2819 (<COMMA> StatementExpression() {list.add(expr);})*
2821 Statement[] stmtsArray = new Statement[list.size()];
2822 list.toArray(stmtsArray);
2826 Continue ContinueStatement() :
2828 Expression expr = null;
2829 final int pos = SimpleCharStream.getPosition();
2832 <CONTINUE> [ expr = Expression() ]
2835 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2836 } catch (ParseException e) {
2837 errorMessage = "';' expected after 'continue' statement";
2839 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2840 errorEnd = jj_input_stream.getPosition() + 1;
2845 ReturnStatement ReturnStatement() :
2847 Expression expr = null;
2848 final int pos = SimpleCharStream.getPosition();
2851 <RETURN> [ expr = Expression() ]
2854 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2855 } catch (ParseException e) {
2856 errorMessage = "';' expected after 'return' statement";
2858 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2859 errorEnd = jj_input_stream.getPosition() + 1;