diff --git a/mojobasic_internal.h b/mojobasic_internal.h index 2d4616c..54396f5 100644 --- a/mojobasic_internal.h +++ b/mojobasic_internal.h @@ -510,7 +510,8 @@ enum Token TOKEN_DEF, TOKEN_GET, TOKEN_PUT, - TOKEN_STEP + TOKEN_STEP, + TOKEN_USING }; diff --git a/mojobasic_parser.cpp b/mojobasic_parser.cpp index 870eda7..7e12a28 100644 --- a/mojobasic_parser.cpp +++ b/mojobasic_parser.cpp @@ -285,6 +285,7 @@ void Parser::convertToParserToken(TokenData &data) TOKENCMP(GET); TOKENCMP(PUT); TOKENCMP(STEP); + TOKENCMP(USING); #undef TOKENCMP } // if } // Parser::convertToParserToken @@ -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() diff --git a/mojobasic_preprocessor.cpp b/mojobasic_preprocessor.cpp index e5cfbdc..17e66ca 100644 --- a/mojobasic_preprocessor.cpp +++ b/mojobasic_preprocessor.cpp @@ -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: