-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
409 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
all: | ||
ocamlyacc parser.mly | ||
rm parser.mli | ||
ocamllex lexer.mll | ||
ocamlc syntax.ml parser.ml lexer.ml main.ml | ||
|
||
clean: | ||
rm -f *.cm* parser.ml lexer.ml a.out |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ | ||
open Parser | ||
} | ||
|
||
let space = [' ' '\t' '\n' '\r'] | ||
let digit = ['0'-'9'] | ||
let lower = ['a'-'z'] | ||
let upper = ['A'-'Z'] | ||
|
||
rule token = parse | ||
| space+ { token lexbuf } | ||
| "(*" { comment lexbuf; token lexbuf } | ||
| '(' { LPAREN } | ||
| ')' { RPAREN } | ||
| '[' { LBRACK } | ||
| ']' { RBRACK } | ||
| "::" { CONS } | ||
| '@' { AT } | ||
| "as" { AS } | ||
| "begin" { BEGIN } | ||
| "end" { END } | ||
| "match" { MATCH } | ||
| "with" { WITH } | ||
| "when" { WHEN } | ||
| "->" { ARROW } | ||
| "|" { BAR } | ||
| "type" { TYPE } | ||
| "of" { OF } | ||
| ";;" { SEMISEMI } | ||
| "true" { BOOL("true") } | ||
| "false" { BOOL("false") } | ||
| "not" { NOT } | ||
| digit+ { INT(Lexing.lexeme lexbuf) } | ||
| digit+ ('.' digit*)? (['e' 'E'] ['+' '-']? digit+)? | ||
{ FLOAT(Lexing.lexeme lexbuf) } | ||
| '-' { MINUS } | ||
| '+' { PLUS } | ||
| '*' { AST } | ||
| "-." { MINUS_DOT } | ||
| "+." { PLUS_DOT } | ||
| "*." { AST_DOT } | ||
| "/." { SLASH_DOT } | ||
| '=' { EQUAL } | ||
| "<>" { LESS_GREATER } | ||
| "<=" { LESS_EQUAL } | ||
| ">=" { GREATER_EQUAL } | ||
| '<' { LESS } | ||
| '>' { GREATER } | ||
| "if" { IF } | ||
| "then" { THEN } | ||
| "else" { ELSE } | ||
| "let" { LET } | ||
| "in" { IN } | ||
| "rec" { REC } | ||
| "mutable" { MUTABLE } | ||
| "open" { OPEN } | ||
| '{' { LBRACE } | ||
| '}' { RBRACE } | ||
| ':' { COLON } | ||
| ',' { COMMA } | ||
| '_' { IDENT("_") } | ||
| '.' { DOT } | ||
| "<-" { LESS_MINUS } | ||
| ":=" { COLON_EQUAL } | ||
| '!' { EXCLAM } | ||
| ';' { SEMICOLON } | ||
| eof { EOF } | ||
| '"' ([^ '"' '\\'] | '\\' _)* '"' { let s = Lexing.lexeme lexbuf in STRING(String.sub s 1 ((String.length s)-2))} | ||
|
||
| upper (digit|lower|upper|'_')* '.' lower (digit|lower|upper|'_')* { IDENT(Lexing.lexeme lexbuf) } | ||
| upper (digit|lower|upper|'_')* { CIDENT(Lexing.lexeme lexbuf) } | ||
| lower (digit|lower|upper|'_')* { IDENT(Lexing.lexeme lexbuf) } | ||
| _ { | ||
failwith | ||
(Printf.sprintf "unknown token %s near characters %d-%d" | ||
(Lexing.lexeme lexbuf) | ||
(Lexing.lexeme_start lexbuf) | ||
(Lexing.lexeme_end lexbuf)) } | ||
and comment = parse | ||
| "*)" { () } | ||
| "(*" { comment lexbuf; comment lexbuf } | ||
| eof { Format.eprintf "warning: unterminated comment@." } | ||
| _ { comment lexbuf } |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
let lexbuf outchan l = | ||
(Parser.exp Lexer.token l) | ||
|
||
let string s = lexbuf stdout (Lexing.from_string s) | ||
|
||
let file f = | ||
let inchan = open_in (f ^ ".ml") in | ||
let outchan = open_out (f ^ ".js") in | ||
try | ||
lexbuf outchan (Lexing.from_channel inchan); | ||
close_in inchan; | ||
close_out outchan; | ||
with e -> (close_in inchan; close_out outchan; raise e) | ||
|
||
let () = | ||
let files = ref [] in | ||
Arg.parse | ||
[] | ||
(fun s -> files := !files @ [s]) | ||
("Min-Caml beautifier\n" ^ | ||
Printf.sprintf "usage: %s ...filenames without \".ml\"..." Sys.argv.(0)); | ||
List.iter | ||
(fun f -> ignore (file f)) | ||
!files |
Oops, something went wrong.