diff lab0/lexer.mll @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lab0/lexer.mll	Thu Oct 05 08:04:15 2017 +0100
@@ -0,0 +1,26 @@
+(* lab1/lexer.mll *)
+(* Copyright (c) 2017 J. M. Spivey *)
+
+{
+open Parser 
+open Lexing
+}
+
+rule token = 
+  parse
+      ['A'-'Z''a'-'z']['A'-'Z''a'-'z''0'-'9''_']* as s
+                        { IDENT s }
+    | ['0'-'9']+("."['0'-'9']+)? as s
+                        { NUMBER (float_of_string s) }
+    | "("               { OPEN }
+    | ")"               { CLOSE }
+    | "="               { EQUAL }
+    | "+"               { PLUS }
+    | "-"               { MINUS }
+    | "*"               { TIMES }
+    | "/"               { DIVIDE }
+    | [' ''\t']+        { token lexbuf }
+    | "\n"              { token lexbuf }
+    | _                 { BADTOK }
+    | eof               { EOF }
+