AST - Variable assignment
This commit is contained in:
parent
c486b81cba
commit
b5ff24ffad
1 changed files with 4 additions and 0 deletions
|
@ -22,6 +22,9 @@ pub enum StmtNode {
|
||||||
/// An AST node that represents an expression.
|
/// An AST node that represents an expression.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ExprNode {
|
pub enum ExprNode {
|
||||||
|
/// Assignment to a variable.
|
||||||
|
Assignment { name: Token, value: Box<ExprNode> },
|
||||||
|
|
||||||
/// Binary expression.
|
/// Binary expression.
|
||||||
Binary {
|
Binary {
|
||||||
left: Box<ExprNode>,
|
left: Box<ExprNode>,
|
||||||
|
@ -79,6 +82,7 @@ impl AstDumper for StmtNode {
|
||||||
impl AstDumper for ExprNode {
|
impl AstDumper for ExprNode {
|
||||||
fn dump(&self) -> String {
|
fn dump(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
|
Self::Assignment { name, value } => format!("( = {} {} )", name.lexeme, value.dump()),
|
||||||
Self::Binary {
|
Self::Binary {
|
||||||
left,
|
left,
|
||||||
operator,
|
operator,
|
||||||
|
|
Loading…
Reference in a new issue