|
Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
|
Statement parsing implementation for the programming language compiler. More...
#include <stdio.h>#include <string.h>#include "../ast/ast.h"#include "parser.h"#include "src/lexer/lexer.h"
Functions | |
| Stmt * | expr_stmt (Parser *parser) |
| Parses an expression statement. | |
| Stmt * | use_stmt (Parser *parser) |
| Stmt * | os_stmt (Parser *parser) |
| Stmt * | link_stmt (Parser *parser) |
| Stmt * | const_stmt (Parser *parser, bool is_public, bool returns_ownership, bool takes_ownership) |
| Parses a constant declaration statement. | |
| Stmt * | fn_stmt (Parser *parser, const char *name, bool is_public, bool is_static, bool returns_ownership, bool takes_ownership) |
| Parses a function declaration statement. | |
| Stmt * | enum_stmt (Parser *parser, const char *name, bool is_public) |
| Parses an enumeration declaration statement. | |
| Stmt * | struct_stmt (Parser *parser, const char *name, bool is_public) |
| Parses a structure declaration statement. | |
| Stmt * | var_stmt (Parser *parser, bool is_public) |
| Parses a variable declaration statement. | |
| Stmt * | return_stmt (Parser *parser) |
| Parses a return statement. | |
| Stmt * | block_stmt (Parser *parser) |
| Parses a block statement. | |
| Stmt * | if_stmt (Parser *parser) |
| Parses if/elif/else conditional statements. | |
| Stmt * | infinite_loop_stmt (Parser *parser, int line, int col) |
| Parses an infinite loop statement. | |
| Stmt * | loop_init (Parser *parser, int line, int col) |
| Parses a loop initializer declaration. | |
| Stmt * | for_loop_stmt (Parser *parser, int line, int col) |
| Parses a for loop statement. | |
| Stmt * | loop_stmt (Parser *parser) |
| Parses loop statements (infinite, while, or for loops) | |
| Stmt * | print_stmt (Parser *parser, bool ln) |
| Parses print/println statements. | |
| Stmt * | break_continue_stmt (Parser *parser, bool is_continue) |
| Parses break and continue statements. | |
| Stmt * | defer_stmt (Parser *parser) |
| Stmt * | switch_stmt (Parser *parser) |
| Stmt * | impl_stmt (Parser *parser) |
Statement parsing implementation for the programming language compiler.
This file contains implementations for parsing all types of statements in the programming language, including declarations, control flow statements, and compound statements. Each parsing function is responsible for consuming the appropriate tokens and constructing the corresponding AST nodes.
Supported statement types:
Parses a block statement.
Handles block statements with the syntax: { statement1; statement2; ... }
| parser | Pointer to the parser instance |
Parses break and continue statements.
Handles loop control statements with the syntax:
break; - Exit the current loopcontinue; - Skip to the next iteration of the current loop| parser | Pointer to the parser instance |
| is_continue | Whether this is a continue (true) or break (false) statement |
Parses a constant declaration statement.
Handles multiple forms of constant declarations:
const name: Type = value; - Explicit type annotationconst name = fn ... - Function declarationconst name = struct ... - Struct declarationconst name = enum ... - Enum declaration| parser | Pointer to the parser instance |
| is_public | Whether this declaration has public visibility |
Parses an enumeration declaration statement.
Handles enum declarations with the syntax: enum { member1, member2, member3, ... };
| parser | Pointer to the parser instance |
| name | Enum name (already parsed by caller) |
| is_public | Whether this enum has public visibility |
Parses an expression statement.
An expression statement consists of any expression followed by a semicolon. This is used for statements that evaluate an expression for its side effects, such as function calls or assignment expressions.
| parser | Pointer to the parser instance |
| Stmt * fn_stmt | ( | Parser * | parser, |
| const char * | name, | ||
| bool | is_public, | ||
| bool | is_static, | ||
| bool | returns_ownership, | ||
| bool | takes_ownership | ||
| ) |
Parses a function declaration statement.
Handles function declarations with the syntax: fn(param1: Type1, param2: Type2, ...) ReturnType { body }
| parser | Pointer to the parser instance |
| name | Function name (already parsed by caller) |
| is_public | Whether this function has public visibility |
Parses a for loop statement.
Handles for loops with the syntax:
| parser | Pointer to the parser instance |
| line | Line number where the loop statement starts |
| col | Column number where the loop statement starts |
Parses if/elif/else conditional statements.
Handles complex conditional statements with multiple branches:
| parser | Pointer to the parser instance |
Parses an infinite loop statement.
Handles infinite loops with the syntax: loop { ... }
| parser | Pointer to the parser instance |
| line | Line number where the loop statement starts |
| col | Column number where the loop statement starts |
Parses a loop initializer declaration.
Helper function for parsing variable declarations within for-loop initializers. Handles the syntax: name: Type = expression
| parser | Pointer to the parser instance |
| line | Line number for the declaration |
| col | Column number for the declaration |
Parses loop statements (infinite, while, or for loops)
Dispatcher function that determines the type of loop based on the following tokens and delegates to the appropriate specialized parser:
loop { ... } → infinite looploop [initializers](...) { ... } → for looploop (condition) { ... } → while looploop (condition) : (optional_condition) { ... } → while loop with secondary condition| parser | Pointer to the parser instance |
Parses print/println statements.
Handles output statements with the syntax:
print(expr1, expr2, ...);println(expr1, expr2, ...);| parser | Pointer to the parser instance |
| ln | Whether this is a println (true) or print (false) statement |
print(); Parses a return statement.
Handles return statements with optional return values:
return; - Return with no value (void return)return expression; - Return with a value| parser | Pointer to the parser instance |
Parses a structure declaration statement.
Handles struct declarations with public/private member visibility:
| parser | Pointer to the parser instance |
| name | Struct name (already parsed by caller) |
| is_public | Whether this struct has public visibility |
Parses a variable declaration statement.
Handles variable declarations with the syntax: var name: Type = value;
| parser | Pointer to the parser instance |
| is_public | Whether this variable has public visibility |