Start using ASTVisitor for reduction process

This commit is contained in:
greg 2019-07-11 19:11:54 -07:00
parent a187d43fc1
commit 74a574b093

View File

@ -3,6 +3,7 @@ use std::rc::Rc;
use crate::ast::*; use crate::ast::*;
use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable}; use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable};
use crate::builtin::{BinOp, PrefixOp}; use crate::builtin::{BinOp, PrefixOp};
use crate::visitor::{ASTVisitor, Visitable};
#[derive(Debug)] #[derive(Debug)]
pub struct ReducedAST(pub Vec<Stmt>); pub struct ReducedAST(pub Vec<Stmt>);
@ -94,6 +95,30 @@ pub enum Func {
} }
} }
struct Reducer {
}
impl Reducer {
fn new() -> Reducer {
Reducer { }
}
fn output(&mut self) -> Result<ReducedAST, String> {
Err("yolo".to_string())
}
}
impl ASTVisitor for Reducer {
}
pub fn perform_reduction(mut input: AST, _symbol_table: &SymbolTable) -> Result<ReducedAST, String> {
let mut reducer = Reducer::new();
input.visit(&mut reducer);
reducer.output()
}
impl AST { impl AST {
pub fn reduce(&self, symbol_table: &SymbolTable) -> ReducedAST { pub fn reduce(&self, symbol_table: &SymbolTable) -> ReducedAST {
let mut output = vec![]; let mut output = vec![];