diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-05 19:23:38 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-05 19:23:38 -0500 |
| commit | cc13d887c77e0b09d7dc7d4aeb66841e06f52330 (patch) | |
| tree | 852eb220586a28bd71ee6361f792301608bc3829 /compiler/ast.cup | |
| parent | [compiler.cup] Add support for lexically scoped local variables (diff) | |
| download | cup-cc13d887c77e0b09d7dc7d4aeb66841e06f52330.tar.xz cup-cc13d887c77e0b09d7dc7d4aeb66841e06f52330.zip | |
[compiler.cup] Add codegen for relational + if/conditional support
Diffstat (limited to 'compiler/ast.cup')
| -rw-r--r-- | compiler/ast.cup | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/ast.cup b/compiler/ast.cup index 689f7fb..82e8477 100644 --- a/compiler/ast.cup +++ b/compiler/ast.cup @@ -286,6 +286,13 @@ fn dump_ast(node: Node*, depth: int) { putsln(node_type_to_string(node.typ)); dump_ast(node.d.unary, depth + 1); + } else if (node.typ == AST_CONDITIONAL || node.typ == AST_IF) { + putsln(node_type_to_string(node.typ)); + dump_ast(node.d.conditional.cond, depth + 1); + dump_ast(node.d.conditional.then, depth + 1); + if (node.d.conditional.els) + dump_ast(node.d.conditional.els, depth + 1); + } else if (node.typ == AST_LITERAL) { if (node.etyp.typ == TYPE_INT) { putu(node.d.literal.as_int); putc('\n'); @@ -311,6 +318,12 @@ fn dump_ast(node: Node*, depth: int) { } else { putc('\n'); } + } else if (node.typ == AST_ASSIGN) { + putsln(node_type_to_string(node.typ)); + dump_ast(node.d.assign.lhs, depth + 1); + dump_ast(node.d.assign.rhs, depth + 1); + } else if (node.typ == AST_LOCAL_VAR || node.typ == AST_GLOBAL_VAR) { + putsln(node.d.variable.name); } else { putsln(node_type_to_string(node.typ)); } |