-(* L4 Compiler
+(* L5 Compiler
* Lexer
* Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
* Modified: Frank Pfenning <fp@cs.cmu.edu>
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)
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];
<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));
<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));
<INITIAL> {decnum} => (number (yytext, yypos));
+<INITIAL> {hexnum} => (hexnumber (yytext, yypos));
<INITIAL> {id} => (let
val id = Symbol.symbol yytext