summaryrefslogtreecommitdiff
path: root/src/ast_pretty_printer.c
AgeCommit message (Collapse)Author
2023-05-10gas: Generate code for if statementCarlos Maniero
If statements are now working, the only exception is for the comparators || and && that will be addressed in a further commit. Checks tested: fn main(): i32 { let n: i32 = 11; if (n == 11) { if n != 12 { if n < 12 { if n <= 11 { if n > 10 { if n >= 11 { return 42; } } } } } } return n; } To compile the && and || a precedence issue must be addressed: they must have the highest precedence, witch is not working now: 1 == 2 || 3 != 2 The or should be the higher level of the tree in the example above. Signed-off-by: Carlos Maniero <carlos@maniero.me>
2023-05-09parser: parses an if statement no code generationCarlos Maniero
This commit parses a if statement following the grammar bellow: if boolean_expression { n_epressions; } No else neither code generation was implemented. Signed-off-by: Carlos Maniero <carlos@maniero.me>
2023-05-09parser: create a block node typeCarlos Maniero
Since the next step to pipa programming language is about having control flow statements we could benefit ourselves by having a block node to control scope. Now, functions has a block node, instead of an vector as body. As you can see through the ast-dump: FunctionDecl name='main' └─ body: └─ Block └─ ReturnStmt └─ Literal type=i32 value='69' This same node kind can be used for parsing if, for and while blocks. I could use ast_block_t as body for functions but instead, I opted to use an ast_node_t. This brings the flexibility to, in the future, having another function body kinds, such as arrow functions if we want to: fn add(a: i32, b: i32): i32 => a + b; Signed-off-by: Carlos Maniero <carlos@maniero.me>
2023-05-09parser: Add the bool typeCarlos Maniero
This commit introduces a new type for booleans. There is no code generation for this type yet. The intention of this commit is to enable flow control in the near future. Signed-off-by: Carlos Maniero <carlos@maniero.me> Reviewed-by: Johnny Richard <johnny@johnnyrichard.com>
2023-05-06cli: Fix bitwise handling on --ast-dumpJohnny Richard
In C, literal integers default to a 32-bit size for arithmetic operations. Unfortunately, this was causing incorrect values to be assigned to our uint64_t variables, leading to unexpected behavior. To resolve this issue, we have updated our code to explicitly set the literal size using the "ULL" suffix (unsigned long long). It's important to note that this implementation has a limitation of 64 levels of indentation. Beyond this point, we may encounter a 64-bit overflow. However, at present, we don't anticipate the need to visualize trees that exceed this depth. If this requirement arises in the future, we can explore solutions like dynamically creating new numbers to accommodate larger tree sizes. Overall, this change ensures that our code is functioning correctly and improves the reliability of our codebase. Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
2023-05-05cli: Add AST pretty-printing option (--ast-dump)Johnny Richard
Parsing can be a complex process, and it's not always easy to get a clear picture of what's happening with the AST. This commit adds a new feature to the CLI that allows us to pretty-print the AST (outputs to stdout), making it easier to visualize the tree structure and understand how the parser is working. The new --ast-dump option generates a human-readable representation of the AST, including node types, values, and child relationships. This information can be invaluable for debugging and understanding the parser's behavior. Signed-off-by: Johnny Richard <johnny@johnnyrichard.com> Reviewed-by: Carlos Maniero <carlos@maniero.me>