@@ -45,7 +45,7 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
4545 _ => panic ! ( "Unsupported operator for numbers" ) ,
4646 }
4747 }
48- ( Value :: Float ( l) , Value :: Float ( r) ) => { // New case for float operations
48+ ( Value :: Float ( l) , Value :: Float ( r) ) => {
4949 match op {
5050 Token :: Plus => Value :: Float ( l + r) ,
5151 Token :: Minus => Value :: Float ( l - r) ,
@@ -60,7 +60,7 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
6060 _ => panic ! ( "Unsupported operator for floats" ) ,
6161 }
6262 }
63- ( Value :: Number ( l) , Value :: Float ( r) ) => { // Mixed number and float operations
63+ ( Value :: Number ( l) , Value :: Float ( r) ) => {
6464 let l = l as f64 ;
6565 match op {
6666 Token :: Plus => Value :: Float ( l + r) ,
@@ -76,7 +76,7 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
7676 _ => panic ! ( "Unsupported operator for mixed number and float" ) ,
7777 }
7878 }
79- ( Value :: Float ( l) , Value :: Number ( r) ) => { // Mixed float and number operations
79+ ( Value :: Float ( l) , Value :: Number ( r) ) => {
8080 let r = r as f64 ;
8181 match op {
8282 Token :: Plus => Value :: Float ( l + r) ,
@@ -136,6 +136,24 @@ fn interpret_node(node: &ASTNode, symbol_table: &mut HashMap<String, (Value, boo
136136 }
137137 Value :: Null
138138 } ,
139+ ASTNode :: While ( condition, body) => {
140+ loop {
141+ let cond_value = interpret_node ( condition, symbol_table, is_verbose, true ) ;
142+ if let Value :: Boolean ( false ) = cond_value {
143+ break ;
144+ }
145+
146+ for stmt in body {
147+ let result = interpret_node ( stmt, symbol_table, is_verbose, true ) ;
148+ match result {
149+ Value :: Break => return Value :: Null ,
150+ Value :: Continue => break ,
151+ _ => { }
152+ }
153+ }
154+ }
155+ Value :: Null
156+ } ,
139157 ASTNode :: Var ( name, expr, is_mutable) => {
140158 let value = if let Some ( expr) = expr {
141159 interpret_node ( expr, symbol_table, is_verbose, in_loop)
0 commit comments