Added support for discard statement
This commit is contained in:
parent
818e385889
commit
dc162e7b03
|
@ -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
|
||||
*
|
||||
|
@ -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() ~ "'");
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue