|
@@ -48,14 +48,6 @@ static Token consumeNewline(Context* c) {
|
|
|
return t;
|
|
return t;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void consumeLiteral(Context* c, const char* name) {
|
|
|
|
|
- Token token = consumeToken(c, LITERAL);
|
|
|
|
|
- const char* actual = token.stringValue;
|
|
|
|
|
- if(strcmp(actual, name) != 0) {
|
|
|
|
|
- THROW_ERROR("Unexpected literal(%s)", actual);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
static void compileConstant(Context* c) {
|
|
static void compileConstant(Context* c) {
|
|
|
Token token = tokenizerNext(c->tokenizer);
|
|
Token token = tokenizerNext(c->tokenizer);
|
|
|
if(token.type == STRING) {
|
|
if(token.type == STRING) {
|
|
@@ -89,16 +81,15 @@ static void compileIf(Context* c) {
|
|
|
CODE(codePushInstruction(c->code, JUMP_ON_0));
|
|
CODE(codePushInstruction(c->code, JUMP_ON_0));
|
|
|
size_t posIndex = codeGetWritePosition(c->code);
|
|
size_t posIndex = codeGetWritePosition(c->code);
|
|
|
CODE(codePushSize(c->code, 0));
|
|
CODE(codePushSize(c->code, 0));
|
|
|
- consumeLiteral(c, "then");
|
|
|
|
|
|
|
+ consumeToken(c, THEN);
|
|
|
consumeNewline(c);
|
|
consumeNewline(c);
|
|
|
while(true) {
|
|
while(true) {
|
|
|
- Token token = tokenizerPeek(c->tokenizer);
|
|
|
|
|
- if(token.type == LITERAL && strcmp(token.stringValue, "endif") == 0) {
|
|
|
|
|
|
|
+ if(tokenizerPeek(c->tokenizer).type == ENDIF) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
compileLine(c, tokenizerNext(c->tokenizer));
|
|
compileLine(c, tokenizerNext(c->tokenizer));
|
|
|
}
|
|
}
|
|
|
- consumeLiteral(c, "endif");
|
|
|
|
|
|
|
+ consumeToken(c, ENDIF);
|
|
|
consumeNewline(c);
|
|
consumeNewline(c);
|
|
|
size_t endIndex = codeGetWritePosition(c->code);
|
|
size_t endIndex = codeGetWritePosition(c->code);
|
|
|
codeSetWritePosition(c->code, posIndex);
|
|
codeSetWritePosition(c->code, posIndex);
|
|
@@ -110,8 +101,10 @@ static void compileLine(Context* c, Token token) {
|
|
|
if(token.type == NEWLINE) {
|
|
if(token.type == NEWLINE) {
|
|
|
c->line++;
|
|
c->line++;
|
|
|
return;
|
|
return;
|
|
|
- }
|
|
|
|
|
- if(token.type != LITERAL) {
|
|
|
|
|
|
|
+ } else if(token.type == IF) {
|
|
|
|
|
+ compileIf(c);
|
|
|
|
|
+ return;
|
|
|
|
|
+ } else if(token.type != LITERAL) {
|
|
|
unexpectedToken(c, token);
|
|
unexpectedToken(c, token);
|
|
|
}
|
|
}
|
|
|
const char* s = token.stringValue;
|
|
const char* s = token.stringValue;
|
|
@@ -122,8 +115,6 @@ static void compileLine(Context* c, Token token) {
|
|
|
}
|
|
}
|
|
|
consumeNewline(c);
|
|
consumeNewline(c);
|
|
|
CODE(codePushInstruction(c->code, PRINT_NEWLINE));
|
|
CODE(codePushInstruction(c->code, PRINT_NEWLINE));
|
|
|
- } else if(strcmp(s, "if") == 0) {
|
|
|
|
|
- compileIf(c);
|
|
|
|
|
} else {
|
|
} else {
|
|
|
THROW_ERROR("Unexpected literal(%s)", s);
|
|
THROW_ERROR("Unexpected literal(%s)", s);
|
|
|
}
|
|
}
|