Port onto libakstdlib 2b79aca and convert the eight bool predicates
akbasic's src/ now calls libakstdlib 313 times and raw libc 7 -- 2.2% bypassed, against 86.4% on the same tree before this. The submodule bump 669b2b3 -> 2b79aca needed no source change of its own: the release is drop-in for what akbasic already used. Seven of the eight sites the earlier port left on raw libc change their own signature rather than swallowing an error, per andrew's ruling on libakstdlib#38. word_is, the is_waiting_for pair, the scanner's is_at_end, peek, peek_next and match_next_char, format.c's overflow, and sink_akgl's scroll/newline/putchar_at/echo_line/edit_key chain all return an akerr_ErrorContext * and hand the answer back through an out parameter. is_waiting_for and is_waiting_for_any are a public header change; every call site that used one as a term in a condition hoists it into a statement first. verb_compare is the eighth and stays on strcmp. bsearch(3) fixes the comparator's signature, so there is no out parameter to report through -- which is what libakstdlib#38 concluded. It carries a comment saying so and saying why the bypass is safe there. Six snprintf sites stay raw because they want truncation as an answer rather than an error, and aksl_snprintf cannot express that until libakstdlib#34 hands the required length back. Each of the six says so at the site. Two of them, in host.c, are a latent defect rather than a decision: a host type name over 31 characters truncates silently and two sharing a prefix then collide, where structtype.c refuses the same case. DLOAD leaked a file descriptor. Its read loop sat inside an ATTEMPT and the PASS in it returned past CLEANUP, so a scan error left the file open. Hoisting the loop into its own helper to convert fgets fixes it. Refs libakstdlib#26, libakstdlib#38 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,10 +10,9 @@
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include <akerror.h>
|
||||
#include <akstdlib.h>
|
||||
|
||||
#include <akbasic/error.h>
|
||||
#include <akbasic/parser.h>
|
||||
@@ -78,20 +77,23 @@ akerr_ErrorContext *akbasic_parse_graphic(akbasic_Parser *parser, akbasic_ASTLea
|
||||
akbasic_ASTLeaf *arglist = NULL;
|
||||
akbasic_ASTLeaf *expr = NULL;
|
||||
akbasic_Token *peeked = NULL;
|
||||
int cmp = 0;
|
||||
|
||||
peeked = akbasic_parser_peek(parser);
|
||||
if ( peeked != NULL && peeked->tokentype == AKBASIC_TOK_COMMAND &&
|
||||
strcmp(peeked->lexeme, "CLR") == 0 ) {
|
||||
(void)akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND);
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &arglist));
|
||||
arglist->leaftype = AKBASIC_LEAF_ARGUMENTLIST;
|
||||
arglist->operator_ = AKBASIC_TOK_FUNCTION_ARGUMENT;
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &arglist->right));
|
||||
PASS(errctx, akbasic_leaf_new_literal_int(arglist->right, "5"));
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &expr));
|
||||
PASS(errctx, akbasic_leaf_new_command(expr, "GRAPHIC", arglist));
|
||||
*dest = expr;
|
||||
SUCCEED_RETURN(errctx);
|
||||
if ( peeked != NULL && peeked->tokentype == AKBASIC_TOK_COMMAND ) {
|
||||
PASS(errctx, aksl_strcmp(peeked->lexeme, "CLR", &cmp));
|
||||
if ( cmp == 0 ) {
|
||||
(void)akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND);
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &arglist));
|
||||
arglist->leaftype = AKBASIC_LEAF_ARGUMENTLIST;
|
||||
arglist->operator_ = AKBASIC_TOK_FUNCTION_ARGUMENT;
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &arglist->right));
|
||||
PASS(errctx, akbasic_leaf_new_literal_int(arglist->right, "5"));
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &expr));
|
||||
PASS(errctx, akbasic_leaf_new_command(expr, "GRAPHIC", arglist));
|
||||
*dest = expr;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
}
|
||||
PASS(errctx, akbasic_parse_arglist(parser, dest));
|
||||
SUCCEED_RETURN(errctx);
|
||||
@@ -105,6 +107,7 @@ akerr_ErrorContext *akbasic_parse_draw(akbasic_Parser *parser, akbasic_ASTLeaf *
|
||||
akbasic_ASTLeaf *tail = NULL;
|
||||
akbasic_Token *peeked = NULL;
|
||||
akbasic_Token *operator_ = NULL;
|
||||
int cmp = 0;
|
||||
|
||||
/*
|
||||
* DRAW source, x1,y1 TO x2,y2 TO x3,y3 -- a polyline, with TO between pairs
|
||||
@@ -125,9 +128,11 @@ akerr_ErrorContext *akbasic_parse_draw(akbasic_Parser *parser, akbasic_ASTLeaf *
|
||||
|
||||
for ( ;; ) {
|
||||
peeked = akbasic_parser_peek(parser);
|
||||
if ( peeked == NULL ||
|
||||
peeked->tokentype != AKBASIC_TOK_COMMAND ||
|
||||
strcmp(peeked->lexeme, "TO") != 0 ) {
|
||||
if ( peeked == NULL || peeked->tokentype != AKBASIC_TOK_COMMAND ) {
|
||||
break;
|
||||
}
|
||||
PASS(errctx, aksl_strcmp(peeked->lexeme, "TO", &cmp));
|
||||
if ( cmp != 0 ) {
|
||||
break;
|
||||
}
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND),
|
||||
@@ -259,6 +264,7 @@ static akerr_ErrorContext *parse_loop_condition(akbasic_Parser *parser, akbasic_
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
akbasic_Token *peeked = NULL;
|
||||
int cmp = 0;
|
||||
|
||||
*condition = NULL;
|
||||
*kind = AKBASIC_LOOPCOND_NONE;
|
||||
@@ -267,12 +273,15 @@ static akerr_ErrorContext *parse_loop_condition(akbasic_Parser *parser, akbasic_
|
||||
if ( peeked == NULL || peeked->tokentype != AKBASIC_TOK_COMMAND ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
if ( strcmp(peeked->lexeme, "WHILE") == 0 ) {
|
||||
PASS(errctx, aksl_strcmp(peeked->lexeme, "WHILE", &cmp));
|
||||
if ( cmp == 0 ) {
|
||||
*kind = AKBASIC_LOOPCOND_WHILE;
|
||||
} else if ( strcmp(peeked->lexeme, "UNTIL") == 0 ) {
|
||||
*kind = AKBASIC_LOOPCOND_UNTIL;
|
||||
} else {
|
||||
SUCCEED_RETURN(errctx);
|
||||
PASS(errctx, aksl_strcmp(peeked->lexeme, "UNTIL", &cmp));
|
||||
if ( cmp != 0 ) {
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
*kind = AKBASIC_LOOPCOND_UNTIL;
|
||||
}
|
||||
(void)akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND);
|
||||
|
||||
@@ -372,6 +381,7 @@ akerr_ErrorContext *akbasic_parse_on(akbasic_Parser *parser, akbasic_ASTLeaf **d
|
||||
akbasic_ASTLeaf *expr = NULL;
|
||||
akbasic_ASTLeaf *tail = NULL;
|
||||
akbasic_Token *operator_ = NULL;
|
||||
int cmp = 0;
|
||||
bool gosub = false;
|
||||
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &arglist));
|
||||
@@ -389,10 +399,12 @@ akerr_ErrorContext *akbasic_parse_on(akbasic_Parser *parser, akbasic_ASTLeaf **d
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND),
|
||||
AKBASIC_ERR_SYNTAX, "Expected GOTO or GOSUB after ON (expression)");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &operator_));
|
||||
if ( strcmp(operator_->lexeme, "GOSUB") == 0 ) {
|
||||
PASS(errctx, aksl_strcmp(operator_->lexeme, "GOSUB", &cmp));
|
||||
if ( cmp == 0 ) {
|
||||
gosub = true;
|
||||
} else {
|
||||
FAIL_NONZERO_RETURN(errctx, strcmp(operator_->lexeme, "GOTO"), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcmp(operator_->lexeme, "GOTO", &cmp));
|
||||
FAIL_NONZERO_RETURN(errctx, cmp, AKBASIC_ERR_SYNTAX,
|
||||
"Expected GOTO or GOSUB after ON (expression)");
|
||||
}
|
||||
marker->literal_int = (gosub ? 1 : 0);
|
||||
@@ -429,14 +441,20 @@ akerr_ErrorContext *akbasic_parse_resume(akbasic_Parser *parser, akbasic_ASTLeaf
|
||||
akbasic_ASTLeaf *expr = NULL;
|
||||
akbasic_ASTLeaf *target = NULL;
|
||||
akbasic_Token *peeked = NULL;
|
||||
int cmp = 0;
|
||||
|
||||
peeked = akbasic_parser_peek(parser);
|
||||
if ( peeked != NULL && peeked->tokentype == AKBASIC_TOK_COMMAND &&
|
||||
strcmp(peeked->lexeme, "NEXT") == 0 ) {
|
||||
(void)akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND);
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &target));
|
||||
PASS(errctx, akbasic_leaf_new_command(target, "NEXT", NULL));
|
||||
} else if ( peeked != NULL && peeked->tokentype != AKBASIC_TOK_COLON ) {
|
||||
if ( peeked != NULL && peeked->tokentype == AKBASIC_TOK_COMMAND ) {
|
||||
PASS(errctx, aksl_strcmp(peeked->lexeme, "NEXT", &cmp));
|
||||
if ( cmp == 0 ) {
|
||||
(void)akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND);
|
||||
PASS(errctx, akbasic_parser_new_leaf(parser, &target));
|
||||
PASS(errctx, akbasic_leaf_new_command(target, "NEXT", NULL));
|
||||
}
|
||||
}
|
||||
/* The other two forms, taken only when the word was not NEXT -- which is
|
||||
what a target already built says. */
|
||||
if ( target == NULL && peeked != NULL && peeked->tokentype != AKBASIC_TOK_COLON ) {
|
||||
PASS(errctx, akbasic_parser_expression(parser, &target));
|
||||
}
|
||||
|
||||
@@ -464,6 +482,8 @@ akerr_ErrorContext *akbasic_parse_print(akbasic_Parser *parser, akbasic_ASTLeaf
|
||||
akbasic_ASTLeaf *arglist = NULL;
|
||||
akbasic_ASTLeaf *right = NULL;
|
||||
akbasic_Token *peeked = NULL;
|
||||
int cmp = 0;
|
||||
bool matched = false;
|
||||
|
||||
peeked = akbasic_parser_peek(parser);
|
||||
|
||||
@@ -499,8 +519,11 @@ akerr_ErrorContext *akbasic_parse_print(akbasic_Parser *parser, akbasic_ASTLeaf
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
if ( peeked == NULL || peeked->tokentype != AKBASIC_TOK_COMMAND ||
|
||||
strcmp(peeked->lexeme, "USING") != 0 ) {
|
||||
if ( peeked != NULL && peeked->tokentype == AKBASIC_TOK_COMMAND ) {
|
||||
PASS(errctx, aksl_strcmp(peeked->lexeme, "USING", &cmp));
|
||||
matched = (cmp == 0);
|
||||
}
|
||||
if ( !matched ) {
|
||||
/* The ordinary PRINT: one expression, or none at all. */
|
||||
if ( peeked != NULL && peeked->tokentype != AKBASIC_TOK_COLON ) {
|
||||
PASS(errctx, akbasic_parser_expression(parser, &right));
|
||||
@@ -627,12 +650,14 @@ akerr_ErrorContext *akbasic_parse_point(akbasic_Parser *parser, akbasic_ASTLeaf
|
||||
akbasic_ASTLeaf *arglist = NULL;
|
||||
akbasic_ASTLeaf *command = NULL;
|
||||
akbasic_Token *word = NULL;
|
||||
int cmp = 0;
|
||||
|
||||
PASS(errctx, akbasic_parser_expression(parser, &pointer));
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_IDENTIFIER),
|
||||
AKBASIC_ERR_SYNTAX, "Expected POINT <pointer> AT <structure>");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
FAIL_ZERO_RETURN(errctx, (strcasecmp(word->lexeme, "AT") == 0), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcasecmp(word->lexeme, "AT", &cmp));
|
||||
FAIL_ZERO_RETURN(errctx, (cmp == 0), AKBASIC_ERR_SYNTAX,
|
||||
"Expected AT after POINT <pointer>, not %s", word->lexeme);
|
||||
PASS(errctx, akbasic_parser_expression(parser, &target));
|
||||
|
||||
@@ -668,6 +693,7 @@ akerr_ErrorContext *akbasic_parse_dim(akbasic_Parser *parser, akbasic_ASTLeaf **
|
||||
PREPARE_ERROR(errctx);
|
||||
akbasic_ASTLeaf *command = NULL;
|
||||
akbasic_Token *word = NULL;
|
||||
int cmp = 0;
|
||||
|
||||
PASS(errctx, parse_verb_with_identifier(parser, "DIM", dest));
|
||||
command = *dest;
|
||||
@@ -676,13 +702,15 @@ akerr_ErrorContext *akbasic_parse_dim(akbasic_Parser *parser, akbasic_ASTLeaf **
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
FAIL_ZERO_RETURN(errctx, (strcasecmp(word->lexeme, "AS") == 0), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcasecmp(word->lexeme, "AS", &cmp));
|
||||
FAIL_ZERO_RETURN(errctx, (cmp == 0), AKBASIC_ERR_SYNTAX,
|
||||
"Expected AS after DIM %s, not %s", command->right->identifier, word->lexeme);
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_IDENTIFIER),
|
||||
AKBASIC_ERR_SYNTAX, "Expected a type name after AS");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
if ( strcasecmp(word->lexeme, "PTR") == 0 ) {
|
||||
PASS(errctx, aksl_strcasecmp(word->lexeme, "PTR", &cmp));
|
||||
if ( cmp == 0 ) {
|
||||
command->literal_int = 1;
|
||||
/*
|
||||
* `TO` is already a verb -- FOR ... TO owns it -- so it arrives as a
|
||||
@@ -694,13 +722,14 @@ akerr_ErrorContext *akbasic_parse_dim(akbasic_Parser *parser, akbasic_ASTLeaf **
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND),
|
||||
AKBASIC_ERR_SYNTAX, "Expected TO after PTR");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
FAIL_ZERO_RETURN(errctx, (strcasecmp(word->lexeme, "TO") == 0), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcasecmp(word->lexeme, "TO", &cmp));
|
||||
FAIL_ZERO_RETURN(errctx, (cmp == 0), AKBASIC_ERR_SYNTAX,
|
||||
"Expected PTR TO TYPENAME, not PTR %s", word->lexeme);
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_IDENTIFIER),
|
||||
AKBASIC_ERR_SYNTAX, "Expected a type name after PTR TO");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
}
|
||||
snprintf(command->literal_string, sizeof(command->literal_string), "%s", word->lexeme);
|
||||
PASS(errctx, aksl_strcpy(command->literal_string, sizeof(command->literal_string), word->lexeme));
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
@@ -738,6 +767,7 @@ static akerr_ErrorContext *parse_def_parameters(akbasic_Parser *parser, akbasic_
|
||||
akbasic_ASTLeaf *param = NULL;
|
||||
akbasic_ASTLeaf *tail = NULL;
|
||||
akbasic_Token *word = NULL;
|
||||
int cmp = 0;
|
||||
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_LEFT_PAREN),
|
||||
AKBASIC_ERR_SYNTAX, "Expected an argument list after DEF <name>");
|
||||
@@ -762,25 +792,28 @@ static akerr_ErrorContext *parse_def_parameters(akbasic_Parser *parser, akbasic_
|
||||
"%s must name its type: %s AS TYPENAME, or %s AS PTR TO TYPENAME",
|
||||
param->identifier, param->identifier, param->identifier);
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
FAIL_ZERO_RETURN(errctx, (strcasecmp(word->lexeme, "AS") == 0), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcasecmp(word->lexeme, "AS", &cmp));
|
||||
FAIL_ZERO_RETURN(errctx, (cmp == 0), AKBASIC_ERR_SYNTAX,
|
||||
"Expected AS after %s, not %s", param->identifier, word->lexeme);
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_IDENTIFIER),
|
||||
AKBASIC_ERR_SYNTAX, "Expected a type name after AS");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
if ( strcasecmp(word->lexeme, "PTR") == 0 ) {
|
||||
PASS(errctx, aksl_strcasecmp(word->lexeme, "PTR", &cmp));
|
||||
if ( cmp == 0 ) {
|
||||
param->literal_int = 1;
|
||||
/* `TO` is already a verb -- FOR ... TO owns it -- so it arrives
|
||||
as a command token rather than an identifier. */
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND),
|
||||
AKBASIC_ERR_SYNTAX, "Expected TO after PTR");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
FAIL_ZERO_RETURN(errctx, (strcasecmp(word->lexeme, "TO") == 0), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcasecmp(word->lexeme, "TO", &cmp));
|
||||
FAIL_ZERO_RETURN(errctx, (cmp == 0), AKBASIC_ERR_SYNTAX,
|
||||
"Expected PTR TO TYPENAME, not PTR %s", word->lexeme);
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_IDENTIFIER),
|
||||
AKBASIC_ERR_SYNTAX, "Expected a type name after PTR TO");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &word));
|
||||
}
|
||||
snprintf(param->literal_string, sizeof(param->literal_string), "%s", word->lexeme);
|
||||
PASS(errctx, aksl_strcpy(param->literal_string, sizeof(param->literal_string), word->lexeme));
|
||||
}
|
||||
|
||||
if ( tail == NULL ) {
|
||||
@@ -806,6 +839,7 @@ akerr_ErrorContext *akbasic_parse_def(akbasic_Parser *parser, akbasic_ASTLeaf **
|
||||
akbasic_ASTLeaf *expression = NULL;
|
||||
akbasic_ASTLeaf *command = NULL;
|
||||
akbasic_FunctionDef *fndef = NULL;
|
||||
size_t namelen = 0;
|
||||
size_t i = 0;
|
||||
|
||||
PASS(errctx, akbasic_parser_primary(parser, &identifier));
|
||||
@@ -817,13 +851,14 @@ akerr_ErrorContext *akbasic_parse_def(akbasic_Parser *parser, akbasic_ASTLeaf **
|
||||
PASS(errctx, akbasic_runtime_new_function(runtime, &fndef));
|
||||
|
||||
/* Uppercase the name: verbs and function names are case-insensitive. */
|
||||
FAIL_ZERO_RETURN(errctx, (strlen(identifier->identifier) < sizeof(fndef->name)),
|
||||
PASS(errctx, aksl_strlen(identifier->identifier, &namelen));
|
||||
FAIL_ZERO_RETURN(errctx, (namelen < sizeof(fndef->name)),
|
||||
AKBASIC_ERR_BOUNDS, "Function name '%s' is too long", identifier->identifier);
|
||||
for ( i = 0; i < strlen(identifier->identifier); i++ ) {
|
||||
for ( i = 0; i < namelen; i++ ) {
|
||||
char c = identifier->identifier[i];
|
||||
fndef->name[i] = (char)((c >= 'a' && c <= 'z') ? (c - 'a' + 'A') : c);
|
||||
}
|
||||
fndef->name[strlen(identifier->identifier)] = '\0';
|
||||
fndef->name[namelen] = '\0';
|
||||
|
||||
if ( akbasic_parser_match1(parser, AKBASIC_TOK_ASSIGNMENT) ) {
|
||||
PASS(errctx, akbasic_parser_expression(parser, &expression));
|
||||
@@ -866,13 +901,15 @@ akerr_ErrorContext *akbasic_parse_for(akbasic_Parser *parser, akbasic_ASTLeaf **
|
||||
akbasic_Environment *parent = runtime->environment;
|
||||
akbasic_Environment *newenv = NULL;
|
||||
int64_t firstline = 0;
|
||||
int cmp = 0;
|
||||
|
||||
PASS(errctx, akbasic_parser_assignment(parser, &assignment));
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND),
|
||||
AKBASIC_ERR_SYNTAX,
|
||||
"Expected FOR (assignment) TO (expression) [STEP (expression)]");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &operator_));
|
||||
FAIL_NONZERO_RETURN(errctx, strcmp(operator_->lexeme, "TO"), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcmp(operator_->lexeme, "TO", &cmp));
|
||||
FAIL_NONZERO_RETURN(errctx, cmp, AKBASIC_ERR_SYNTAX,
|
||||
"Expected FOR (assignment) TO (expression) [STEP (expression)]");
|
||||
FAIL_ZERO_RETURN(errctx,
|
||||
(assignment != NULL && akbasic_leaf_is_identifier(assignment->left)),
|
||||
@@ -894,7 +931,8 @@ akerr_ErrorContext *akbasic_parse_for(akbasic_Parser *parser, akbasic_ASTLeaf **
|
||||
|
||||
if ( akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND) ) {
|
||||
PASS(errctx, akbasic_parser_previous(parser, &operator_));
|
||||
FAIL_NONZERO_RETURN(errctx, strcmp(operator_->lexeme, "STEP"), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcmp(operator_->lexeme, "STEP", &cmp));
|
||||
FAIL_NONZERO_RETURN(errctx, cmp, AKBASIC_ERR_SYNTAX,
|
||||
"Expected FOR (assignment) TO (expression) [STEP (expression)]");
|
||||
PASS(errctx, akbasic_parser_expression(parser, &newenv->forStepLeaf));
|
||||
} else {
|
||||
@@ -907,7 +945,8 @@ akerr_ErrorContext *akbasic_parse_for(akbasic_Parser *parser, akbasic_ASTLeaf **
|
||||
}
|
||||
|
||||
/* A NEXT already being awaited means this is an inner loop over the same variable. */
|
||||
if ( strcmp(parent->waitingForCommand, "NEXT") == 0 ) {
|
||||
PASS(errctx, aksl_strcmp(parent->waitingForCommand, "NEXT", &cmp));
|
||||
if ( cmp == 0 ) {
|
||||
newenv->forNextVariable = parent->forNextVariable;
|
||||
}
|
||||
newenv->loopFirstLine = firstline;
|
||||
@@ -1038,6 +1077,7 @@ akerr_ErrorContext *akbasic_parse_if(akbasic_Parser *parser, akbasic_ASTLeaf **d
|
||||
akbasic_ASTLeaf *else_command = NULL;
|
||||
akbasic_ASTLeaf *branch = NULL;
|
||||
akbasic_Token *operator_ = NULL;
|
||||
int cmp = 0;
|
||||
|
||||
/*
|
||||
* Everything from here to the THEN is a condition, so a lone `=` in it is an
|
||||
@@ -1057,14 +1097,16 @@ akerr_ErrorContext *akbasic_parse_if(akbasic_Parser *parser, akbasic_ASTLeaf **d
|
||||
FAIL_ZERO_RETURN(errctx, akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND),
|
||||
AKBASIC_ERR_SYNTAX, "Incomplete IF statement");
|
||||
PASS(errctx, akbasic_parser_previous(parser, &operator_));
|
||||
FAIL_NONZERO_RETURN(errctx, strcmp(operator_->lexeme, "THEN"), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcmp(operator_->lexeme, "THEN", &cmp));
|
||||
FAIL_NONZERO_RETURN(errctx, cmp, AKBASIC_ERR_SYNTAX,
|
||||
"Expected IF ... THEN");
|
||||
|
||||
PASS(errctx, akbasic_parser_command(parser, &then_command));
|
||||
|
||||
if ( akbasic_parser_match1(parser, AKBASIC_TOK_COMMAND) ) {
|
||||
PASS(errctx, akbasic_parser_previous(parser, &operator_));
|
||||
FAIL_NONZERO_RETURN(errctx, strcmp(operator_->lexeme, "ELSE"), AKBASIC_ERR_SYNTAX,
|
||||
PASS(errctx, aksl_strcmp(operator_->lexeme, "ELSE", &cmp));
|
||||
FAIL_NONZERO_RETURN(errctx, cmp, AKBASIC_ERR_SYNTAX,
|
||||
"Expected IF ... THEN ... ELSE ...");
|
||||
PASS(errctx, akbasic_parser_command(parser, &else_command));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user