Started new kv impl with support for mutable cells, just the basic interpreter. Going to add the lazy bytecode interperter next
This commit is contained in:
31
kv/src/grammar.lalrpop
Normal file
31
kv/src/grammar.lalrpop
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::str::FromStr;
|
||||
use std::rc::Rc;
|
||||
use crate::ast::Form;
|
||||
|
||||
grammar;
|
||||
|
||||
pub Term: Form = {
|
||||
NUM => Form::Int(i32::from_str(<>).unwrap()),
|
||||
SYM => Form::Symbol(<>.to_owned()),
|
||||
"(" <ListInside?> ")" => <>.unwrap_or(Form::Nil),
|
||||
"'" <Term> => Form::Pair(Rc::new(Form::Symbol("quote".to_owned())), Rc::new(Form::Pair(Rc::new(<>), Rc::new(Form::Nil)))),
|
||||
"!" <h: Term> <t: Term> => {
|
||||
h.append(Rc::new(t)).unwrap()
|
||||
},
|
||||
};
|
||||
ListInside: Form = {
|
||||
<Term> => Form::Pair(Rc::new(<>), Rc::new(Form::Nil)),
|
||||
<h: Term> <t: ListInside> => Form::Pair(Rc::new(h), Rc::new(t)),
|
||||
<a: Term> "." <d: Term> => Form::Pair(Rc::new(a), Rc::new(d)),
|
||||
}
|
||||
match {
|
||||
"(",
|
||||
")",
|
||||
".",
|
||||
"'",
|
||||
"!",
|
||||
r"[0-9]+" => NUM,
|
||||
r"[a-zA-Z+*/_=?%&|^<>-][\w+*/=_?%&|^<>-]*" => SYM,
|
||||
r"(;[^\n]*\n)|\s+" => { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user