Added support for discard statement

This commit is contained in:
Tristan B. Kildaire 2021-06-09 12:55:59 +02:00
parent 818e385889
commit dc162e7b03
2 changed files with 33 additions and 1 deletions

View File

@ -781,6 +781,25 @@ public final class Parser
return bruh;
}
/**
* Only a subset of expressions are parsed without coming after
* an assignment, functioncall parameters etc
*
* Therefore instead of mirroring a lot fo what is in expression, for now atleast
* I will support everything using discard
*
* TODO: Remove discard and implement the needed mirrors
*/
private Expression parseDiscard()
{
/* Consume the `discard` */
nextToken();
return parseExpression();
}
/**
* Parses an expression
*
@ -963,7 +982,7 @@ public final class Parser
/* Get the identifier */
string identifier = getCurrentToken().getToken();
nextToken();
Expression toAdd;
@ -1444,6 +1463,13 @@ public final class Parser
/* Add the struct definition to the program */
modulle.addStatement(ztruct);
}
/* If it is a `discard` statement */
else if(symbol == SymbolType.DISCARD)
{
Expression expression = parseDiscard();
modulle.addStatement(expression);
}
else
{
expect("parse(): Unknown '" ~ tok.getToken() ~ "'");

View File

@ -27,6 +27,7 @@ public enum SymbolType
NEW,
IF,
ELSE,
DISCARD,
WHILE,
CLASS,
INHERIT_OPP,
@ -313,6 +314,11 @@ public SymbolType getSymbolType(Token tokenIn)
{
return SymbolType.NEW;
}
/* discard keyword */
else if(cmp(token, "discard") == 0)
{
return SymbolType.DISCARD;
}
/* An identifier/type (of some sorts) - further inspection in parser is needed */
else if(isPathIdentifier(token) || isIdentifier(token))
{