-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
2,845 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Unix makefile for tigermain example | ||
|
||
HOME=/usr/bin | ||
MOSMLHOME=${HOME} | ||
MOSMLTOOLS=camlrunm /usr/share/mosml/tools | ||
MOSMLLEX=mosmllex | ||
MOSMLYACC=mosmlyac -v | ||
|
||
GCC=gcc | ||
CFLAGS= -g | ||
MOSMLC=${MOSMLHOME}/mosmlc -c -liberal | ||
MOSMLL=${MOSMLHOME}/mosmlc | ||
|
||
# Unix | ||
REMOVE=rm -f | ||
MOVE=mv | ||
EXEFILE= | ||
|
||
# DOS | ||
#REMOVE=del | ||
#MOVE=move | ||
#EXEFILE=.exe | ||
|
||
.SUFFIXES : | ||
.SUFFIXES : .sig .sml .ui .uo | ||
|
||
GRALOBJS= tigerabs.uo tigergrm.uo tigerlex.uo tigermain.uo \ | ||
tigernlin.uo tigerpp.uo tigerescap.uo tigertab.uo tigerseman.uo tigertemp.uo tigertopsort.uo tigermuestratipos.uo | ||
|
||
all: tiger | ||
|
||
tiger: $(GRALOBJS) $(OBJSGEN) | ||
$(MOSMLL) -o tiger $(EXEFILE) tigermain.uo | ||
|
||
tigergrm.sml tigergrm.sig: tigergrm.y | ||
$(MOSMLYACC) tigergrm.y | ||
|
||
tigerlex.sml: tigerlex.lex | ||
$(MOSMLLEX) tigerlex.lex | ||
|
||
clean: | ||
$(REMOVE) Makefile.bak | ||
$(REMOVE) tigergrm.output | ||
$(REMOVE) tigergrm.sig | ||
$(REMOVE) tigergrm.sml | ||
$(REMOVE) tigerlex.sml | ||
$(REMOVE) tigermain | ||
$(REMOVE) *.ui | ||
$(REMOVE) *.uo | ||
$(REMOVE) errlist | ||
$(REMOVE) *.o | ||
|
||
.sig.ui: | ||
$(MOSMLC) $< | ||
|
||
.sml.uo: | ||
$(MOSMLC) $< | ||
|
||
### Agregar modulos acá también | ||
depend: tigerabs.sml tigergrm.sml tigerlex.sml tigermain.sml \ | ||
tigernlin.sml tigerpp.sml tigertopsort.sml tigermuestratipos.sml | ||
$(REMOVE) Makefile.bak | ||
$(MOVE) Makefile Makefile.bak | ||
$(MOSMLTOOLS)/cutdeps < Makefile.bak > Makefile | ||
$(MOSMLTOOLS)/mosmldep >> Makefile | ||
|
||
### DO NOT DELETE THIS LINE | ||
tigermain.uo: tigerseman.ui tigerescap.ui tigergrm.ui tigerlex.uo \ | ||
tigerpp.uo | ||
tigerescap.uo: tigerescap.ui tigertab.ui tigerabs.uo | ||
tigerseman.uo: tigerseman.ui tigersres.uo tigertab.ui tigerabs.uo | ||
tigertopsort.ui: tigertab.ui tigertips.uo tigerabs.uo | ||
tigertemp.uo: tigertemp.ui | ||
tigermuestratipos.uo: tigermuestratipos.ui tigertips.uo | ||
tigergrm.uo: tigergrm.ui tigernlin.uo tigerabs.uo | ||
tigerpp.uo: tigerabs.uo | ||
tigertopsort.uo: tigertopsort.ui tigertab.ui tigertips.uo tigerabs.uo \ | ||
tigermuestratipos.ui | ||
tigermuestratipos.ui: tigertips.uo | ||
tigerescap.ui: tigerabs.uo | ||
tigerlex.uo: tigergrm.ui tigernlin.uo | ||
tigertab.uo: tigertab.ui | ||
tigerseman.ui: tigersres.uo tigertab.ui tigertips.uo tigerabs.uo | ||
tigersres.uo: tigertab.ui tigertips.uo tigertemp.ui tigerabs.uo | ||
tigergrm.ui: tigerabs.uo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Tiger permite denotar dos tipos primitivos: int y string, y construir sinónimos, records y arreglos. | ||
Pero permite denotar valores de otros tipos (ej ()). Así que, internamente Tiger usará un sistema de | ||
tipos extendido. | ||
|
||
(Archivo en tigertips.sml) | ||
|
||
---------------------------- | ||
|
||
Usaremos en tigerseman.sml dos entornos (tablas hash): | ||
- tenv (type environment): [("int", TInt RW), ("string", TString)] | ||
- venv (variable enviornment). | ||
|
||
---------------------------- | ||
|
||
En tigergrm.y se encuentra la gramatica libre de contexto del lenguaje Tiger. | ||
|
||
---------------------------- | ||
|
||
codigo fuente -> LEXER/PARSER -> ast (sin escapes) -> ESCAPES -> ast -> ANALISIS SEMANTICO | ||
|
||
LEXER/PARSER | ||
- tigerlex.lex | ||
- tigergrm.y | ||
- tigerlin.sml | ||
|
||
AST: | ||
- tigerabs.sml | ||
- tigerpp.sml | ||
|
||
ESCAPES: | ||
- tigerscap.sml/.sig | ||
|
||
TABLAS: | ||
- tigertab.sml/.sig | ||
|
||
ANALISIS SEMANTICO: | ||
- tigersres.sml | ||
- tigertips.sml | ||
- tigerseman.sig/.sml: | ||
* trexp chequea tipos y comenta errores. | ||
|
||
tigermain.sml, donde se concatenan los módulos del compilador. | ||
|
||
-------------------------------------- | ||
|
||
''a tipo polimórfico a que admite comparación | ||
|
||
-------------------------------------- | ||
|
||
tigergrm.sml utiliza, entre otras cosas, tigerabs.sml. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
structure tigerabs = | ||
struct | ||
|
||
type symbol = string | ||
type pos = int | ||
|
||
datatype var = SimpleVar of symbol | ||
| FieldVar of var * symbol | ||
| SubscriptVar of var * exp | ||
|
||
and exp = VarExp of var * pos | ||
| UnitExp of pos | ||
| NilExp of pos | ||
| IntExp of int * pos | ||
| StringExp of string * pos | ||
| CallExp of {func: symbol, args: exp list} * pos | ||
| OpExp of {left: exp, oper: oper, right: exp} * pos | ||
| RecordExp of {fields: (symbol * exp) list, typ: symbol} * pos | ||
| SeqExp of exp list * pos | ||
| AssignExp of {var: var, exp: exp} * pos | ||
| IfExp of {test: exp, then': exp, else': exp option} * pos | ||
| WhileExp of {test: exp, body: exp} * pos | ||
| ForExp of {var: symbol, escape: bool ref, | ||
lo: exp, hi: exp, body: exp} * pos | ||
| LetExp of {decs: dec list, body: exp} * pos | ||
| BreakExp of pos | ||
| ArrayExp of {typ: symbol, size: exp, init: exp} * pos | ||
|
||
and dec = FunctionDec of ({name: symbol, params: field list, | ||
result: symbol option, body: exp} * pos) list | ||
| VarDec of {name: symbol, escape: bool ref, | ||
typ: symbol option, init: exp} * pos | ||
| TypeDec of ({name: symbol, ty: ty} * pos) list | ||
|
||
and ty = NameTy of symbol | ||
| RecordTy of field list | ||
| ArrayTy of symbol | ||
and oper = PlusOp | MinusOp | TimesOp | DivideOp | ||
| EqOp | NeqOp | LtOp | LeOp | GtOp | GeOp | ||
|
||
withtype field = {name: symbol, escape: bool ref, typ: ty} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
signature tigerescap = | ||
sig | ||
val findEscape: tigerabs.exp -> unit | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
structure tigerescap :> tigerescap = | ||
struct | ||
|
||
open tigerabs | ||
open tigertab | ||
|
||
type depth = int | ||
type escEnv = (string, depth * bool ref) tigertab.Tabla | ||
|
||
fun travVar env d s = | ||
case s of | ||
SimpleVar s => | ||
(case tabBusca(s, env) of | ||
SOME (dd, b) => if d>dd then b:=true else () | ||
| NONE => raise Fail ("escape?? "^s^" inexist.")) | ||
| FieldVar(v, s) => travVar env d v | ||
| SubscriptVar(v, e) => | ||
(travVar env d v; travExp env d e) | ||
and travExp env d s = | ||
case s of | ||
VarExp(v, _) => travVar env d v | ||
| CallExp({func, args}, nl) => travExp env d (SeqExp(args, nl)) | ||
| OpExp({left, oper, right}, _) => | ||
(travExp env d left; travExp env d right) | ||
| RecordExp({fields, typ}, _) => | ||
List.app ((travExp env d) o #2) fields | ||
| SeqExp(le, nl) => | ||
(List.foldl (fn (e, (v, d)) => (travExp v d e; (v, d))) | ||
(env, d) le; ()) | ||
| AssignExp({var, exp}, _) => | ||
(travVar env d var; travExp env d exp) | ||
| IfExp({test, then', else'=NONE}, _) => | ||
(travExp env d test; travExp env d then') | ||
| IfExp({test, then', else'=SOME e}, _) => | ||
(travExp env d test; travExp env d then'; travExp env d e) | ||
| WhileExp({test, body}, _) => | ||
(travExp env d test; travExp env d body) | ||
| ForExp({var, escape, lo, hi, body}, _) => | ||
let val env' = tabRInserta(var, (d, escape), env); | ||
in travExp env d lo; | ||
travExp env d hi; | ||
travExp env' d body | ||
end | ||
| LetExp({decs, body}, _) => | ||
travExp (travDecs env d decs) d body | ||
| ArrayExp({typ, size, init}, _) => travExp env d init | ||
| _ => () | ||
and travDecs env d [] = env | ||
| travDecs env d (s::t) = | ||
let fun aux s = | ||
case s of | ||
FunctionDec l => | ||
let fun aux(({name, params, result, body}, _), env) = | ||
let fun aux1(x, e) = | ||
tabRInserta(#name(x), (d+1, #escape(x)), e) | ||
val env' = foldr aux1 env params | ||
in travExp env' (d+1) body; env end | ||
in foldl aux env l end | ||
| VarDec({name, escape, typ, init}, _) => | ||
(travExp env d init; tabRInserta(name, (d, escape), env)) | ||
| TypeDec _ => env | ||
val env' = aux s | ||
in travDecs env' d t end | ||
|
||
fun findEscape prog = travExp (tigertab.tabNueva()) 0 prog | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
local | ||
in | ||
datatype token = | ||
AMPER | ||
| ARRAY | ||
| BREAK | ||
| CD | ||
| CI | ||
| COMA | ||
| DIST | ||
| DIV | ||
| DO | ||
| DOSP | ||
| DOSPIG | ||
| ELSE | ||
| END | ||
| EOF | ||
| FOR | ||
| FUNCTION | ||
| ID of string | ||
| IF | ||
| IGUAL | ||
| IN | ||
| LD | ||
| LET | ||
| LI | ||
| LITERAL of string | ||
| MAS | ||
| MAYIG | ||
| MAYOR | ||
| MENIG | ||
| MENOR | ||
| MENOS | ||
| NIL | ||
| NRO of int | ||
| OF | ||
| PCOMA | ||
| PD | ||
| PI | ||
| PIPE | ||
| POR | ||
| PTO | ||
| THEN | ||
| TO | ||
| TYPE | ||
| VAR | ||
| WHILE | ||
end; | ||
|
||
val prog : | ||
(Lexing.lexbuf -> token) -> Lexing.lexbuf -> tigerabs.exp; |
Oops, something went wrong.