{
<VAR> variableDeclaration = VariableDeclaratorNoSuffix()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));}
+ outlineInfo.addVariable(new String(variableDeclaration.name()));}
(
<COMMA> variableDeclaration = VariableDeclaratorNoSuffix()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));}
+ outlineInfo.addVariable(new String(variableDeclaration.name()));}
)*
try {
<SEMICOLON>
{
if (initializer == null) {
return new VariableDeclaration(currentSegment,
- varName.image.substring(1).toCharArray(),
+ new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
pos,
SimpleCharStream.getPosition());
}
return new VariableDeclaration(currentSegment,
- varName.image.substring(1).toCharArray(),
+ new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
initializer,
VariableDeclaration.EQUAL,
pos);
{
if (initializer == null) {
return new VariableDeclaration(currentSegment,
- varName.toCharArray(),
+ new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
pos,
SimpleCharStream.getPosition());
}
return new VariableDeclaration(currentSegment,
- varName.toCharArray(),
- initializer,
- VariableDeclaration.EQUAL,
- pos);
+ new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
+ initializer,
+ VariableDeclaration.EQUAL,
+ pos);
}
}
}
[
var = FormalParameter()
- {parameters.put(new String(var.name),var);}
+ {parameters.put(new String(var.name()),var);}
(
<COMMA> var = FormalParameter()
- {parameters.put(new String(var.name),var);}
+ {parameters.put(new String(var.name()),var);}
)*
]
try {
final Expression expr;
Expression initializer = null;
final int pos = SimpleCharStream.getPosition();
+ int assignOperator = -1;
}
{
- expr = ConditionalExpression() {return expr;}
+ LOOKAHEAD(1)
+ expr = ConditionalExpression()
+ [
+ assignOperator = AssignmentOperator()
+ try {
+ initializer = ConditionalExpression()
+ } catch (ParseException e) {
+ if (errorMessage != null) {
+ throw e;
+ }
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
+ errorLevel = ERROR;
+ errorEnd = SimpleCharStream.getPosition();
+ throw e;
+ }
+ ]
+ {
+ char[] varName = expr.toStringExpression().substring(1).toCharArray();
+ if (assignOperator == -1) {
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
+ pos,
+ SimpleCharStream.getPosition());
+ return expr;
+ }
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
+ initializer,
+ assignOperator,
+ pos);
+ }
+ {return expr;}
| expr = ExpressionWBang() {return expr;}
}
{
expr = PrintExpression() {return expr;}
| expr = ListExpression() {return expr;}
-|
- var = VariableDeclaratorId()
- [
- assignOperator = AssignmentOperator()
- try {
- expr = Expression()
- } catch (ParseException e) {
- if (errorMessage != null) {
- throw e;
- }
- errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
- errorLevel = ERROR;
- errorEnd = SimpleCharStream.getPosition();
- throw e;
- }
- ]
- {
- if (assignOperator == -1) {
- return new VariableDeclaration(currentSegment,
- var.toCharArray(),
- pos,
- SimpleCharStream.getPosition());
- }
- return new VariableDeclaration(currentSegment,
- var.toCharArray(),
- expr,
- assignOperator,
- pos);
- }
- {return expr;}
}
/**
final int pos = SimpleCharStream.getPosition();
}
{
- identifier = <IDENTIFIER>
- {expr = new ConstantIdentifier(token.image.toCharArray(),
- pos,
- SimpleCharStream.getPosition());}
+ expr = PrimaryPrefix()
(expr = PrimarySuffix(expr))*
+ [ expr = Arguments(expr) ]
{return expr;}
|
- expr = ArrayDeclarator()
+ <NEW> expr = ClassIdentifier()
+ {expr = new PrefixedUnaryExpression(expr,
+ OperatorIds.NEW,
+ pos);
+ }
+ [ expr = Arguments(expr) ]
{return expr;}
|
- <NEW> expr = ClassIdentifier()
- {expr = new PrefixedUnaryExpression(expr,OperatorIds.NEW,pos);}
- [expr = Arguments(expr)]
+ expr = ArrayDeclarator()
{return expr;}
}
+Expression PrimaryPrefix() :
+{
+ final Expression expr;
+ final Token token;
+ final String var;
+ final int pos = SimpleCharStream.getPosition();
+}
+{
+ token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
+ pos,
+ SimpleCharStream.getPosition());}
+|
+ var = VariableDeclaratorId() {return new Variable(var.toCharArray(),
+ pos,
+ SimpleCharStream.getPosition());}
+}
+
AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
{
final AbstractSuffixExpression suffix;
final Expression expr;
}
{
- suffix = Arguments(prefix) {return suffix;}
-| suffix = VariableSuffix(prefix) {return suffix;}
+ suffix = VariableSuffix(prefix) {return suffix;}
| <STATICCLASSACCESS> expr = ClassIdentifier()
{suffix = new ClassAccess(prefix,
expr,
/**
* A Statement without break.
+ * @return a statement
*/
Statement StatementNoBreak() :
{
}
{
LOOKAHEAD(2)
- statement = Expression()
- try {
- <SEMICOLON>
- } catch (ParseException e) {
- if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
- errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
- errorLevel = ERROR;
- errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
- }
- }
- {return statement;}
+ statement = expressionStatement() {return statement;}
| LOOKAHEAD(1)
- statement = LabeledStatement() {return statement;}
-| statement = Block() {return statement;}
-| statement = EmptyStatement() {return statement;}
-/*| statement = StatementExpression()
- try {
- <SEMICOLON>
- } catch (ParseException e) {
- errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
- errorLevel = ERROR;
- errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
- }
- {return statement;} */
+ statement = LabeledStatement() {return statement;}
+| statement = Block() {return statement;}
+| statement = EmptyStatement() {return statement;}
| statement = SwitchStatement() {return statement;}
| statement = IfStatement() {return statement;}
| statement = WhileStatement() {return statement;}
| statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
}
+/**
+ * A statement expression.
+ * expression ;
+ * @return an expression
+ */
+Statement expressionStatement() :
+{
+ final Statement statement;
+}
+{
+ statement = Expression()
+ try {
+ <SEMICOLON>
+ } catch (ParseException e) {
+ if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ throw e;
+ }
+ }
+ {return statement;}
+}
+
Define defineStatement() :
{
final int start = SimpleCharStream.getPosition();
VariableDeclaration expr;
}
{
- <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
- (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
+ <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name()));}
+ (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name()));})*
try {
<SEMICOLON>
{
{
if (initializer == null) {
return new VariableDeclaration(currentSegment,
- varName.toCharArray(),
+ new Variable(varName.toCharArray(),SimpleCharStream.getPosition()-varName.length(),SimpleCharStream.getPosition()),
pos,
SimpleCharStream.getPosition());
}
return new VariableDeclaration(currentSegment,
- varName.toCharArray(),
+ new Variable(varName.toCharArray(),SimpleCharStream.getPosition()-varName.length(),SimpleCharStream.getPosition()),
initializer,
VariableDeclaration.EQUAL,
pos);