Created
October 24, 2013 15:42
-
-
Save pasberth/7139535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
open Parser | |
} | |
rule token = parse | |
[' ' '\t'] { token lexbuf } | |
| ['a'-'z' 'A'-'Z'] { IDENT(Lexing.lexeme lexbuf) } | |
| '\\' { LAMBDA } | |
| '.' { DOT } | |
| ':' '=' { ASSIGN } | |
| ['\n'] { EOL } | |
| '(' { OPEN } | |
| ')' { CLOSE } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE_OCAMLFIND = true | |
OCAMLPACKS[] = | |
llvm | |
FILES[] = | |
types | |
lambda | |
parser | |
lexer | |
OCamlProgram(lambda, $(FILES)) | |
OCamlGeneratedFiles(parser.ml lexer.ml) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open build/OCaml | |
.SUBDIRS: . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
%} | |
%token <string> IDENT | |
%token LAMBDA | |
%token DOT | |
%token ASSIGN | |
%token EOL | |
%token OPEN | |
%token CLOSE | |
%start main | |
%type <Types.stat> main | |
%% | |
main: | |
stat EOL { $1 } | |
stat: | |
IDENT ASSIGN expr { Types.Def($1, $3) } | |
| IDENT ASSIGN app { Types.Def($1, $3) } | |
| IDENT ASSIGN lam { Types.Def($1, $3) } | |
expr: | |
ref { $1 } | |
| OPEN app CLOSE { $2 } | |
| OPEN lam CLOSE { $2 } | |
| OPEN expr CLOSE { $2 } | |
ref: | |
IDENT { Types.Ref($1) } | |
lam: | |
LAMBDA param_list DOT expr { List.fold_right (fun x y -> Types.Lam(x, y)) $2 $4 } | |
| LAMBDA param_list DOT app { List.fold_right (fun x y -> Types.Lam(x, y)) $2 $4 } | |
param_list: | |
IDENT { [$1] } | |
| IDENT param_list { $1 :: $2 } | |
app: | |
expr expr { Types.App($1, $2) } | |
| app expr { Types.App($1, $2) } | |
%% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ast = | |
| Ref of (string) | |
| Lam of (string * ast) | |
| App of (ast * ast) | |
type stat = | |
| Def of (string * ast) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment