-
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.
Relates to #2
- Loading branch information
Showing
15 changed files
with
486 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ FLG -rectypes | |
FLG -w a | ||
|
||
PKG batteries | ||
PKG menhirLib | ||
PKG num |
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
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,30 @@ | ||
(* -------------------------------------------------------------------- *) | ||
open Core | ||
|
||
module P = Parser | ||
module L = Lexing | ||
|
||
(* -------------------------------------------------------------------- *) | ||
let parserfun_entry = | ||
MenhirLib.Convert.Simplified.traditional2revised P.program | ||
|
||
(* -------------------------------------------------------------------- *) | ||
let lexbuf_from_channel = fun name channel -> | ||
let lexbuf = Lexing.from_channel (IO.to_input_channel channel) in | ||
lexbuf.Lexing.lex_curr_p <- { | ||
Lexing.pos_fname = name; | ||
Lexing.pos_lnum = 1; | ||
Lexing.pos_bol = 0; | ||
Lexing.pos_cnum = 0 | ||
}; | ||
lexbuf | ||
|
||
(* -------------------------------------------------------------------- *) | ||
let lexer (lexbuf : L.lexbuf) = | ||
let token = Lexer.main lexbuf in | ||
(token, L.lexeme_start_p lexbuf, L.lexeme_end_p lexbuf) | ||
|
||
(* -------------------------------------------------------------------- *) | ||
let parse_program ?(name = "") (inc : IO.input) = | ||
let reader = lexbuf_from_channel name inc in | ||
parserfun_entry (fun () -> lexer reader) |
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,2 @@ | ||
(* -------------------------------------------------------------------- *) | ||
val parse_program : ?name:string -> Core.IO.input -> Syntax.pprogram |
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,54 @@ | ||
(* -------------------------------------------------------------------- *) | ||
{ | ||
open Core | ||
open Parser | ||
|
||
module L = Location | ||
|
||
(* ------------------------------------------------------------------ *) | ||
let lex_error lexbuf msg = | ||
let loc = L.of_lexbuf lexbuf in | ||
raise (Syntax.ParseError (Some loc, PE_LexicalError msg)) | ||
|
||
(* ------------------------------------------------------------------ *) | ||
let _keywords = [ | ||
("check", CHECK); | ||
("var" , VAR ); | ||
] | ||
|
||
(* ------------------------------------------------------------------ *) | ||
let keywords = | ||
let table = Hashtbl.create 0 in | ||
List.iter (uncurry (Hashtbl.add table)) _keywords; table | ||
} | ||
|
||
let empty = "" | ||
let blank = [' ' '\t' '\r'] | ||
let newline = '\n' | ||
let upper = ['A'-'Z'] | ||
let lower = ['a'-'z'] | ||
let letter = upper | lower | ||
let digit = ['0'-'9'] | ||
let uint = digit+ | ||
let ichar = (letter | digit | '_' | '\'') | ||
let ident = (letter | '_') ichar* | ||
|
||
(* -------------------------------------------------------------------- *) | ||
rule main = parse | ||
| newline { Lexing.new_line lexbuf; main lexbuf } | ||
| blank+ { main lexbuf } | ||
| ident as id { try Hashtbl.find keywords id with Not_found -> IDENT id } | ||
| digit+ as num { INT (Big_int.big_int_of_string num) } | ||
|
||
| '+' { PLUS } | ||
| '*' { STAR } | ||
| '^' { HAT } | ||
| '(' { LPAREN } | ||
| ')' { RPAREN } | ||
| '{' { LBRACE } | ||
| '}' { RBRACE } | ||
|
||
| eof { EOF } | ||
|
||
| _ as c | ||
{ lex_error lexbuf (Printf.sprintf "illegal character: `%c'" c) } |
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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
utils | ||
groebnerBasis | ||
nc_gasbi | ||
monalg | ||
Core | ||
Location | ||
Lexer | ||
Parser | ||
Syntax | ||
Io | ||
GroebnerBasis | ||
Nc_gasbi | ||
Monalg |
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,85 @@ | ||
(* -------------------------------------------------------------------- *) | ||
open Lexing | ||
|
||
(* -------------------------------------------------------------------- *) | ||
type t = { | ||
loc_fname : string; | ||
loc_start : int * int; | ||
loc_end : int * int; | ||
loc_bchar : int; | ||
loc_echar : int; | ||
} | ||
|
||
let _dummy : t = { | ||
loc_fname = ""; | ||
loc_start = (-1, -1); | ||
loc_end = (-1, -1); | ||
loc_bchar = -1; | ||
loc_echar = -1; | ||
} | ||
|
||
(* -------------------------------------------------------------------- *) | ||
let make (p1 : position) (p2 : position) = | ||
let mkpos (p : position) = | ||
(p.pos_lnum, p.pos_cnum - p.pos_bol) | ||
in | ||
{ loc_fname = p1.pos_fname; | ||
loc_start = mkpos p1 ; | ||
loc_end = mkpos p2 ; | ||
loc_bchar = p1.pos_cnum ; | ||
loc_echar = p2.pos_cnum ; } | ||
|
||
let of_lexbuf (lb : lexbuf) = | ||
let p1 = Lexing.lexeme_start_p lb in | ||
let p2 = Lexing.lexeme_end_p lb in | ||
make p1 p2 | ||
|
||
(* --------------------------------------------------------------------- *) | ||
let merge (p1 : t) (p2 : t) = | ||
{ loc_fname = p1.loc_fname; | ||
loc_start = min p1.loc_start p2.loc_start; | ||
loc_end = max p1.loc_end p2.loc_end ; | ||
loc_bchar = min p1.loc_bchar p2.loc_bchar; | ||
loc_echar = max p1.loc_echar p2.loc_echar; } | ||
|
||
let mergeall (p : t list) = | ||
match p with | ||
| [] -> _dummy | ||
| t :: ts -> List.fold_left merge t ts | ||
|
||
let isdummy (p : t) = | ||
p.loc_bchar < 0 || p.loc_echar < 0 | ||
|
||
(* --------------------------------------------------------------------- *) | ||
let tostring (p : t) = | ||
let spos = | ||
if p.loc_start = p.loc_end then | ||
Printf.sprintf "line %d (%d)" | ||
(fst p.loc_start) (snd p.loc_start) | ||
else if fst p.loc_start = fst p.loc_end then | ||
Printf.sprintf "line %d (%d-%d)" | ||
(fst p.loc_start) (snd p.loc_start) (snd p.loc_end) | ||
else | ||
Printf.sprintf "line %d (%d) to line %d (%d)" | ||
(fst p.loc_start) (snd p.loc_start) | ||
(fst p.loc_end ) (snd p.loc_end ) | ||
in | ||
|
||
if p.loc_fname <> "" then | ||
Printf.sprintf "%s: %s" p.loc_fname spos | ||
else | ||
spos | ||
|
||
(* -------------------------------------------------------------------- *) | ||
type 'a loced = { plloc : t; pldesc : 'a; } | ||
|
||
(* -------------------------------------------------------------------- *) | ||
let loc x = x.plloc | ||
let unloc x = x.pldesc | ||
let unlocs x = List.map unloc x | ||
|
||
let lmap (f : 'a -> 'b) (x : 'a loced) = | ||
{ x with pldesc = f x.pldesc } | ||
|
||
let mkloc (loc : t) (x : 'a) : 'a loced = | ||
{ plloc = loc; pldesc = x; } |
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,30 @@ | ||
(* -------------------------------------------------------------------- *) | ||
open Lexing | ||
|
||
(* -------------------------------------------------------------------- *) | ||
type t = { | ||
loc_fname : string; | ||
loc_start : int * int; | ||
loc_end : int * int; | ||
loc_bchar : int; | ||
loc_echar : int; | ||
} | ||
|
||
(* -------------------------------------------------------------------- *) | ||
val _dummy : t | ||
val make : position -> position -> t | ||
val of_lexbuf : lexbuf -> t | ||
|
||
val merge : t -> t -> t | ||
val mergeall : t list -> t | ||
|
||
val tostring : t -> string | ||
|
||
(* -------------------------------------------------------------------- *) | ||
type 'a loced = { plloc : t; pldesc : 'a; } | ||
|
||
val mkloc : t -> 'a -> 'a loced | ||
val loc : 'a loced -> t | ||
val unloc : 'a loced -> 'a | ||
val unlocs : ('a loced) list -> 'a list | ||
val lmap : ('a -> 'b) -> 'a loced -> 'b loced |
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
Oops, something went wrong.