]> git.kianting.info Git - uann/blobdiff - ocaml_yacc/lexer.mll
add ocaml EoC ast viewet
[uann] / ocaml_yacc / lexer.mll
diff --git a/ocaml_yacc/lexer.mll b/ocaml_yacc/lexer.mll
new file mode 100644 (file)
index 0000000..a134e2e
--- /dev/null
@@ -0,0 +1,22 @@
+(* File lexer.mll *)
+{
+open Parser(* The type token is defined in parser.mli *)
+exception Eof
+}
+rule token = parse
+    [' ' '\t']     { token lexbuf }     (* skip blanks *)
+  | ['\n' ]{ EOL }
+  | ['i']['n']    { IN }
+  | ('_'|['a'-'z']|['A'-'Z']) as lxm { ID((String.make 1 lxm)) }
+  | ('_'|['a'-'z']|['A'-'Z'])(['0'-'9']|'_'|['a'-'z']|['A'-'Z'])+ as lxm { ID(lxm) }
+  | ['0'-'9']+ as lxm { INT(lxm) }
+  | '+'    { PLUS }
+  | '-'    { MINUS }
+  | '*'    { TIMES }
+  | '/'    { DIV }
+  | '('    { LPAREN }
+  | ')'    { RPAREN }
+  | ['-']['>']    { IMPLY }
+  | ['=']['>']    { FUNC }
+  | '='    { ASSIGN }
+  | eof    { raise Eof }