Add the tiger source code bundle from the book site

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2024-12-18 15:18:45 -08:00
parent 915660c8a7
commit 33d8bac511
87 changed files with 3252 additions and 0 deletions

18
tiger/chap2/tiger.lex Normal file
View file

@ -0,0 +1,18 @@
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());