#! A parser for lambda expressions, by Matthew Willis #! The grammar in BNF is: #! ::= #! ::= #! ::= ( . ) #! ::= ( ) #! ::= #! ::= : USING: lazy-lists parser-combinators strings sequences kernel ; IN: lambda LAZY: #! parses an uppercase or lowercase letter [ letter? ] satisfy [ 1string ] <@ ; LAZY: #! parses an uppercase or lowercase letter [ LETTER? ] satisfy [ 1string ] <@ ; LAZY: #! parses a number [ digit? ] satisfy [ 1string ] <@ ; LAZY: #! parses an alphanumeral <|> ; LAZY: #! parses an alphanumeral <|> ; LAZY: #! parses an identifier (string for now) #! TODO: do we need to enter it into a symbol table? <*> <&:> [ concat ] <@ ; LAZY: #! parses a name, which is used in replacement <+> [ concat ] <@ ; DEFER: LAZY: ( -- parser ) #! parses (.), the "lambda" expression #! all occurences of are replaced with a pointer to this #! lambda expression. "(" token sp &> "." token sp <& sp <&> ")" token sp <& [ [ first var-node-name ] keep second ] <@ ; LAZY: ( -- parser ) #! parses ( ), the function application "(" token sp &> sp <&> ")" token sp <& [ [ first ] keep second ] <@ ; LAZY: ( -- parser ) #! parses [], the alien invocation #! an alien factor word must be all capital letters and numerals "[" token sp &> "]" token sp <& [ ] <@ ; LAZY: <|> <|> [ ] <@ <|> <|> ; LAZY: ":" token &> sp <&> f succeed <&> <|> "." token &> f succeed <&> <|> ; : lambda-parse some parse force ;