Skip to content

Parser Returns Hardcoded AST on Invalid Input #10

Description

@SAMBA8695

Description

The parser currently returns a hardcoded AST node (create_num_node(4)) when the first token is not TOKEN_LET.

This causes invalid or unsupported input to silently compile into an incorrect AST instead of producing a syntax error.

Current Code

ASTNode *parse(Token *tokens){
    if(tokens[pos].type == TOKEN_LET){
        ...
        return create_var_declare_node(name, value);
    }
    return create_num_node(4);
}

Current Behavior

Any input that does not begin with let is parsed as the constant value 4.

Example

x + 2;

Produces an AST equivalent to:

4

No error is reported.

Expected Behavior

  • The parser should not fabricate AST nodes
  • Unsupported or invalid syntax should produce a clear parse error
  • Compilation should fail explicitly instead of returning a placeholder value

Suggested Direction

  • Remove the hardcoded fallback create_num_node(4)
  • Return NULL or a structured parse error
  • Add proper error reporting for unsupported top-level syntax

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions