Structures pour représenter une expression et affichage d'un AST.
This commit is contained in:
31
src/main.rs
31
src/main.rs
@@ -1,6 +1,7 @@
|
||||
use std::env;
|
||||
use std::process;
|
||||
use crate::expr::Expr;
|
||||
use crate::expr::{Binary, Expr, Grouping, Literal, Unary, Visitable};
|
||||
use crate::expr::Expr::LiteralExpr;
|
||||
|
||||
mod rlox_interpreter;
|
||||
mod scanner;
|
||||
@@ -9,6 +10,8 @@ mod token_type;
|
||||
mod expr;
|
||||
|
||||
use crate::rlox_interpreter::RLoxInterpreter;
|
||||
use crate::token::Token;
|
||||
use crate::token_type::TokenType;
|
||||
|
||||
// Exit codes from #include <sysexits.h>
|
||||
const EX_OK: i32 = 0;
|
||||
@@ -18,6 +21,8 @@ const EX_USAGE : i32 = 66;
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
essai_visitor();
|
||||
|
||||
let exit_code = match args.len() {
|
||||
1 => { RLoxInterpreter::new().run_prompt() } ,
|
||||
2 => { RLoxInterpreter::new().run_file(&args[1]) },
|
||||
@@ -30,6 +35,30 @@ fn main() {
|
||||
process::exit(exit_code);
|
||||
}
|
||||
|
||||
fn essai_visitor() {
|
||||
let expression = Expr::BinaryExpr(Binary {
|
||||
left: Box::new(Expr::UnaryExpr( Unary {
|
||||
operator: Token {
|
||||
token_type: TokenType::Minus,
|
||||
lexeme: String::from("-"),
|
||||
line: 0,
|
||||
literal: String::from("-")
|
||||
},
|
||||
right: Box::new(Expr::LiteralExpr(Literal::LiteralNumber(123.0)))
|
||||
})),
|
||||
operator: Token {
|
||||
token_type: TokenType::Star,
|
||||
lexeme: String::from("*"),
|
||||
line: 0,
|
||||
literal: String::from("*")
|
||||
},
|
||||
right: Box::new(Expr::GroupingExpr ( Grouping {
|
||||
expression: Box::new(LiteralExpr(Literal::LiteralNumber(123.0)))
|
||||
}))
|
||||
});
|
||||
|
||||
expression.visit();
|
||||
}
|
||||
|
||||
|
||||
// Implémentations de référence :
|
||||
|
||||
Reference in New Issue
Block a user