Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8618bb2
feat: AST generation for arithmetic expressions
LeanSerra Oct 24, 2025
10b9f99
fix: remove clone from Ast
LeanSerra Oct 24, 2025
dd518f7
ci: set rust toolchain to nightly
LeanSerra Oct 24, 2025
ef7e251
ci: set rust toolchain to nightly 1.91.0
LeanSerra Oct 24, 2025
0992a35
ci: remove toolchain version from install rust step
LeanSerra Oct 24, 2025
f1f46db
feat: graph AST with Graphviz
LeanSerra Oct 25, 2025
002840b
docs: update README.md with graphviz reference
LeanSerra Oct 25, 2025
040e25e
docs: fix prerequisites list formatting
LeanSerra Oct 25, 2025
e3769e7
fix: remove boolean chains (a<b<c) and fix conjunctions
LeanSerra Oct 26, 2025
fc203fd
feat: AST generation for booleanStatements and If
LeanSerra Oct 26, 2025
6b42e9c
fix: else statements could be used before having an if before it
LeanSerra Oct 26, 2025
f549d63
feat: AST generation for else statements and nested ifs
LeanSerra Oct 26, 2025
e597648
fix: reset body pointer on empty body
LeanSerra Oct 27, 2025
16cf44d
feat: AST generation for while statements
LeanSerra Oct 27, 2025
6a18108
fix: var name in while_loop_while
LeanSerra Oct 27, 2025
aabb950
feat: AST generation for write io function
LeanSerra Oct 27, 2025
7036d79
feat: AST generation for read io function
LeanSerra Oct 27, 2025
7a1021d
feat: AST support multiple statements in body
LeanSerra Oct 27, 2025
0fed071
fix: handle errors for empty statement stack
LeanSerra Oct 27, 2025
70af0d4
feat: AST support for convDate
LeanSerra Oct 28, 2025
78c4418
feat: AST support for isZero
LeanSerra Oct 28, 2025
5508518
feat: AST generation for Number
LeanSerra Oct 28, 2025
efb80e3
refactor: cleanup AST code
LeanSerra Oct 28, 2025
f2ae3df
refactor: move wrap log_error_and_exit into log_ast_error
LeanSerra Oct 28, 2025
1bd4c62
Merge branch 'main' into feat/ast_cleanup
LeanSerra Oct 29, 2025
7357639
fix: comment in term_term_div_factor
LeanSerra Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 8 additions & 32 deletions src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::{

pub struct Ast {
tree: [Rc<Node>; mem::variant_count::<AstPtr>()],
pub stack_t: Vec<Rc<Node>>,
pub stack_e: Vec<Rc<Node>>,
pub term_stack: Vec<Rc<Node>>,
pub expression_stack: Vec<Rc<Node>>,
pub comparision_op_stack: Vec<ComparisonOp>,
pub comparision_expressions_stack: Vec<Rc<Node>>,
pub boolean_expression_stack: Vec<Rc<Node>>,
Expand All @@ -23,8 +23,8 @@ pub struct Ast {

impl Debug for Ast {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{:?}", self.stack_t)?;
writeln!(f, "{:?}", self.stack_e)?;
writeln!(f, "{:?}", self.term_stack)?;
writeln!(f, "{:?}", self.expression_stack)?;
writeln!(f, "{:?}", self.comparision_op_stack)?;
writeln!(f, "{:?}", self.comparision_expressions_stack)
}
Expand Down Expand Up @@ -132,6 +132,7 @@ pub enum AstAction {
Read,
Write,
S,
Negative,
Noop,
}

Expand Down Expand Up @@ -159,6 +160,7 @@ impl Display for AstAction {
Self::Read => write!(f, "READ"),
Self::Write => write!(f, "WRITE"),
Self::S => write!(f, "S"),
Self::Negative => write!(f, "NEG"),
Self::Noop => write!(f, "NOOP"),
}
}
Expand All @@ -181,8 +183,8 @@ impl Default for Ast {
fn default() -> Self {
Self {
tree: array::from_fn(|_| Rc::new(Node::new_leaf(NodeValue::Value("".to_string())))),
stack_e: Vec::new(),
stack_t: Vec::new(),
expression_stack: Vec::new(),
term_stack: Vec::new(),
comparision_op_stack: Vec::new(),
comparision_expressions_stack: Vec::new(),
boolean_expression_stack: Vec::new(),
Expand Down Expand Up @@ -286,32 +288,6 @@ impl Ast {
Ok(node_count)
}

pub fn push_t_stack(&mut self, node: AstNodeRef) {
let node = match node {
AstNodeRef::Node(node) => node,
AstNodeRef::Ptr(ptr) => self.tree[ptr as usize].clone(),
};

self.stack_t.push(node);
}

pub fn pop_t_stack(&mut self) -> Option<Rc<Node>> {
self.stack_t.pop()
}

pub fn push_e_stack(&mut self, node: AstNodeRef) {
let node = match node {
AstNodeRef::Node(node) => node,
AstNodeRef::Ptr(ptr) => self.tree[ptr as usize].clone(),
};

self.stack_e.push(node);
}

pub fn pop_e_stack(&mut self) -> Option<Rc<Node>> {
self.stack_e.pop()
}

pub fn get_node_from_ptr(&self, from: AstPtr) -> Rc<Node> {
self.tree[from as usize].clone()
}
Expand Down
Loading