end
class Parser
+ LEVELS = {
+ none: 0,
+ assign: 1,
+ or: 2,
+ and: 3,
+ equality: 4,
+ compare: 5,
+ term: 6,
+ factor: 7,
+ unary: 8,
+ call: 9,
+ primary: 10,
+ }
+
def initialize(path)
@lex = Lexer.new(path)
+ @prev = nil
@next = nil
end
defs
end
+ private
+
def topdef(defs)
dectype = declaration(defs)
if dectype == :fun then
expect("{")
+ value = expression()
expect("}")
else
expect("=")
- expect(:int)
+ value = expression()
end
+ pp value
end
def declaration(syms)
end
end
- private
+ def parseLevel(level)
+ end
+
+ def expression()
+ constant()
+ end
+
+ def constant()
+ if (peek().type == :int)
+ AST::Value.new(Type::Int, consume().text.to_i)
+ else
+ error("not a valid constant")
+ end
+ end
def error(str)
raise str
def accept(type)
if (matches(type))
+ @prev = @next
@next = nil
true
else