Blocs d'instructions
This commit is contained in:
20
src/main.rs
20
src/main.rs
@@ -16,7 +16,7 @@ mod stmt;
|
||||
mod environment;
|
||||
|
||||
use crate::scanner::Scanner;
|
||||
use crate::stmt::{Statement, StatementVisitor};
|
||||
use crate::stmt::StatementVisitor;
|
||||
|
||||
// Exit codes from #include <sysexits.h>
|
||||
const EX_OK: i32 = 0;
|
||||
@@ -77,22 +77,14 @@ fn run(src: String) -> i32 {
|
||||
|
||||
println!("AST");
|
||||
let mut printer = ASTPrinter { depth: 0 };
|
||||
for s in program.clone() {
|
||||
match s {
|
||||
Statement::Expression(e) => { printer.visit_expr_stmt(&e) }
|
||||
Statement::Print(p) => { printer.visit_print(&p) }
|
||||
Statement::Var(v) => { printer.visit_var_stmt(&v) }
|
||||
}
|
||||
for s in &program {
|
||||
printer.visit_stmt(s);
|
||||
}
|
||||
|
||||
println!("Interpretation");
|
||||
let mut interpreter = Interpreter::new();
|
||||
for s in program {
|
||||
match s {
|
||||
Statement::Expression(e) => { interpreter.visit_expr_stmt(&e) }
|
||||
Statement::Print(p) => { interpreter.visit_print(&p) }
|
||||
Statement::Var(v) => { interpreter.visit_var_stmt(&v) }
|
||||
}
|
||||
for s in &program {
|
||||
interpreter.visit_stmt(s);
|
||||
}
|
||||
|
||||
EX_OK
|
||||
@@ -103,4 +95,4 @@ fn run(src: String) -> i32 {
|
||||
// https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations#rust
|
||||
|
||||
// Pause :
|
||||
// http://www.craftinginterpreters.com/statements-and-state.html#assignment
|
||||
// http://www.craftinginterpreters.com/statements-and-state.html#block-syntax-and-semantics (visiteur du block statement dans l'interpréteur)
|
||||
|
||||
Reference in New Issue
Block a user