Define initial grammar
[tiger.ml.git] / tiger / src / lib / tiger / tiger_lexer.mll
index 9e08685..359366f 100644 (file)
@@ -1,5 +1,5 @@
 {
-  open Tiger_parser.Token
+  open Tiger_parser
 
   let comment_level = ref 0
   let string_buf    = Buffer.create 100
@@ -10,9 +10,7 @@ let num = ['0'-'9']
 let newline = '\n' | '\r' | "\n\r"
 
 rule token = parse
-  | eof {
-      None
-  }
+  | eof {EOF}
 
   (* Track line number *)
   | newline {
@@ -26,29 +24,29 @@ rule token = parse
       comment lexbuf
   }
 
-  | ":=" {Some ASSIGN}
-  | "<=" {Some LE}
-  | ">=" {Some GE}
-  | "<>" {Some NEQ}
-  | '&'  {Some AND}
-  | '('  {Some LPAREN}
-  | ')'  {Some RPAREN}
-  | '*'  {Some TIMES}
-  | '+'  {Some PLUS}
-  | '-'  {Some MINUS}
-  | '/'  {Some DIVIDE}
-  | ','  {Some COMMA}
-  | '.'  {Some DOT}
-  | ':'  {Some COLON}
-  | ';'  {Some SEMICOLON}
-  | '>'  {Some GT}
-  | '<'  {Some LT}
-  | '='  {Some EQ}
-  | '['  {Some LBRACK}
-  | ']'  {Some RBRACK}
-  | '{'  {Some LBRACE}
-  | '}'  {Some RBRACE}
-  | '|'  {Some OR}
+  | ":=" {ASSIGN}
+  | "<=" {LE}
+  | ">=" {GE}
+  | "<>" {NEQ}
+  | '&'  {AND}
+  | '('  {LPAREN}
+  | ')'  {RPAREN}
+  | '*'  {TIMES}
+  | '+'  {PLUS}
+  | '-'  {MINUS}
+  | '/'  {DIVIDE}
+  | ','  {COMMA}
+  | '.'  {DOT}
+  | ':'  {COLON}
+  | ';'  {SEMICOLON}
+  | '>'  {GT}
+  | '<'  {LT}
+  | '='  {EQ}
+  | '['  {LBRACK}
+  | ']'  {RBRACK}
+  | '{'  {LBRACE}
+  | '}'  {RBRACE}
+  | '|'  {OR}
 
   (* String literal *)
   | '"' {
@@ -61,29 +59,29 @@ rule token = parse
   }
 
   | (num+ as int) {
-    Some (INT (int_of_string int))
+    INT (int_of_string int)
   }
 
   | (alpha (alpha | num | '_')* as id) {
       match id with
-      | "array"    -> Some ARRAY
-      | "break"    -> Some BREAK
-      | "do"       -> Some DO
-      | "else"     -> Some ELSE
-      | "end"      -> Some END
-      | "for"      -> Some FOR
-      | "function" -> Some FUNCTION
-      | "if"       -> Some IF
-      | "in"       -> Some IN
-      | "let"      -> Some LET
-      | "nil"      -> Some NIL
-      | "of"       -> Some OF
-      | "then"     -> Some THEN
-      | "to"       -> Some TO
-      | "type"     -> Some TYPE
-      | "var"      -> Some VAR
-      | "while"    -> Some WHILE
-      | _          -> Some (ID id)
+      | "array"    -> ARRAY
+      | "break"    -> BREAK
+      | "do"       -> DO
+      | "else"     -> ELSE
+      | "end"      -> END
+      | "for"      -> FOR
+      | "function" -> FUNCTION
+      | "if"       -> IF
+      | "in"       -> IN
+      | "let"      -> LET
+      | "nil"      -> NIL
+      | "of"       -> OF
+      | "then"     -> THEN
+      | "to"       -> TO
+      | "type"     -> TYPE
+      | "var"      -> VAR
+      | "while"    -> WHILE
+      | _          -> (ID id)
   }
 and string_literal = parse
   (* Keep escaped quote marks as part of the string literal *)
@@ -95,7 +93,7 @@ and string_literal = parse
   | '"' {
       let string = Buffer.contents string_buf in
       Buffer.reset string_buf;
-      Some (STRING string)
+      STRING string
   }
 
 
@@ -104,10 +102,8 @@ and string_literal = parse
       string_literal lexbuf
   }
 and comment = parse
-  | eof {
-      (* TODO: Error: unterminated comment? or we don't care? *)
-      None
-  }
+  (* TODO: Error: unterminated comment? or we don't care? *)
+  | eof {EOF}
 
   (* Track line number *)
   | newline {
This page took 0.042811 seconds and 4 git commands to generate.