Made `new` expression support more explicit to return a `NewExpression` with an embedded FunctionCall rather than a FunctionCall alone
This commit is contained in:
parent
8799ab9b85
commit
c957845c66
|
@ -995,14 +995,15 @@ public final class Parser
|
|||
nextToken();
|
||||
|
||||
|
||||
Expression toAdd;
|
||||
NewExpression toAdd;
|
||||
FunctionCall functionCallPart;
|
||||
|
||||
/* If the symbol is `(` then function call */
|
||||
if (getSymbolType(getCurrentToken()) == SymbolType.LBRACE)
|
||||
{
|
||||
/* TODO: Implement function call parsing */
|
||||
previousToken();
|
||||
toAdd = parseFuncCall();
|
||||
functionCallPart = parseFuncCall();
|
||||
}
|
||||
/* If not an `(` */
|
||||
else
|
||||
|
@ -1011,9 +1012,27 @@ public final class Parser
|
|||
expect(SymbolType.LBRACE, getCurrentToken());
|
||||
}
|
||||
|
||||
/* Create a NewExpression with the associated FunctionCall */
|
||||
toAdd = new NewExpression(functionCallPart);
|
||||
|
||||
/* Add the expression */
|
||||
addRetExp(toAdd);
|
||||
}
|
||||
/* TODO: New addition (UNTESTED, remove if problem causer) */
|
||||
else if(symbol == SymbolType.DOT)
|
||||
{
|
||||
/* Pop the previous expression */
|
||||
Expression previousExpression = removeExp();
|
||||
|
||||
/* TODO: Get next expression */
|
||||
nextToken();
|
||||
Expression item = parseExpression();
|
||||
|
||||
/* TODO: Construct accessor expression from both and addRetExp */
|
||||
|
||||
BinaryOperatorExpression binOp = new BinaryOperatorExpression(SymbolType.DOT, previousExpression, item);
|
||||
|
||||
addRetExp(binOp);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1324,7 +1343,7 @@ public final class Parser
|
|||
gprintln("parseStatement(): Leave", DebugType.WARNING);
|
||||
}
|
||||
|
||||
private Expression parseFuncCall()
|
||||
private FunctionCall parseFuncCall()
|
||||
{
|
||||
gprintln("parseFuncCall(): Enter", DebugType.WARNING);
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ public enum SymbolType
|
|||
CASE,
|
||||
GOTO,
|
||||
DO,
|
||||
DOT,
|
||||
DELETE,
|
||||
STRUCT,
|
||||
UNKNOWN
|
||||
|
@ -369,6 +370,12 @@ public SymbolType getSymbolType(Token tokenIn)
|
|||
{
|
||||
return SymbolType.TILDE;
|
||||
}
|
||||
/* Dot operator check */
|
||||
else if (token[0] == '.')
|
||||
{
|
||||
return SymbolType.DOT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -86,4 +86,19 @@ public class Expression : Statement
|
|||
}
|
||||
|
||||
/* TODO: Evalute this expression's type */
|
||||
}
|
||||
|
||||
public final class NewExpression : Expression
|
||||
{
|
||||
private FunctionCall funcCall;
|
||||
|
||||
this(FunctionCall funcCall)
|
||||
{
|
||||
this.funcCall = funcCall;
|
||||
}
|
||||
|
||||
public FunctionCall getFuncCall()
|
||||
{
|
||||
return funcCall;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ A aInstance;
|
|||
B bInstance;
|
||||
int p = p+p*2;
|
||||
int k =1+p+l;
|
||||
int o = new A().l;
|
||||
int o = new A().l.p.p;
|
||||
|
||||
class A
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue