Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-03-01 11:38:02 -08:00
parent ecbc47d4fe
commit bc09cb07b1
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
17 changed files with 236 additions and 217 deletions

View file

@ -15,17 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use crate::segment::{Ctr, Seg};
use crate::sym::SymTable;
use crate::segment::{Seg, Ctr};
/* iterates over a syntax tree
* returns a NEW LIST of values
* representing the simplest possible form of the input
*/
pub fn eval (
ast: &Seg,
syms: &mut SymTable,
) -> Result<Box<Ctr>, String> {
pub fn eval(ast: &Seg, syms: &mut SymTable) -> Result<Box<Ctr>, String> {
// data to return
let mut ret = Box::from(Ctr::None);
let mut first = true;
@ -42,12 +39,10 @@ pub fn eval (
let mut none = false;
while !none {
match &**arg_car {
Ctr::Seg(ref inner) => {
match eval(inner, syms) {
Ok(res) => car = res,
Err(e) => return Err(format!("evaluation error: {}", e)),
}
}
Ctr::Seg(ref inner) => match eval(inner, syms) {
Ok(res) => car = res,
Err(e) => return Err(format!("evaluation error: {}", e)),
},
Ctr::Symbol(ref tok) => {
let outer_scope_seg_holder: Seg;