Minimal reproducible example:
Expected
No parsing errors
Actual
(AST) Error: Operator expected 2 operands, but 1 found
Full parser output
(RUN) Lexing BASIC program
(LEXER) Found identifier "random"
(LEXER) Found separator (
(LEXER) Found separator )
(LEXER) Found operator +
(LEXER) Found number 1
(LEXER) End of program
(LEXER) Finished tokenization of program
(RUN) Parsing to AST
(AST) Found 6 tokens in the token list
(AST) Function call to "random"
(AST) Parsing function call argument list
(AST) Function argument parse:
(AST) Trying to find expression between tokens 2 and 2
(AST) End of function call "random"
(AST) Function argument list ends at token 2
(AST) Trying to find expression between tokens 3 and 6
(AST) Expression found from token 3 to 5
(AST) Parse operator
(AST) Parse integer number
(AST) Error: Operator expected 2 operands, but 1 found
(AST) Finished parsing the program
(RUN) Preparing runtime
(RUN) Running BASIC program
(RUN) Program finished executing
Cause of the issue
After analysis of the parser, it is found that in the function basic_parse_to_ast_between_level, when case TOKEN_IDENTIFIER is encountered (and basic_parse_id_is_fn_call branch is taken), it doesn't consider it a part of a greater expression. So when an operator token is encountered later, the identifier should have been a part of the operand of this expression, but it finds only the rhs operand, causing the error.
Minimal reproducible example:
Expected
No parsing errors
Actual
Full parser output
Cause of the issue
After analysis of the parser, it is found that in the function
basic_parse_to_ast_between_level, whencase TOKEN_IDENTIFIERis encountered (andbasic_parse_id_is_fn_callbranch is taken), it doesn't consider it a part of a greater expression. So when an operator token is encountered later, the identifier should have been a part of the operand of this expression, but it finds only the rhs operand, causing the error.