]> Joshua Wise's Git repositories - snipe.git/blobdiff - parse/l5.lex
Initial import of l5c
[snipe.git] / parse / l5.lex
similarity index 86%
rename from parse/l4.lex
rename to parse/l5.lex
index b988c3548851c533e6bb2215a7380305a961e7ca..e10f8b7da384d198bb047cce7e2c8f06a21fb1c4 100644 (file)
@@ -1,4 +1,4 @@
-(* L4 Compiler
+(* L5 Compiler
  * Lexer
  * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
  * Modified: Frank Pfenning <fp@cs.cmu.edu>
@@ -41,6 +41,22 @@ in
                       Tokens.INTNUM (Word32Signed.ZERO, yyp, yyp + size yyt) )
           | SOME n => Tokens.INTNUM (n,yyp,yyp + size yyt)
       end
+  fun hexnumber (yyt, yyp) =
+      let
+        val t = String.extract (yyt, 2, NONE)
+        val ext = ParseState.ext (yyp, yyp + size yyt)
+       val numOpt = StringCvt.scanString (Word32.scan StringCvt.HEX) t
+                     handle Overflow =>
+                           ( ErrorMsg.error ext
+                                ("integral constant `" ^ yyt ^ "' too large") ;
+                             NONE )
+      in
+       case numOpt
+         of NONE => ( ErrorMsg.error ext
+                         ("cannot parse integral constant `" ^ yyt ^ "'");
+                      Tokens.INTNUM (Word32Signed.ZERO, yyp, yyp + size yyt) )
+          | SOME n => Tokens.INTNUM (n,yyp,yyp + size yyt)
+      end
 
   fun eof () = 
       ( if (!commentLevel > 0)
@@ -51,12 +67,13 @@ in
 end
 
 %%
-%header (functor L4LexFn(structure Tokens : L4_TOKENS));
+%header (functor L5LexFn(structure Tokens : L5_TOKENS));
 %full
 %s COMMENT COMMENT_LINE;
 
 id = [A-Za-z_][A-Za-z0-9_]*;
 decnum = [0-9][0-9]*;
+hexnum = 0x[0-9a-fA-F][0-9a-fA-F]*;
 
 ws = [\ \t\012];
 
@@ -84,6 +101,9 @@ ws = [\ \t\012];
 <INITIAL> "^="        => (Tokens.BITXOREQ (yypos, yypos + size yytext));
 <INITIAL> "|="        => (Tokens.BITOREQ (yypos, yypos + size yytext));
 
+<INITIAL> "++"         => (Tokens.PLUSPLUS (yypos, yypos + size yytext));
+<INITIAL> "--"         => (Tokens.MINUSMINUS (yypos, yypos + size yytext));
+
 <INITIAL> "+"         => (Tokens.PLUS (yypos, yypos + size yytext));
 <INITIAL> "-"         => (Tokens.MINUS (yypos, yypos + size yytext));
 <INITIAL> "!"         => (Tokens.BANG (yypos, yypos + size yytext));
@@ -105,6 +125,7 @@ ws = [\ \t\012];
 <INITIAL> ">="        => (Tokens.GE (yypos, yypos + size yytext));
 <INITIAL> ">"         => (Tokens.GT (yypos, yypos + size yytext));
 
+<INITIAL> "?"         => (Tokens.QUESTION (yypos, yypos + size yytext));
 <INITIAL> ":"         => (Tokens.COLON (yypos, yypos + size yytext));
 <INITIAL> ","         => (Tokens.COMMA (yypos, yypos + size yytext));
 
@@ -129,6 +150,7 @@ ws = [\ \t\012];
 
 
 <INITIAL> {decnum}    => (number (yytext, yypos));
+<INITIAL> {hexnum}    => (hexnumber (yytext, yypos));
 
 <INITIAL> {id}        => (let
                             val id = Symbol.symbol yytext
This page took 0.024727 seconds and 4 git commands to generate.