Codegen
This commit is contained in:
@@ -12,4 +12,6 @@ void main() {
|
|||||||
|
|
||||||
app_instance.boot();
|
app_instance.boot();
|
||||||
app_instance.run();
|
app_instance.run();
|
||||||
|
|
||||||
|
1+(1*2);
|
||||||
}
|
}
|
||||||
+21
-21
@@ -156,6 +156,25 @@ impl GetRust for Expression {
|
|||||||
+ &Some(prefixes).get_rust()
|
+ &Some(prefixes).get_rust()
|
||||||
+ &postfixes.get_rust()
|
+ &postfixes.get_rust()
|
||||||
}
|
}
|
||||||
|
// Safely integrated to handle the tree structure built by the Pratt Parser
|
||||||
|
Expression::Binary { lhs, op, rhs } => {
|
||||||
|
let op_str = match op {
|
||||||
|
BinaryOp::Plus => "+",
|
||||||
|
BinaryOp::Minus => "-",
|
||||||
|
BinaryOp::Multiply => "*",
|
||||||
|
BinaryOp::Divide => "/",
|
||||||
|
BinaryOp::Modulo => "%",
|
||||||
|
BinaryOp::Equal => "==",
|
||||||
|
BinaryOp::NotEqual => "!=",
|
||||||
|
BinaryOp::LessThan => "<",
|
||||||
|
BinaryOp::GreaterThan => ">",
|
||||||
|
BinaryOp::LessThanOrEqual => "<=",
|
||||||
|
BinaryOp::GreaterThanOrEqual => ">=",
|
||||||
|
BinaryOp::And => "&&",
|
||||||
|
BinaryOp::Or => "||",
|
||||||
|
};
|
||||||
|
format!("{} {} {}", lhs.get_rust(), op_str, rhs.get_rust())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,26 +244,8 @@ impl GetRust for Postfix {
|
|||||||
|
|
||||||
Postfix::Index(idx) => {
|
Postfix::Index(idx) => {
|
||||||
format!("[{}]", idx.get_rust())
|
format!("[{}]", idx.get_rust())
|
||||||
}
|
} // Note: Postfix::Binary variant logic has been completely transferred
|
||||||
|
// to Expression::Binary to match your updated AST configuration.
|
||||||
Postfix::Binary(op, rhs) => {
|
|
||||||
let op_str = match op {
|
|
||||||
BinaryOp::Plus => "+",
|
|
||||||
BinaryOp::Minus => "-",
|
|
||||||
BinaryOp::Multiply => "*",
|
|
||||||
BinaryOp::Divide => "/",
|
|
||||||
BinaryOp::Modulo => "%",
|
|
||||||
BinaryOp::Equal => "==",
|
|
||||||
BinaryOp::NotEqual => "!=",
|
|
||||||
BinaryOp::LessThan => "<",
|
|
||||||
BinaryOp::GreaterThan => ">",
|
|
||||||
BinaryOp::LessThanOrEqual => "<=",
|
|
||||||
BinaryOp::GreaterThanOrEqual => ">=",
|
|
||||||
BinaryOp::And => "&&",
|
|
||||||
BinaryOp::Or => "||",
|
|
||||||
};
|
|
||||||
format!(" {} {}", op_str, rhs.get_rust())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,7 +255,6 @@ impl GetRust for [Postfix] {
|
|||||||
self.iter().map(Postfix::get_rust).collect()
|
self.iter().map(Postfix::get_rust).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// ToRust — output-writing (top-level, statements, blocks)
|
// ToRust — output-writing (top-level, statements, blocks)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user