parseExpression fixed for termination

Updated test cases to test this
expression_parsing.sync-conflict-20210316-090018-O3W7KWN
Tristan B. Kildaire 2021-03-15 10:46:00 +02:00
parent 0cc1b2e4ea
commit b7f77b8619
2 changed files with 50 additions and 38 deletions

View File

@ -281,6 +281,15 @@ public final class Parser
/* TODO: Implement expression parsing */ /* TODO: Implement expression parsing */
/**
* We loop here until we hit something that closes
* an expression, in other words an expression
* appears in variable assignments which end with a
* `;`, they also appear in conditions which end in
* a `)`
*/
while (true)
{
SymbolType symbol = getSymbolType(getCurrentToken()); SymbolType symbol = getSymbolType(getCurrentToken());
/* If it is a number literal */ /* If it is a number literal */
@ -288,21 +297,16 @@ public final class Parser
{ {
/* Get the next token */ /* Get the next token */
nextToken(); nextToken();
}
/* Check if the token is a mathematical operator */ /* If it is a maths operator */
if (isMathOp(getCurrentToken())) else if(isMathOp(getCurrentToken()))
{ {
/* TODO:check math op */ /* 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 */ /* If it is a string literal */
else if (symbol == SymbolType.STRING_LITERAL) else if (symbol == SymbolType.STRING_LITERAL)
{ {
@ -328,10 +332,16 @@ public final class Parser
} }
} }
/* TODO: Add the `)` and `;` detection here to terminate ourselves */ /* TODO: Add the `)` and `;` detection here to terminate ourselves */
else if(symbol == SymbolType.SEMICOLON || symbol == SymbolType.RBRACE)
{
break;
}
else else
{ {
gprintln("parseExpression(): NO MATCH", DebugType.ERROR); //gprintln("parseExpression(): NO MATCH", DebugType.ERROR);
/* TODO: Something isn't right here */ /* TODO: Something isn't right here */
expect("Expected expression terminator ) or ;");
}
} }
gprintln("parseExpression(): Leave", DebugType.WARNING); gprintln("parseExpression(): Leave", DebugType.WARNING);

View File

@ -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)
{ {