extended lexer to support 'this'

This commit is contained in:
CPunch 2020-11-05 18:43:21 -06:00
parent ffa6ca22e3
commit 4cd5c89d28
3 changed files with 10 additions and 0 deletions

View File

@ -21,6 +21,7 @@ CReservedWord reservedWords[] = {
{TOKEN_THEN, "then", 4}, {TOKEN_THEN, "then", 4},
{TOKEN_TRUE, "true", 4}, {TOKEN_TRUE, "true", 4},
{TOKEN_VAR, "var", 3}, {TOKEN_VAR, "var", 3},
{TOKEN_THIS, "this", 4},
{TOKEN_WHILE, "while", 5} {TOKEN_WHILE, "while", 5}
}; };
@ -198,6 +199,8 @@ _scanTokenEnter:
case ')': state->openedBraces--; return makeToken(state, TOKEN_RIGHT_PAREN); case ')': state->openedBraces--; return makeToken(state, TOKEN_RIGHT_PAREN);
case '{': state->openedBraces++; return makeToken(state, TOKEN_LEFT_BRACE); case '{': state->openedBraces++; return makeToken(state, TOKEN_LEFT_BRACE);
case '}': state->openedBraces--; return makeToken(state, TOKEN_RIGHT_BRACE); case '}': state->openedBraces--; return makeToken(state, TOKEN_RIGHT_BRACE);
case '[': state->openedBraces++; return makeToken(state, TOKEN_LEFT_BRACKET);
case ']': state->openedBraces--; return makeToken(state, TOKEN_RIGHT_BRACKET);
case '\0': case '\0':
state->isEnd = true; state->isEnd = true;
if (state->lastType == TOKEN_EOS) if (state->lastType == TOKEN_EOS)

View File

@ -9,6 +9,8 @@ typedef enum {
TOKEN_RIGHT_PAREN, TOKEN_RIGHT_PAREN,
TOKEN_LEFT_BRACE, TOKEN_LEFT_BRACE,
TOKEN_RIGHT_BRACE, TOKEN_RIGHT_BRACE,
TOKEN_LEFT_BRACKET,
TOKEN_RIGHT_BRACKET,
TOKEN_COMMA, TOKEN_COMMA,
TOKEN_DOT, TOKEN_DOT,
TOKEN_DOT_DOT, TOKEN_DOT_DOT,
@ -51,6 +53,7 @@ typedef enum {
TOKEN_RETURN, TOKEN_RETURN,
TOKEN_THEN, TOKEN_THEN,
TOKEN_VAR, TOKEN_VAR,
TOKEN_THIS,
TOKEN_WHILE, TOKEN_WHILE,
TOKEN_ERROR, TOKEN_ERROR,

View File

@ -536,6 +536,8 @@ ParseRule ruleTable[] = {
[TOKEN_RIGHT_PAREN] = {NULL, NULL, PREC_NONE}, [TOKEN_RIGHT_PAREN] = {NULL, NULL, PREC_NONE},
[TOKEN_LEFT_BRACE] = {object, NULL, PREC_OBJ}, [TOKEN_LEFT_BRACE] = {object, NULL, PREC_OBJ},
[TOKEN_RIGHT_BRACE] = {NULL, NULL, PREC_NONE}, [TOKEN_RIGHT_BRACE] = {NULL, NULL, PREC_NONE},
[TOKEN_LEFT_BRACKET] = {NULL, NULL, PREC_NONE},
[TOKEN_RIGHT_BRACKET] = {NULL, NULL, PREC_NONE},
[TOKEN_COMMA] = {NULL, NULL, PREC_NONE}, [TOKEN_COMMA] = {NULL, NULL, PREC_NONE},
[TOKEN_DOT] = {NULL, dot, PREC_CALL}, [TOKEN_DOT] = {NULL, dot, PREC_CALL},
[TOKEN_DOT_DOT] = {NULL, concat, PREC_CONCAT}, [TOKEN_DOT_DOT] = {NULL, concat, PREC_CONCAT},
@ -573,6 +575,8 @@ ParseRule ruleTable[] = {
[TOKEN_THEN] = {NULL, NULL, PREC_NONE}, [TOKEN_THEN] = {NULL, NULL, PREC_NONE},
[TOKEN_WHILE] = {NULL, NULL, PREC_NONE}, [TOKEN_WHILE] = {NULL, NULL, PREC_NONE},
[TOKEN_ERROR] = {NULL, NULL, PREC_NONE}, [TOKEN_ERROR] = {NULL, NULL, PREC_NONE},
[TOKEN_VAR] = {NULL, NULL, PREC_NONE},
[TOKEN_THIS] = {NULL, NULL, PREC_NONE},
[TOKEN_EOF] = {NULL, NULL, PREC_NONE} [TOKEN_EOF] = {NULL, NULL, PREC_NONE}
}; };