Skip to content

Instantly share code, notes, and snippets.

@jimblandy
Last active September 24, 2018 06:08
Show Gist options
  • Save jimblandy/94268b0f298160515ce2902a7d4ec09a to your computer and use it in GitHub Desktop.
Save jimblandy/94268b0f298160515ce2902a7d4ec09a to your computer and use it in GitHub Desktop.
Working LALRPOP grammar for the lambda calculus
use ::Expr;
use ::app_chain;
grammar;
pub Expr = {
<Fun>,
<App>,
<Prim>,
};
Fun: Box<Expr> = {
"/" <Id> "." <Expr> => Box::new(Expr::Fun(<>)),
};
App: Box<Expr> = {
<Prim+> <Prim> => app_chain(<>),
<Prim+> <Fun> => app_chain(<>),
};
Prim = {
<Var>,
"(" <Expr> ")",
}
Var: Box<Expr> = <Id> => Box::new(Expr::Var(<>));
Id: String = <r"[a-zA-Z_][a-zA-Z0-9_]*"> => <>.to_owned();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment