modern-compiler-ml/tiger/chap2/tiger.lex
jmug 33d8bac511 Add the tiger source code bundle from the book site
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
2024-12-18 15:18:45 -08:00

18 lines
490 B
Text

type pos = int
type lexresult = Tokens.token
val lineNum = ErrorMsg.lineNum
val linePos = ErrorMsg.linePos
fun err(p1,p2) = ErrorMsg.error p1
fun eof() = let val pos = hd(!linePos) in Tokens.EOF(pos,pos) end
%%
%%
\n => (lineNum := !lineNum+1; linePos := yypos :: !linePos; continue());
"," => (Tokens.COMMA(yypos,yypos+1));
var => (Tokens.VAR(yypos,yypos+3));
"123" => (Tokens.INT(123,yypos,yypos+3));
. => (ErrorMsg.error yypos ("illegal character " ^ yytext); continue());