parseExpression fixed for termination
Updated test cases to test thisexpression_parsing.sync-conflict-20210316-090018-O3W7KWN
parent
0cc1b2e4ea
commit
b7f77b8619
|
@ -281,58 +281,68 @@ public final class Parser
|
||||||
|
|
||||||
/* TODO: Implement expression parsing */
|
/* TODO: Implement expression parsing */
|
||||||
|
|
||||||
SymbolType symbol = getSymbolType(getCurrentToken());
|
/**
|
||||||
|
* We loop here until we hit something that closes
|
||||||
/* If it is a number literal */
|
* an expression, in other words an expression
|
||||||
if (symbol == SymbolType.NUMBER_LITERAL)
|
* appears in variable assignments which end with a
|
||||||
|
* `;`, they also appear in conditions which end in
|
||||||
|
* a `)`
|
||||||
|
*/
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
/* Get the next token */
|
SymbolType symbol = getSymbolType(getCurrentToken());
|
||||||
nextToken();
|
|
||||||
|
|
||||||
/* Check if the token is a mathematical operator */
|
/* If it is a number literal */
|
||||||
if (isMathOp(getCurrentToken()))
|
if (symbol == SymbolType.NUMBER_LITERAL)
|
||||||
{
|
{
|
||||||
/* TODO:check math op */
|
/* Get the next token */
|
||||||
|
nextToken();
|
||||||
|
}
|
||||||
|
/* If it is a maths operator */
|
||||||
|
else if(isMathOp(getCurrentToken()))
|
||||||
|
{
|
||||||
|
/* TODO: Parse expression or pass arithemetic (I think latter) */
|
||||||
nextToken();
|
nextToken();
|
||||||
|
|
||||||
/* Parse an expression */
|
/* Parse expression */
|
||||||
parseExpression();
|
parseExpression();
|
||||||
}
|
}
|
||||||
else
|
/* If it is a string literal */
|
||||||
|
else if (symbol == SymbolType.STRING_LITERAL)
|
||||||
{
|
{
|
||||||
|
/* Get the next token */
|
||||||
|
nextToken();
|
||||||
}
|
}
|
||||||
}
|
/* If it is an identifier */
|
||||||
/* If it is a string literal */
|
else if (symbol == SymbolType.IDENTIFIER)
|
||||||
else if (symbol == SymbolType.STRING_LITERAL)
|
|
||||||
{
|
|
||||||
/* Get the next token */
|
|
||||||
nextToken();
|
|
||||||
}
|
|
||||||
/* If it is an identifier */
|
|
||||||
else if (symbol == SymbolType.IDENTIFIER)
|
|
||||||
{
|
|
||||||
string identifier = getCurrentToken().getToken();
|
|
||||||
|
|
||||||
nextToken();
|
|
||||||
|
|
||||||
/* If the symbol is `(` then function call */
|
|
||||||
if (getSymbolType(getCurrentToken()) == SymbolType.LBRACE)
|
|
||||||
{
|
{
|
||||||
/* TODO: Implement function call parsing */
|
string identifier = getCurrentToken().getToken();
|
||||||
|
|
||||||
|
nextToken();
|
||||||
|
|
||||||
|
/* If the symbol is `(` then function call */
|
||||||
|
if (getSymbolType(getCurrentToken()) == SymbolType.LBRACE)
|
||||||
|
{
|
||||||
|
/* TODO: Implement function call parsing */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* TODO: Leave the token here */
|
||||||
|
/* TODO: Just leave it, yeah */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* TODO: Add the `)` and `;` detection here to terminate ourselves */
|
||||||
|
else if(symbol == SymbolType.SEMICOLON || symbol == SymbolType.RBRACE)
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* TODO: Leave the token here */
|
//gprintln("parseExpression(): NO MATCH", DebugType.ERROR);
|
||||||
/* TODO: Just leave it, yeah */
|
/* TODO: Something isn't right here */
|
||||||
|
expect("Expected expression terminator ) or ;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* TODO: Add the `)` and `;` detection here to terminate ourselves */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gprintln("parseExpression(): NO MATCH", DebugType.ERROR);
|
|
||||||
/* TODO: Something isn't right here */
|
|
||||||
}
|
|
||||||
|
|
||||||
gprintln("parseExpression(): Leave", DebugType.WARNING);
|
gprintln("parseExpression(): Leave", DebugType.WARNING);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,9 @@ void main(int hello, byte d)
|
||||||
print(1+1);
|
print(1+1);
|
||||||
print(1+1);
|
print(1+1);
|
||||||
|
|
||||||
if(1)
|
ubyte eish = 1+1;
|
||||||
|
|
||||||
|
if(1+1)
|
||||||
{
|
{
|
||||||
if(1)
|
if(1)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue