Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implemented parsing of PRINT statement.
  • Loading branch information
icculus committed Nov 18, 2017
1 parent 0a281cb commit 5b04f5a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
3 changes: 2 additions & 1 deletion mojobasic_internal.h
Expand Up @@ -510,7 +510,8 @@ enum Token
TOKEN_DEF,
TOKEN_GET,
TOKEN_PUT,
TOKEN_STEP
TOKEN_STEP,
TOKEN_USING
};


Expand Down
53 changes: 50 additions & 3 deletions mojobasic_parser.cpp
Expand Up @@ -285,6 +285,7 @@ void Parser::convertToParserToken(TokenData &data)
TOKENCMP(GET);
TOKENCMP(PUT);
TOKENCMP(STEP);
TOKENCMP(USING);
#undef TOKENCMP
} // if
} // Parser::convertToParserToken
Expand Down Expand Up @@ -1181,10 +1182,56 @@ AstSubCallStatement *Parser::parseSeek()
AstSubCallStatement *Parser::parsePrint()
{
const SourcePosition position(previousToken.position);
AstExpressionList *args = NULL;
bool bHasUsing = false;
bool bDone = false;

while (!bDone) {
AstExpression *expr = NULL;
int type = -1;
if (wantEndOfStatement()) {
type = 0;
pushback();
bDone = true;
} else if (want(TOKEN_USING)) {
if (bHasUsing) {
fail("Can't have multiple USING clauses");
}
bHasUsing = true;
type = 1;
expr = parseExpression();
need(TOKEN_SEMICOLON, "Expected ';'");
} else if (want(TOKEN_SEMICOLON)) {
type = 2;
} else if (want(TOKEN_COMMA)) {
type = 3;
} else {
expr = parseExpression();
if (expr) {
type = 4;
}
}

// !!! FIXME: ugh, get rid of this need to have the first expression when constructing AstExpressionList.
if (type != -1) {
AstIntLiteralExpression *expr = new AstIntLiteralExpression(position, type);
if (!args) {
args = new AstExpressionList(position, expr);
} else {
args->append(expr);
}
}

if (expr) {
if (!args) {
args = new AstExpressionList(position, expr);
} else {
args->append(expr);
}
}
}

// !!! FIXME: actually write me. This one is nasty.
dumpUntilEndOfStatement(); pushback();
return new AstSubCallStatement(position, "PRINT", NULL);
return new AstSubCallStatement(position, "PRINT", args);
} // Parser::parsePrint()

AstSubCallStatement *Parser::parseView()
Expand Down
1 change: 1 addition & 0 deletions mojobasic_preprocessor.cpp
Expand Up @@ -235,6 +235,7 @@ static void MOJOBASIC_print_debug_token(const char *subsystem, const char *token
TOKENCASE(TOKEN_GET);
TOKENCASE(TOKEN_PUT);
TOKENCASE(TOKEN_STEP);
TOKENCASE(TOKEN_USING);
#undef TOKENCASE

default:
Expand Down

0 comments on commit 5b04f5a

Please sign in to comment.