Starting parsing work

This commit is contained in:
greg 2015-07-20 01:46:02 -07:00
parent 3058af4f05
commit 9f4330889a

View File

@ -24,9 +24,15 @@ enum Token {
#[derive(Debug)] #[derive(Debug)]
enum ASTNode { enum ASTNode {
GenericNode Name(String),
Number(f64),
BinOp(Box<ASTNode>, Box<ASTNode>, Box<ASTNode>)
} }
enum ParseResult<'a> {
Ok(ASTNode, &'a [Token]),
Err(String, &'a [Token])
}
fn repl() { fn repl() {
let stdin = io::stdin(); let stdin = io::stdin();
@ -45,11 +51,15 @@ fn repl() {
buf.clear(); buf.clear();
println!("Tokens: {:?}", tokens); println!("Tokens: {:?}", tokens);
let ast = parse(tokens); match parse(tokens) {
println!("AST: {:?}", ast); ParseResult::Ok(ast, _) => println!("AST: {:?}", ast),
ParseResult::Err(err, _) => println!("Error: {}", err)
}
/*
let eval = evaluate(&ast); let eval = evaluate(&ast);
println!("{}", eval); println!("{}", eval);
*/
}, },
Err(err) => { Err(err) => {
println!("Error: {}", err); println!("Error: {}", err);
@ -123,17 +133,11 @@ fn tokenize(input: &str) -> Vec<Token> {
tokens tokens
} }
fn parse(_input: Vec<Token>) -> ASTNode { fn parse<'a>(input: Vec<Token>) -> ParseResult<'a> {
ASTNode::GenericNode
let mut tokens = input.iter().peekable();
return ParseResult::Ok(ASTNode::Name("Hella".to_string()), &[]);
} }
fn evaluate(input: &ASTNode) -> String {
return match eval_ast(input) {
ASTNode::GenericNode => "Not implemented".to_string()
};
fn eval_ast(_input: &ASTNode) -> ASTNode {
return ASTNode::GenericNode;
}
}