setup a simple lisp

This commit is contained in:
2023-11-19 21:53:51 -05:00
parent 774eb668de
commit 41aa05dc97
3 changed files with 196 additions and 40 deletions

View File

@@ -6,17 +6,17 @@ grammar;
pub Term: Rc<Form> = {
NUM => Rc::new(Form::Int(i32::from_str(<>).unwrap())),
SYM => Rc::new(Form::Symbol(<>.to_owned())),
SYM => Rc::new(Form::Symbol(<>.to_owned(),None)),
"(" <ListInside?> ")" => <>.unwrap_or(Rc::new(Form::Nil)),
"'" <Term> => Rc::new(Form::Pair(Rc::new(Form::Symbol("quote".to_owned())), Rc::new(Form::Pair(<>, Rc::new(Form::Nil))))),
"'" <Term> => Rc::new(Form::Pair(Rc::new(Form::Symbol("quote".to_owned(),None)), Rc::new(Form::Pair(<>, Rc::new(Form::Nil),None)),None)),
"!" <h: Term> <t: Term> => {
h.append(t).unwrap()
},
};
ListInside: Rc<Form> = {
<Term> => Rc::new(Form::Pair(<>, Rc::new(Form::Nil))),
<h: Term> <t: ListInside> => Rc::new(Form::Pair(h, t)),
<a: Term> "." <d: Term> => Rc::new(Form::Pair(a, d)),
<Term> => Rc::new(Form::Pair(<>, Rc::new(Form::Nil),None)),
<h: Term> <t: ListInside> => Rc::new(Form::Pair(h, t,None)),
<a: Term> "." <d: Term> => Rc::new(Form::Pair(a, d,None)),
}
match {
"(",