Mise en place formelle du visiteur et séparation de l'affichage d'un arbre syntaxique abstrait (AST).

This commit is contained in:
2024-05-03 08:03:05 +02:00
parent 66e4a515b3
commit 6e12be2d36
3 changed files with 75 additions and 38 deletions

View File

@@ -1,17 +1,20 @@
use std::env;
use std::process;
use crate::expr::{Binary, Expr, Grouping, Literal, Unary, Visitable};
use crate::expr::Expr::LiteralExpr;
mod rlox_interpreter;
mod scanner;
mod token;
mod token_type;
mod expr;
mod astprinter;
use crate::rlox_interpreter::RLoxInterpreter;
use crate::token::Token;
use crate::token_type::TokenType;
use crate::expr::{Binary, Expr, Grouping, Literal, Unary, VisitableExpr};
use crate::expr::Expr::LiteralExpr;
use crate::astprinter::ASTPrinter;
// Exit codes from #include <sysexits.h>
const EX_OK: i32 = 0;
@@ -44,7 +47,7 @@ fn essai_visitor() {
line: 0,
literal: String::from("-")
},
right: Box::new(Expr::LiteralExpr(Literal::LiteralNumber(123.0)))
right: Box::new(Expr::LiteralExpr(Literal::LiteralNumber(456.0)))
})),
operator: Token {
token_type: TokenType::Star,
@@ -57,7 +60,8 @@ fn essai_visitor() {
}))
});
expression.visit();
let a = ASTPrinter{};
expression.accept(&a);
}