mirror of https://github.com/tbklang/tlang.git
Added support for discard statement
This commit is contained in:
parent
818e385889
commit
dc162e7b03
|
@ -781,6 +781,25 @@ public final class Parser
|
||||||
return bruh;
|
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
|
* Parses an expression
|
||||||
*
|
*
|
||||||
|
@ -963,7 +982,7 @@ public final class Parser
|
||||||
/* Get the identifier */
|
/* Get the identifier */
|
||||||
string identifier = getCurrentToken().getToken();
|
string identifier = getCurrentToken().getToken();
|
||||||
nextToken();
|
nextToken();
|
||||||
|
|
||||||
|
|
||||||
Expression toAdd;
|
Expression toAdd;
|
||||||
|
|
||||||
|
@ -1444,6 +1463,13 @@ public final class Parser
|
||||||
/* Add the struct definition to the program */
|
/* Add the struct definition to the program */
|
||||||
modulle.addStatement(ztruct);
|
modulle.addStatement(ztruct);
|
||||||
}
|
}
|
||||||
|
/* If it is a `discard` statement */
|
||||||
|
else if(symbol == SymbolType.DISCARD)
|
||||||
|
{
|
||||||
|
Expression expression = parseDiscard();
|
||||||
|
|
||||||
|
modulle.addStatement(expression);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
expect("parse(): Unknown '" ~ tok.getToken() ~ "'");
|
expect("parse(): Unknown '" ~ tok.getToken() ~ "'");
|
||||||
|
|
|
@ -27,6 +27,7 @@ public enum SymbolType
|
||||||
NEW,
|
NEW,
|
||||||
IF,
|
IF,
|
||||||
ELSE,
|
ELSE,
|
||||||
|
DISCARD,
|
||||||
WHILE,
|
WHILE,
|
||||||
CLASS,
|
CLASS,
|
||||||
INHERIT_OPP,
|
INHERIT_OPP,
|
||||||
|
@ -313,6 +314,11 @@ public SymbolType getSymbolType(Token tokenIn)
|
||||||
{
|
{
|
||||||
return SymbolType.NEW;
|
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 */
|
/* An identifier/type (of some sorts) - further inspection in parser is needed */
|
||||||
else if(isPathIdentifier(token) || isIdentifier(token))
|
else if(isPathIdentifier(token) || isIdentifier(token))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue