generating token files
This commit is contained in:
parent
8657509bd7
commit
91618eda7f
@ -7,6 +7,35 @@
|
|||||||
(modules token token_type lexer)
|
(modules token token_type lexer)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(executable
|
||||||
|
(name generator)
|
||||||
|
(libraries
|
||||||
|
tezos-utils
|
||||||
|
)
|
||||||
|
(modules generator)
|
||||||
|
)
|
||||||
|
|
||||||
|
(rule
|
||||||
|
(targets token.mly)
|
||||||
|
(deps generator.exe)
|
||||||
|
(action (system "./generator.exe mly > token.mly"))
|
||||||
|
(mode promote-until-clean)
|
||||||
|
)
|
||||||
|
|
||||||
|
(rule
|
||||||
|
(targets token.ml)
|
||||||
|
(deps generator.exe)
|
||||||
|
(action (system "./generator.exe ml > token.ml"))
|
||||||
|
(mode promote-until-clean)
|
||||||
|
)
|
||||||
|
|
||||||
|
(rule
|
||||||
|
(targets lexer.mll)
|
||||||
|
(deps generator.exe)
|
||||||
|
(action (system "./generator.exe mll > lexer.mll"))
|
||||||
|
(mode promote-until-clean)
|
||||||
|
)
|
||||||
|
|
||||||
(rule
|
(rule
|
||||||
(targets token_type.ml token_type.mli)
|
(targets token_type.ml token_type.mli)
|
||||||
(deps token.mly)
|
(deps token.mly)
|
||||||
|
119
src/ligo/multifix/lex/generator.ml
Normal file
119
src/ligo/multifix/lex/generator.ml
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
type pre_token = {
|
||||||
|
name : string ;
|
||||||
|
pattern : string ;
|
||||||
|
}
|
||||||
|
|
||||||
|
let make name pattern = { name ; pattern }
|
||||||
|
|
||||||
|
let keyword = fun k -> make (String.uppercase_ascii k) k
|
||||||
|
let symbol = fun sym name -> make name sym
|
||||||
|
|
||||||
|
module Print_mly = struct
|
||||||
|
open Format
|
||||||
|
|
||||||
|
let token = fun ppf pre_token ->
|
||||||
|
fprintf ppf "%%token %s" pre_token.name
|
||||||
|
|
||||||
|
let tokens = fun ppf tokens ->
|
||||||
|
fprintf ppf "%%token EOF\n" ;
|
||||||
|
fprintf ppf "%%token <int> INT\n" ;
|
||||||
|
fprintf ppf "%%token <string> STRING\n" ;
|
||||||
|
fprintf ppf "%%token <string> NAME\n" ;
|
||||||
|
fprintf ppf "\n%a\n\n" (PP.list_sep token (PP.const "\n")) tokens ;
|
||||||
|
fprintf ppf "%%%%\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
module Print_mll = struct
|
||||||
|
open Format
|
||||||
|
|
||||||
|
let token = fun ppf {name;pattern} ->
|
||||||
|
fprintf ppf "| \"%s\" { %s }" pattern name
|
||||||
|
|
||||||
|
let pre =
|
||||||
|
{pre|{
|
||||||
|
open Token
|
||||||
|
|
||||||
|
exception Error of string
|
||||||
|
exception Unexpected_character of string
|
||||||
|
}
|
||||||
|
|
||||||
|
(* This rule analyzes a single line and turns it into a stream of
|
||||||
|
tokens. *)
|
||||||
|
|
||||||
|
rule token = parse
|
||||||
|
(*
|
||||||
|
| "//" ([^ '\n']* ) (['\n' '\r']+)
|
||||||
|
{ Lexing.new_line lexbuf ; token lexbuf }
|
||||||
|
*)
|
||||||
|
| ('\r'? '\n' '\r'?)
|
||||||
|
{ Lexing.new_line lexbuf; token lexbuf }
|
||||||
|
| [' ' '\t']
|
||||||
|
{ token lexbuf }
|
||||||
|
| ['0'-'9']+ as i
|
||||||
|
{ INT (int_of_string i) }
|
||||||
|
| '"' ( [^ '"' '\\'] | ( '\\' [^ '"'] ) ) as s '"'
|
||||||
|
{ STRING s }
|
||||||
|
|pre}
|
||||||
|
let post =
|
||||||
|
{post|| (['a'-'z']['a'-'z''A'-'Z''0'-'9''_']+) as v
|
||||||
|
{ NAME v }
|
||||||
|
| eof { EOF }
|
||||||
|
| _
|
||||||
|
{ raise (Unexpected_character (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
|
||||||
|
|post}
|
||||||
|
let tokens = fun ppf tokens ->
|
||||||
|
fprintf ppf "%s%a\n%s" pre (PP.list_sep token (PP.const "\n")) tokens post
|
||||||
|
end
|
||||||
|
|
||||||
|
module Print_ml = struct
|
||||||
|
open Format
|
||||||
|
|
||||||
|
let token = fun ppf {name} ->
|
||||||
|
fprintf ppf " | %s -> \"%s\"" name name
|
||||||
|
|
||||||
|
let pre =
|
||||||
|
{pre|include Token_type
|
||||||
|
|
||||||
|
let to_string : token -> string = function
|
||||||
|
| STRING _ -> "STRING"
|
||||||
|
| NAME _ -> "NAME s"
|
||||||
|
| INT _ -> "INT n"
|
||||||
|
| EOF -> "EOF"
|
||||||
|
|pre}
|
||||||
|
|
||||||
|
let tokens = fun ppf tokens ->
|
||||||
|
fprintf ppf "%s%a" pre (PP.list_sep token (PP.const "\n")) tokens
|
||||||
|
end
|
||||||
|
|
||||||
|
let tokens = [
|
||||||
|
keyword "let" ;
|
||||||
|
keyword "in" ;
|
||||||
|
keyword "list" ;
|
||||||
|
keyword "block" ;
|
||||||
|
keyword "for" ;
|
||||||
|
symbol "+" "PLUS" ;
|
||||||
|
symbol "-" "MINUS" ;
|
||||||
|
symbol "*" "TIMES" ;
|
||||||
|
symbol "/" "DIV" ;
|
||||||
|
symbol "=" "EQUAL" ;
|
||||||
|
symbol "[" "LSQUARE" ;
|
||||||
|
symbol "]" "RSQUARE" ;
|
||||||
|
symbol ";" "SEMICOLON" ;
|
||||||
|
]
|
||||||
|
|
||||||
|
let () =
|
||||||
|
let argn = Array.length Sys.argv in
|
||||||
|
if argn = 1 then exit 1 ;
|
||||||
|
let arg = Sys.argv.(1) in
|
||||||
|
match arg with
|
||||||
|
| "mll" -> (
|
||||||
|
Format.printf "%a@.%a\n" PP.comment "Generated .mll" Print_mll.tokens tokens
|
||||||
|
)
|
||||||
|
| "mly" -> (
|
||||||
|
Format.printf "%a@.%a\n" PP.comment "Generated .mly" Print_mly.tokens tokens
|
||||||
|
)
|
||||||
|
| "ml" -> (
|
||||||
|
Format.printf "%a@.%a\n" PP.comment "Generated .ml" Print_ml.tokens tokens
|
||||||
|
)
|
||||||
|
| _ -> exit 1
|
||||||
|
|
@ -1,410 +0,0 @@
|
|||||||
# 1 "lexer.mll"
|
|
||||||
|
|
||||||
open Token
|
|
||||||
|
|
||||||
exception Error of string
|
|
||||||
exception Unexpected_character of string
|
|
||||||
|
|
||||||
# 9 "lexer.ml"
|
|
||||||
let __ocaml_lex_tables = {
|
|
||||||
Lexing.lex_base =
|
|
||||||
"\000\000\238\255\239\255\075\000\241\255\242\255\243\255\244\255\
|
|
||||||
\245\255\246\255\247\255\248\255\160\000\235\000\041\000\014\000\
|
|
||||||
\254\255\001\000\001\000\255\255\038\000\001\000\252\255\054\001\
|
|
||||||
\129\001\204\001\023\002\098\002\173\002\248\002";
|
|
||||||
Lexing.lex_backtrk =
|
|
||||||
"\255\255\255\255\255\255\017\000\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\017\000\017\000\017\000\002\000\
|
|
||||||
\255\255\000\000\017\000\255\255\255\255\255\255\255\255\015\000\
|
|
||||||
\015\000\015\000\004\000\015\000\006\000\005\000";
|
|
||||||
Lexing.lex_default =
|
|
||||||
"\001\000\000\000\000\000\255\255\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\255\255\255\255\021\000\255\255\
|
|
||||||
\000\000\255\255\255\255\000\000\021\000\255\255\000\000\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255";
|
|
||||||
Lexing.lex_trans =
|
|
||||||
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\016\000\017\000\017\000\000\000\018\000\019\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\016\000\000\000\014\000\022\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\006\000\008\000\000\000\007\000\000\000\005\000\
|
|
||||||
\015\000\015\000\015\000\015\000\015\000\015\000\015\000\015\000\
|
|
||||||
\015\000\015\000\000\000\009\000\000\000\004\000\015\000\015\000\
|
|
||||||
\015\000\015\000\015\000\015\000\015\000\015\000\015\000\015\000\
|
|
||||||
\255\255\000\000\000\000\255\255\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\011\000\000\000\010\000\000\000\000\000\
|
|
||||||
\000\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\012\000\003\000\003\000\013\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\020\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\000\000\000\000\
|
|
||||||
\000\000\000\000\023\000\000\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\000\000\000\000\000\000\000\000\023\000\
|
|
||||||
\002\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\029\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\000\000\255\255\000\000\
|
|
||||||
\000\000\255\255\000\000\000\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\000\000\000\000\
|
|
||||||
\000\000\000\000\023\000\000\000\023\000\023\000\023\000\023\000\
|
|
||||||
\025\000\023\000\023\000\023\000\024\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\000\000\000\000\000\000\000\000\023\000\000\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\000\000\000\000\000\000\000\000\
|
|
||||||
\023\000\000\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\027\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\000\000\
|
|
||||||
\000\000\000\000\000\000\023\000\000\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\026\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\000\000\000\000\000\000\000\000\023\000\000\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\000\000\000\000\000\000\
|
|
||||||
\000\000\023\000\000\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\028\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\000\000\000\000\000\000\000\000\023\000\000\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\000\000\000\000\000\000\000\000\023\000\
|
|
||||||
\000\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000";
|
|
||||||
Lexing.lex_check =
|
|
||||||
"\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\000\000\000\000\018\000\255\255\000\000\017\000\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\000\000\255\255\000\000\021\000\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\000\000\000\000\255\255\000\000\255\255\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\255\255\000\000\255\255\000\000\015\000\015\000\
|
|
||||||
\015\000\015\000\015\000\015\000\015\000\015\000\015\000\015\000\
|
|
||||||
\020\000\255\255\255\255\014\000\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\000\000\255\255\000\000\255\255\255\255\
|
|
||||||
\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
|
|
||||||
\000\000\000\000\000\000\003\000\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\003\000\003\000\014\000\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\003\000\003\000\003\000\255\255\255\255\
|
|
||||||
\255\255\255\255\003\000\255\255\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\003\000\003\000\003\000\003\000\003\000\
|
|
||||||
\003\000\003\000\003\000\003\000\003\000\003\000\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\012\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\
|
|
||||||
\012\000\012\000\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\012\000\012\000\012\000\012\000\012\000\012\000\012\000\
|
|
||||||
\012\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\
|
|
||||||
\012\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\
|
|
||||||
\012\000\012\000\012\000\255\255\255\255\255\255\255\255\012\000\
|
|
||||||
\000\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\
|
|
||||||
\012\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\
|
|
||||||
\012\000\012\000\012\000\012\000\012\000\012\000\012\000\012\000\
|
|
||||||
\012\000\012\000\012\000\013\000\013\000\013\000\013\000\013\000\
|
|
||||||
\013\000\013\000\013\000\013\000\013\000\255\255\020\000\255\255\
|
|
||||||
\255\255\014\000\255\255\255\255\013\000\013\000\013\000\013\000\
|
|
||||||
\013\000\013\000\013\000\013\000\013\000\013\000\013\000\013\000\
|
|
||||||
\013\000\013\000\013\000\013\000\013\000\013\000\013\000\013\000\
|
|
||||||
\013\000\013\000\013\000\013\000\013\000\013\000\255\255\255\255\
|
|
||||||
\255\255\255\255\013\000\255\255\013\000\013\000\013\000\013\000\
|
|
||||||
\013\000\013\000\013\000\013\000\013\000\013\000\013\000\013\000\
|
|
||||||
\013\000\013\000\013\000\013\000\013\000\013\000\013\000\013\000\
|
|
||||||
\013\000\013\000\013\000\013\000\013\000\013\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\255\255\255\255\255\255\255\255\023\000\255\255\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\023\000\023\000\023\000\023\000\023\000\023\000\023\000\
|
|
||||||
\023\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\
|
|
||||||
\024\000\024\000\024\000\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\024\000\024\000\024\000\024\000\024\000\024\000\
|
|
||||||
\024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\
|
|
||||||
\024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\
|
|
||||||
\024\000\024\000\024\000\024\000\255\255\255\255\255\255\255\255\
|
|
||||||
\024\000\255\255\024\000\024\000\024\000\024\000\024\000\024\000\
|
|
||||||
\024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\
|
|
||||||
\024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\
|
|
||||||
\024\000\024\000\024\000\024\000\025\000\025\000\025\000\025\000\
|
|
||||||
\025\000\025\000\025\000\025\000\025\000\025\000\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\025\000\025\000\025\000\
|
|
||||||
\025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\
|
|
||||||
\025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\
|
|
||||||
\025\000\025\000\025\000\025\000\025\000\025\000\025\000\255\255\
|
|
||||||
\255\255\255\255\255\255\025\000\255\255\025\000\025\000\025\000\
|
|
||||||
\025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\
|
|
||||||
\025\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\
|
|
||||||
\025\000\025\000\025\000\025\000\025\000\025\000\025\000\026\000\
|
|
||||||
\026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
|
|
||||||
\026\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
|
|
||||||
\026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
|
|
||||||
\026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
|
|
||||||
\026\000\026\000\255\255\255\255\255\255\255\255\026\000\255\255\
|
|
||||||
\026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
|
|
||||||
\026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
|
|
||||||
\026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
|
|
||||||
\026\000\026\000\027\000\027\000\027\000\027\000\027\000\027\000\
|
|
||||||
\027\000\027\000\027\000\027\000\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\027\000\027\000\027\000\027\000\027\000\
|
|
||||||
\027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\
|
|
||||||
\027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\
|
|
||||||
\027\000\027\000\027\000\027\000\027\000\255\255\255\255\255\255\
|
|
||||||
\255\255\027\000\255\255\027\000\027\000\027\000\027\000\027\000\
|
|
||||||
\027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\
|
|
||||||
\027\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\
|
|
||||||
\027\000\027\000\027\000\027\000\027\000\028\000\028\000\028\000\
|
|
||||||
\028\000\028\000\028\000\028\000\028\000\028\000\028\000\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\028\000\028\000\
|
|
||||||
\028\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
|
|
||||||
\028\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
|
|
||||||
\028\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
|
|
||||||
\255\255\255\255\255\255\255\255\028\000\255\255\028\000\028\000\
|
|
||||||
\028\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
|
|
||||||
\028\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
|
|
||||||
\028\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
|
|
||||||
\029\000\029\000\029\000\029\000\029\000\029\000\029\000\029\000\
|
|
||||||
\029\000\029\000\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\029\000\029\000\029\000\029\000\029\000\029\000\029\000\
|
|
||||||
\029\000\029\000\029\000\029\000\029\000\029\000\029\000\029\000\
|
|
||||||
\029\000\029\000\029\000\029\000\029\000\029\000\029\000\029\000\
|
|
||||||
\029\000\029\000\029\000\255\255\255\255\255\255\255\255\029\000\
|
|
||||||
\255\255\029\000\029\000\029\000\029\000\029\000\029\000\029\000\
|
|
||||||
\029\000\029\000\029\000\029\000\029\000\029\000\029\000\029\000\
|
|
||||||
\029\000\029\000\029\000\029\000\029\000\029\000\029\000\029\000\
|
|
||||||
\029\000\029\000\029\000\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
|
|
||||||
\255\255";
|
|
||||||
Lexing.lex_base_code =
|
|
||||||
"";
|
|
||||||
Lexing.lex_backtrk_code =
|
|
||||||
"";
|
|
||||||
Lexing.lex_default_code =
|
|
||||||
"";
|
|
||||||
Lexing.lex_trans_code =
|
|
||||||
"";
|
|
||||||
Lexing.lex_check_code =
|
|
||||||
"";
|
|
||||||
Lexing.lex_code =
|
|
||||||
"";
|
|
||||||
}
|
|
||||||
|
|
||||||
let rec token lexbuf =
|
|
||||||
__ocaml_lex_token_rec lexbuf 0
|
|
||||||
and __ocaml_lex_token_rec lexbuf __ocaml_lex_state =
|
|
||||||
match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
|
|
||||||
| 0 ->
|
|
||||||
# 17 "lexer.mll"
|
|
||||||
( Lexing.new_line lexbuf; token lexbuf )
|
|
||||||
# 305 "lexer.ml"
|
|
||||||
|
|
||||||
| 1 ->
|
|
||||||
# 19 "lexer.mll"
|
|
||||||
( token lexbuf )
|
|
||||||
# 310 "lexer.ml"
|
|
||||||
|
|
||||||
| 2 ->
|
|
||||||
let
|
|
||||||
# 20 "lexer.mll"
|
|
||||||
i
|
|
||||||
# 316 "lexer.ml"
|
|
||||||
= Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in
|
|
||||||
# 21 "lexer.mll"
|
|
||||||
( INT (int_of_string i) )
|
|
||||||
# 320 "lexer.ml"
|
|
||||||
|
|
||||||
| 3 ->
|
|
||||||
let
|
|
||||||
# 22 "lexer.mll"
|
|
||||||
s
|
|
||||||
# 326 "lexer.ml"
|
|
||||||
= Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos (lexbuf.Lexing.lex_curr_pos + -1) in
|
|
||||||
# 23 "lexer.mll"
|
|
||||||
( STRING s )
|
|
||||||
# 330 "lexer.ml"
|
|
||||||
|
|
||||||
| 4 ->
|
|
||||||
# 24 "lexer.mll"
|
|
||||||
( LET )
|
|
||||||
# 335 "lexer.ml"
|
|
||||||
|
|
||||||
| 5 ->
|
|
||||||
# 25 "lexer.mll"
|
|
||||||
( IN )
|
|
||||||
# 340 "lexer.ml"
|
|
||||||
|
|
||||||
| 6 ->
|
|
||||||
# 26 "lexer.mll"
|
|
||||||
( LIST )
|
|
||||||
# 345 "lexer.ml"
|
|
||||||
|
|
||||||
| 7 ->
|
|
||||||
# 27 "lexer.mll"
|
|
||||||
( LSQUARE )
|
|
||||||
# 350 "lexer.ml"
|
|
||||||
|
|
||||||
| 8 ->
|
|
||||||
# 28 "lexer.mll"
|
|
||||||
( RSQUARE )
|
|
||||||
# 355 "lexer.ml"
|
|
||||||
|
|
||||||
| 9 ->
|
|
||||||
# 29 "lexer.mll"
|
|
||||||
( SEMICOLON )
|
|
||||||
# 360 "lexer.ml"
|
|
||||||
|
|
||||||
| 10 ->
|
|
||||||
# 30 "lexer.mll"
|
|
||||||
( PLUS )
|
|
||||||
# 365 "lexer.ml"
|
|
||||||
|
|
||||||
| 11 ->
|
|
||||||
# 31 "lexer.mll"
|
|
||||||
( MINUS )
|
|
||||||
# 370 "lexer.ml"
|
|
||||||
|
|
||||||
| 12 ->
|
|
||||||
# 32 "lexer.mll"
|
|
||||||
( TIMES )
|
|
||||||
# 375 "lexer.ml"
|
|
||||||
|
|
||||||
| 13 ->
|
|
||||||
# 33 "lexer.mll"
|
|
||||||
( DIV )
|
|
||||||
# 380 "lexer.ml"
|
|
||||||
|
|
||||||
| 14 ->
|
|
||||||
# 34 "lexer.mll"
|
|
||||||
( EQUAL )
|
|
||||||
# 385 "lexer.ml"
|
|
||||||
|
|
||||||
| 15 ->
|
|
||||||
let
|
|
||||||
# 35 "lexer.mll"
|
|
||||||
v
|
|
||||||
# 391 "lexer.ml"
|
|
||||||
= Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in
|
|
||||||
# 36 "lexer.mll"
|
|
||||||
( NAME v )
|
|
||||||
# 395 "lexer.ml"
|
|
||||||
|
|
||||||
| 16 ->
|
|
||||||
# 37 "lexer.mll"
|
|
||||||
( EOF )
|
|
||||||
# 400 "lexer.ml"
|
|
||||||
|
|
||||||
| 17 ->
|
|
||||||
# 39 "lexer.mll"
|
|
||||||
( raise (Unexpected_character (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) )
|
|
||||||
# 405 "lexer.ml"
|
|
||||||
|
|
||||||
| __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
|
|
||||||
__ocaml_lex_token_rec lexbuf __ocaml_lex_state
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
{
|
|
||||||
open Token
|
|
||||||
|
|
||||||
exception Error of string
|
|
||||||
exception Unexpected_character of string
|
|
||||||
}
|
|
||||||
|
|
||||||
(* This rule analyzes a single line and turns it into a stream of
|
|
||||||
tokens. *)
|
|
||||||
|
|
||||||
rule token = parse
|
|
||||||
(*
|
|
||||||
| "//" ([^ '\n']* ) (['\n' '\r']+)
|
|
||||||
{ Lexing.new_line lexbuf ; token lexbuf }
|
|
||||||
*)
|
|
||||||
| ('\r'? '\n' '\r'?)
|
|
||||||
{ Lexing.new_line lexbuf; token lexbuf }
|
|
||||||
| [' ' '\t']
|
|
||||||
{ token lexbuf }
|
|
||||||
| ['0'-'9']+ as i
|
|
||||||
{ INT (int_of_string i) }
|
|
||||||
| '"' ( [^ '"' '\\'] | ( '\\' [^ '"'] ) ) as s '"'
|
|
||||||
{ STRING s }
|
|
||||||
| "let" { LET }
|
|
||||||
| "in" { IN }
|
|
||||||
| "list" { LIST }
|
|
||||||
| "[" { LSQUARE }
|
|
||||||
| "]" { RSQUARE }
|
|
||||||
| ";" { SEMICOLON }
|
|
||||||
| "+" { PLUS }
|
|
||||||
| "-" { MINUS }
|
|
||||||
| "*" { TIMES }
|
|
||||||
| "/" { DIV }
|
|
||||||
| "=" { EQUAL }
|
|
||||||
| (['a'-'z']['a'-'z''A'-'Z''0'-'9''_']+) as v
|
|
||||||
{ NAME v }
|
|
||||||
| eof { EOF }
|
|
||||||
| _
|
|
||||||
{ raise (Unexpected_character (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
|
|
@ -1,18 +0,0 @@
|
|||||||
include Token_type
|
|
||||||
|
|
||||||
let to_string : token -> string = function
|
|
||||||
| TIMES -> "TIMES"
|
|
||||||
| STRING _ -> "STRING"
|
|
||||||
| NAME _ -> "NAME s"
|
|
||||||
| INT _ -> "INT n"
|
|
||||||
| SEMICOLON -> "SEMICOLON"
|
|
||||||
| RSQUARE -> "RSQUARE"
|
|
||||||
| PLUS -> "PLUS"
|
|
||||||
| MINUS -> "MINUS"
|
|
||||||
| LSQUARE -> "LSQUARE"
|
|
||||||
| LIST -> "LIST"
|
|
||||||
| LET -> "LET"
|
|
||||||
| IN -> "IN"
|
|
||||||
| EQUAL -> "EQUAL"
|
|
||||||
| EOF -> "EOF"
|
|
||||||
| DIV -> "DIV"
|
|
@ -1,9 +0,0 @@
|
|||||||
%token EOF
|
|
||||||
%token <int> INT
|
|
||||||
%token <string> STRING
|
|
||||||
%token <string> NAME
|
|
||||||
%token LET IN EQUAL
|
|
||||||
%token PLUS MINUS TIMES DIV
|
|
||||||
%token LIST LSQUARE RSQUARE SEMICOLON
|
|
||||||
|
|
||||||
%%
|
|
@ -1,17 +0,0 @@
|
|||||||
|
|
||||||
type token =
|
|
||||||
| TIMES
|
|
||||||
| STRING of (string)
|
|
||||||
| SEMICOLON
|
|
||||||
| RSQUARE
|
|
||||||
| PLUS
|
|
||||||
| NAME of (string)
|
|
||||||
| MINUS
|
|
||||||
| LSQUARE
|
|
||||||
| LIST
|
|
||||||
| LET
|
|
||||||
| INT of (int)
|
|
||||||
| IN
|
|
||||||
| EQUAL
|
|
||||||
| EOF
|
|
||||||
| DIV
|
|
@ -1,19 +0,0 @@
|
|||||||
|
|
||||||
(* The type of tokens. *)
|
|
||||||
|
|
||||||
type token =
|
|
||||||
| TIMES
|
|
||||||
| STRING of (string)
|
|
||||||
| SEMICOLON
|
|
||||||
| RSQUARE
|
|
||||||
| PLUS
|
|
||||||
| NAME of (string)
|
|
||||||
| MINUS
|
|
||||||
| LSQUARE
|
|
||||||
| LIST
|
|
||||||
| LET
|
|
||||||
| INT of (int)
|
|
||||||
| IN
|
|
||||||
| EQUAL
|
|
||||||
| EOF
|
|
||||||
| DIV
|
|
@ -1,39 +0,0 @@
|
|||||||
{
|
|
||||||
open Token
|
|
||||||
|
|
||||||
exception Error of string
|
|
||||||
exception Unexpected_character of string
|
|
||||||
}
|
|
||||||
|
|
||||||
(* This rule analyzes a single line and turns it into a stream of
|
|
||||||
tokens. *)
|
|
||||||
|
|
||||||
rule token = parse
|
|
||||||
(*
|
|
||||||
| "//" ([^ '\n']* ) (['\n' '\r']+)
|
|
||||||
{ Lexing.new_line lexbuf ; token lexbuf }
|
|
||||||
*)
|
|
||||||
| ('\r'? '\n' '\r'?)
|
|
||||||
{ Lexing.new_line lexbuf; token lexbuf }
|
|
||||||
| [' ' '\t']
|
|
||||||
{ token lexbuf }
|
|
||||||
| ['0'-'9']+ as i
|
|
||||||
{ INT (int_of_string i) }
|
|
||||||
| '"' ( [^ '"' '\\'] | ( '\\' [^ '"'] ) ) as s '"'
|
|
||||||
{ STRING s }
|
|
||||||
| (['a'-'z']['a'-'z''A'-'Z''0'-'9''_']+) as v
|
|
||||||
{ NAME v }
|
|
||||||
| "let" { LET }
|
|
||||||
| "in" { IN }
|
|
||||||
| "list" { LIST }
|
|
||||||
| "[" { LSQUARE }
|
|
||||||
| "]" { RSQUARE }
|
|
||||||
| ";" { SEMICOLON }
|
|
||||||
| "+" { PLUS }
|
|
||||||
| "-" { MINUS }
|
|
||||||
| "*" { TIMES }
|
|
||||||
| "/" { DIV }
|
|
||||||
| "=" { EQUAL }
|
|
||||||
| eof { EOF }
|
|
||||||
| _
|
|
||||||
{ raise (Unexpected_character (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
|
|
@ -1,9 +0,0 @@
|
|||||||
%token EOF
|
|
||||||
%token <int> INT
|
|
||||||
%token <string> STRING
|
|
||||||
%token <string> NAME
|
|
||||||
%token LET IN EQUAL
|
|
||||||
%token PLUS MINUS TIMES DIV
|
|
||||||
%token LIST LSQUARE RSQUARE SEMICOLON
|
|
||||||
|
|
||||||
%%
|
|
Loading…
Reference in New Issue
Block a user