Added `parseClass()` function, `class` keyword support - for future class support

This commit is contained in:
Tristan B. Velloza Kildaire 2021-03-04 23:25:20 +02:00
parent 14aafe7097
commit a493ecc2a9
2 changed files with 57 additions and 1 deletions

View File

@ -271,7 +271,12 @@ public final class Parser
/* If the symbol is `(` then function call */
if(getSymbolType(getCurrentToken()) == SymbolType.LBRACE)
{
/* TODO: Implement function call */
/* TODO: Implement function call parsing */
}
else
{
/* TODO: Leave the token here */
/* TODO: Just leave it, yeah */
}
}
else
@ -342,6 +347,36 @@ public final class Parser
gprintln("ParseTypedDec: Je suis fini");
}
/**
* Parses a class definition
*
* This is called when there is an occurrence of
* a token `class`
*
* STATUS: Not integrated
* STATUS: Not tested
*/
private void parseClass()
{
/* Pop off the `class` */
nextToken();
/* Get the class's name */
expect(SymbolType.IDENTIFIER, getCurrentToken());
string className = getCurrentToken().getToken();
gprintln("parseClass(): Class name found '"~className~"'");
/* Expect a `{` */
nextToken();
expect(SymbolType.OCURLY, getCurrentToken());
/* Parse a body */
parseBody();
/* TODO: Ending here, expect closing `}`? */
}
private void parseStatement()
{
/* TODO: Implement parse statement */

View File

@ -25,6 +25,9 @@ public enum SymbolType
CCURLY,
IF,
WHILE,
CLASS,
INHERIT_OPP,
TILDE,
UNKNOWN
}
@ -107,6 +110,11 @@ public static SymbolType getSymbolType(Token tokenIn)
{
return SymbolType.WHILE;
}
/* class keyword */
else if(cmp(token, "class") == 0)
{
return SymbolType.CLASS;
}
/* Identifier check (TODO: Track vars) */
else if (isAlpha(token))
{
@ -147,6 +155,19 @@ public static SymbolType getSymbolType(Token tokenIn)
{
return SymbolType.COMMA;
}
/* Inheritance operator check */
else if (token[0] == ':')
{
return SymbolType.INHERIT_OPP;
}
/* Tilde operator check */
else if (token[0] == '~')
{
return SymbolType.TILDE;
}
return SymbolType.UNKNOWN;