Structures de base pour l'AST
This commit is contained in:
30
src/expr.rs
Normal file
30
src/expr.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use crate::token::Token;
|
||||||
|
|
||||||
|
pub struct Binary {
|
||||||
|
left: Expr,
|
||||||
|
operator: Token,
|
||||||
|
right: Expr,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Grouping {
|
||||||
|
expression: Expr,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Literal {
|
||||||
|
LiteralNumber(i8),
|
||||||
|
LiteralString(String),
|
||||||
|
LiteralBool(bool),
|
||||||
|
LiteralNil,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Unary {
|
||||||
|
operator: Token,
|
||||||
|
right: Expr,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Expr {
|
||||||
|
Binary ,
|
||||||
|
Grouping,
|
||||||
|
Literal,
|
||||||
|
Unary,
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ mod rlox_interpreter;
|
|||||||
mod scanner;
|
mod scanner;
|
||||||
mod token;
|
mod token;
|
||||||
mod token_type;
|
mod token_type;
|
||||||
|
mod expr;
|
||||||
|
|
||||||
use crate::rlox_interpreter::RLoxInterpreter;
|
use crate::rlox_interpreter::RLoxInterpreter;
|
||||||
|
|
||||||
@@ -34,4 +35,4 @@ fn main() {
|
|||||||
// https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations#rust
|
// https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations#rust
|
||||||
|
|
||||||
// Pause :
|
// Pause :
|
||||||
// http://www.craftinginterpreters.com/scanning.html#lexical-errors
|
// http://www.craftinginterpreters.com/representing-code.html#working-with-trees
|
||||||
|
|||||||
Reference in New Issue
Block a user