diff --git a/src/parser.rs b/src/parser.rs index 4071f23..de90b7d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -20,12 +20,24 @@ use std::collections::VecDeque; // op := '+', '-', etc. // +pub type AST = Vec; + #[derive(Debug, Clone)] pub enum Statement { ExprNode(Expression), FuncDefNode(Function), } +impl fmt::Display for Statement { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use self::Statement::*; + match *self { + ExprNode(ref expr) => write!(f, "{}", expr), + FuncDefNode(_) => write!(f, "UNIMPLEMENTED"), + } + } +} + #[derive(Debug, Clone)] pub struct Function { pub prototype: Prototype, @@ -52,16 +64,6 @@ pub enum Expression { While(Box, Vec), } -impl fmt::Display for Statement { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use self::Statement::*; - match *self { - ExprNode(ref expr) => write!(f, "{}", expr), - FuncDefNode(_) => write!(f, "UNIMPLEMENTED"), - } - } -} - impl fmt::Display for Expression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use self::Expression::*; @@ -77,8 +79,6 @@ impl fmt::Display for Expression { } } -pub type AST = Vec; - type Precedence = u8; // TODO make this support incomplete parses @@ -126,6 +126,8 @@ impl Parser { "/" => 20, "%" => 20, "=" => 1, + "==" => 40, + ">" | ">=" | "<" | "<=" => 30, _ => 255, } }