Skip to content

Commit afa928c

Browse files
committed
Rename paths
1 parent 4ea3945 commit afa928c

File tree

149 files changed

+720
-720
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+720
-720
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
signature SYMBOL =
2-
sig
3-
eqtype symbol
4-
val symbol : string -> symbol
5-
val name : symbol -> string
6-
type 'a table
7-
val empty : 'a table
8-
val enter : 'a table * symbol * 'a -> 'a table
9-
val look : 'a table * symbol -> 'a option
10-
end
11-
12-
structure Symbol :> SYMBOL =
13-
struct
14-
15-
type symbol = string * int
16-
17-
structure H = HashTable
18-
19-
exception Symbol
20-
val nextsym = ref 0
21-
val sizeHint = 128
22-
val hashtable : (string,int) H.hash_table =
23-
H.mkTable(HashString.hashString, op = ) (sizeHint,Symbol)
24-
25-
fun symbol name =
26-
case H.find hashtable name
27-
of SOME i => (name,i)
28-
| NONE => let val i = !nextsym
29-
in nextsym := i+1;
30-
H.insert hashtable (name,i);
31-
(name,i)
32-
end
33-
34-
fun name(s,n) = s
35-
36-
structure Table = IntMapTable(type key = symbol
37-
fun getInt(s,n) = n)
38-
39-
type 'a table= 'a Table.table
40-
val empty = Table.empty
41-
val enter = Table.enter
42-
val look = Table.look
43-
end
1+
signature SYMBOL =
2+
sig
3+
eqtype symbol
4+
val symbol : string -> symbol
5+
val name : symbol -> string
6+
type 'a table
7+
val empty : 'a table
8+
val enter : 'a table * symbol * 'a -> 'a table
9+
val look : 'a table * symbol -> 'a option
10+
end
11+
12+
structure Symbol :> SYMBOL =
13+
struct
14+
15+
type symbol = string * int
16+
17+
structure H = HashTable
18+
19+
exception Symbol
20+
val nextsym = ref 0
21+
val sizeHint = 128
22+
val hashtable : (string,int) H.hash_table =
23+
H.mkTable(HashString.hashString, op = ) (sizeHint,Symbol)
24+
25+
fun symbol name =
26+
case H.find hashtable name
27+
of SOME i => (name,i)
28+
| NONE => let val i = !nextsym
29+
in nextsym := i+1;
30+
H.insert hashtable (name,i);
31+
(name,i)
32+
end
33+
34+
fun name(s,n) = s
35+
36+
structure Table = IntMapTable(type key = symbol
37+
fun getInt(s,n) = n)
38+
39+
type 'a table= 'a Table.table
40+
val empty = Table.empty
41+
val enter = Table.enter
42+
val look = Table.look
43+
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,103 @@
1-
type pos = int
2-
type svalue = Tokens.svalue
3-
type pos = int
4-
type ('a, 'b) token = ('a, 'b) Tokens.token
5-
type lexresult = (svalue, pos) token
6-
7-
val lineNum = ErrorMsg.lineNum
8-
val linePos = ErrorMsg.linePos
9-
val commentCount = ref 0
10-
val inString = ref 0
11-
val stringAccum = ref ""
12-
val stringStartPos = ref 0
13-
fun err(p1,p2) = ErrorMsg.error p1
14-
15-
fun eof() = let val pos = hd(!linePos) in
16-
if (!commentCount <> 0) then (ErrorMsg.error pos "Unclosed Comment"; commentCount := 0)
17-
else if !inString <> 0 then (ErrorMsg.error pos "Unclosed String"; inString := 0; stringAccum := "";stringStartPos := 0)
18-
else (); Tokens.EOF(pos,pos)
19-
end
20-
21-
22-
%%
23-
%header (functor TigerLexFun(structure Tokens: Tiger_TOKENS));
24-
%s COMMENT STRING;
25-
dgts = [0-9];
26-
ws = [\ \t];
27-
identf = [a-zA-Z][a-zA-Z0-9_]*;
28-
29-
%%
30-
<INITIAL,COMMENT,STRING>\n => (lineNum := !lineNum+1; linePos := yypos :: !linePos; continue());
31-
<INITIAL,COMMENT>{ws}+ => (continue());
32-
<INITIAL>{dgts}+ => (Tokens.INT(Option.valOf(Int.fromString(yytext)),yypos, if Option.valOf(Int.fromString(yytext)) = 0 then yypos+1 else yypos+1+floor(Math.log10(real(Option.valOf(Int.fromString(yytext)))))));
33-
34-
<INITIAL>of => (Tokens.OF(yypos,yypos+2));
35-
<INITIAL>var => (Tokens.VAR(yypos,yypos+3));
36-
<INITIAL>while => (Tokens.WHILE(yypos, yypos+5));
37-
<INITIAL>for => (Tokens.FOR(yypos, yypos+3));
38-
<INITIAL>to => (Tokens.TO(yypos, yypos+2));
39-
<INITIAL>break => (Tokens.BREAK(yypos, yypos+5));
40-
<INITIAL>let => (Tokens.LET(yypos, yypos+3));
41-
<INITIAL>in => (Tokens.IN(yypos, yypos+2));
42-
<INITIAL>end => (Tokens.END(yypos, yypos+3));
43-
<INITIAL>function => (Tokens.FUNCTION(yypos, yypos+8));
44-
<INITIAL>type => (Tokens.TYPE(yypos, yypos+4));
45-
<INITIAL>array => (Tokens.ARRAY(yypos, yypos+5));
46-
<INITIAL>if => (Tokens.IF(yypos, yypos+2));
47-
<INITIAL>then => (Tokens.THEN(yypos, yypos+4));
48-
<INITIAL>else => (Tokens.ELSE(yypos, yypos+4));
49-
<INITIAL>do => (Tokens.DO(yypos, yypos+2));
50-
<INITIAL>nil => (Tokens.NIL(yypos, yypos+3));
51-
52-
<INITIAL>"," => (Tokens.COMMA(yypos,yypos+1));
53-
<INITIAL>":" => (Tokens.COLON(yypos, yypos+1));
54-
<INITIAL>";" => (Tokens.SEMICOLON(yypos, yypos+1));
55-
<INITIAL>"." => (Tokens.DOT(yypos, yypos+1));
56-
<INITIAL>"(" => (Tokens.LPAREN(yypos, yypos+1));
57-
<INITIAL>")" => (Tokens.RPAREN(yypos, yypos+1));
58-
<INITIAL>"[" => (Tokens.LBRACK(yypos, yypos+1));
59-
<INITIAL>"]" => (Tokens.RBRACK(yypos, yypos+1));
60-
<INITIAL>"{" => (Tokens.LBRACE(yypos, yypos+1));
61-
<INITIAL>"}" => (Tokens.RBRACE(yypos, yypos+1));
62-
<INITIAL>"+" => (Tokens.PLUS(yypos, yypos+1));
63-
<INITIAL>"-" => (Tokens.MINUS(yypos, yypos+1));
64-
<INITIAL>"*" => (Tokens.TIMES(yypos, yypos+1));
65-
<INITIAL>"/" => (Tokens.DIVIDE(yypos, yypos+1));
66-
<INITIAL>"=" => (Tokens.EQ(yypos, yypos+1));
67-
<INITIAL>":=" => (Tokens.ASSIGN(yypos, yypos+2));
68-
<INITIAL>"<>" => (Tokens.NEQ(yypos, yypos+2));
69-
<INITIAL>"<" => (Tokens.LT(yypos, yypos+1));
70-
<INITIAL>">" => (Tokens.GT(yypos, yypos+1));
71-
<INITIAL>"<=" => (Tokens.LE(yypos, yypos+2));
72-
<INITIAL>">=" => (Tokens.GE(yypos, yypos+2));
73-
<INITIAL>"&" => (Tokens.AND(yypos, yypos+1));
74-
<INITIAL>"|" => (Tokens.OR(yypos, yypos+1));
75-
76-
<INITIAL>"/*" => (YYBEGIN COMMENT; commentCount := 1; continue());
77-
<COMMENT>"/*" => (commentCount := !commentCount+1; continue());
78-
<COMMENT>. => (continue());
79-
<COMMENT>"*/" => (commentCount:= !commentCount -1; if !commentCount = 0 then YYBEGIN INITIAL else (); continue());
80-
81-
<INITIAL>\" => (YYBEGIN STRING;inString := 1; stringAccum := ""; stringStartPos := yypos; continue());
82-
<STRING>\" => (YYBEGIN INITIAL;inString := 0; Tokens.STRING(!stringAccum, !stringStartPos, yypos));
83-
<STRING>\\\" => (stringAccum := !stringAccum ^ "\""; continue());
84-
<STRING>\\n => (stringAccum := !stringAccum ^ "\n"; continue());
85-
<STRING>\\t => (stringAccum := !stringAccum ^ "\t"; continue());
86-
<STRING>\\\\ => (stringAccum := !stringAccum ^ "\\"; continue());
87-
88-
<STRING>\\{dgts}{dgts}{dgts} => (stringAccum := !stringAccum ^ Char.toString(chr (valOf(Int.fromString (String.substring(yytext, 1, size(yytext) -1))))); continue());
89-
90-
<STRING>\\[\ \t\n\f]+\\ => (continue());
91-
<STRING>\\\^(@|[A-Z]|\[|\\|\]|\^|_) => (stringAccum := !stringAccum ^ valOf (String.fromString yytext); continue());
92-
<STRING>\\. => (ErrorMsg.error yypos ("illegal escape sequence " ^ yytext); continue());
93-
<STRING>. => (stringAccum := !stringAccum ^ yytext; continue());
94-
95-
96-
<INITIAL>{identf} => (Tokens.ID(yytext, yypos, yypos+String.size(yytext)));
97-
<INITIAL>. => (ErrorMsg.error yypos ("illegal character " ^ yytext); continue());
98-
99-
100-
101-
102-
103-
1+
type pos = int
2+
type svalue = Tokens.svalue
3+
type pos = int
4+
type ('a, 'b) token = ('a, 'b) Tokens.token
5+
type lexresult = (svalue, pos) token
6+
7+
val lineNum = ErrorMsg.lineNum
8+
val linePos = ErrorMsg.linePos
9+
val commentCount = ref 0
10+
val inString = ref 0
11+
val stringAccum = ref ""
12+
val stringStartPos = ref 0
13+
fun err(p1,p2) = ErrorMsg.error p1
14+
15+
fun eof() = let val pos = hd(!linePos) in
16+
if (!commentCount <> 0) then (ErrorMsg.error pos "Unclosed Comment"; commentCount := 0)
17+
else if !inString <> 0 then (ErrorMsg.error pos "Unclosed String"; inString := 0; stringAccum := "";stringStartPos := 0)
18+
else (); Tokens.EOF(pos,pos)
19+
end
20+
21+
22+
%%
23+
%header (functor TigerLexFun(structure Tokens: Tiger_TOKENS));
24+
%s COMMENT STRING;
25+
dgts = [0-9];
26+
ws = [\ \t];
27+
identf = [a-zA-Z][a-zA-Z0-9_]*;
28+
29+
%%
30+
<INITIAL,COMMENT,STRING>\n => (lineNum := !lineNum+1; linePos := yypos :: !linePos; continue());
31+
<INITIAL,COMMENT>{ws}+ => (continue());
32+
<INITIAL>{dgts}+ => (Tokens.INT(Option.valOf(Int.fromString(yytext)),yypos, if Option.valOf(Int.fromString(yytext)) = 0 then yypos+1 else yypos+1+floor(Math.log10(real(Option.valOf(Int.fromString(yytext)))))));
33+
34+
<INITIAL>of => (Tokens.OF(yypos,yypos+2));
35+
<INITIAL>var => (Tokens.VAR(yypos,yypos+3));
36+
<INITIAL>while => (Tokens.WHILE(yypos, yypos+5));
37+
<INITIAL>for => (Tokens.FOR(yypos, yypos+3));
38+
<INITIAL>to => (Tokens.TO(yypos, yypos+2));
39+
<INITIAL>break => (Tokens.BREAK(yypos, yypos+5));
40+
<INITIAL>let => (Tokens.LET(yypos, yypos+3));
41+
<INITIAL>in => (Tokens.IN(yypos, yypos+2));
42+
<INITIAL>end => (Tokens.END(yypos, yypos+3));
43+
<INITIAL>function => (Tokens.FUNCTION(yypos, yypos+8));
44+
<INITIAL>type => (Tokens.TYPE(yypos, yypos+4));
45+
<INITIAL>array => (Tokens.ARRAY(yypos, yypos+5));
46+
<INITIAL>if => (Tokens.IF(yypos, yypos+2));
47+
<INITIAL>then => (Tokens.THEN(yypos, yypos+4));
48+
<INITIAL>else => (Tokens.ELSE(yypos, yypos+4));
49+
<INITIAL>do => (Tokens.DO(yypos, yypos+2));
50+
<INITIAL>nil => (Tokens.NIL(yypos, yypos+3));
51+
52+
<INITIAL>"," => (Tokens.COMMA(yypos,yypos+1));
53+
<INITIAL>":" => (Tokens.COLON(yypos, yypos+1));
54+
<INITIAL>";" => (Tokens.SEMICOLON(yypos, yypos+1));
55+
<INITIAL>"." => (Tokens.DOT(yypos, yypos+1));
56+
<INITIAL>"(" => (Tokens.LPAREN(yypos, yypos+1));
57+
<INITIAL>")" => (Tokens.RPAREN(yypos, yypos+1));
58+
<INITIAL>"[" => (Tokens.LBRACK(yypos, yypos+1));
59+
<INITIAL>"]" => (Tokens.RBRACK(yypos, yypos+1));
60+
<INITIAL>"{" => (Tokens.LBRACE(yypos, yypos+1));
61+
<INITIAL>"}" => (Tokens.RBRACE(yypos, yypos+1));
62+
<INITIAL>"+" => (Tokens.PLUS(yypos, yypos+1));
63+
<INITIAL>"-" => (Tokens.MINUS(yypos, yypos+1));
64+
<INITIAL>"*" => (Tokens.TIMES(yypos, yypos+1));
65+
<INITIAL>"/" => (Tokens.DIVIDE(yypos, yypos+1));
66+
<INITIAL>"=" => (Tokens.EQ(yypos, yypos+1));
67+
<INITIAL>":=" => (Tokens.ASSIGN(yypos, yypos+2));
68+
<INITIAL>"<>" => (Tokens.NEQ(yypos, yypos+2));
69+
<INITIAL>"<" => (Tokens.LT(yypos, yypos+1));
70+
<INITIAL>">" => (Tokens.GT(yypos, yypos+1));
71+
<INITIAL>"<=" => (Tokens.LE(yypos, yypos+2));
72+
<INITIAL>">=" => (Tokens.GE(yypos, yypos+2));
73+
<INITIAL>"&" => (Tokens.AND(yypos, yypos+1));
74+
<INITIAL>"|" => (Tokens.OR(yypos, yypos+1));
75+
76+
<INITIAL>"/*" => (YYBEGIN COMMENT; commentCount := 1; continue());
77+
<COMMENT>"/*" => (commentCount := !commentCount+1; continue());
78+
<COMMENT>. => (continue());
79+
<COMMENT>"*/" => (commentCount:= !commentCount -1; if !commentCount = 0 then YYBEGIN INITIAL else (); continue());
80+
81+
<INITIAL>\" => (YYBEGIN STRING;inString := 1; stringAccum := ""; stringStartPos := yypos; continue());
82+
<STRING>\" => (YYBEGIN INITIAL;inString := 0; Tokens.STRING(!stringAccum, !stringStartPos, yypos));
83+
<STRING>\\\" => (stringAccum := !stringAccum ^ "\""; continue());
84+
<STRING>\\n => (stringAccum := !stringAccum ^ "\n"; continue());
85+
<STRING>\\t => (stringAccum := !stringAccum ^ "\t"; continue());
86+
<STRING>\\\\ => (stringAccum := !stringAccum ^ "\\"; continue());
87+
88+
<STRING>\\{dgts}{dgts}{dgts} => (stringAccum := !stringAccum ^ Char.toString(chr (valOf(Int.fromString (String.substring(yytext, 1, size(yytext) -1))))); continue());
89+
90+
<STRING>\\[\ \t\n\f]+\\ => (continue());
91+
<STRING>\\\^(@|[A-Z]|\[|\\|\]|\^|_) => (stringAccum := !stringAccum ^ valOf (String.fromString yytext); continue());
92+
<STRING>\\. => (ErrorMsg.error yypos ("illegal escape sequence " ^ yytext); continue());
93+
<STRING>. => (stringAccum := !stringAccum ^ yytext; continue());
94+
95+
96+
<INITIAL>{identf} => (Tokens.ID(yytext, yypos, yypos+String.size(yytext)));
97+
<INITIAL>. => (ErrorMsg.error yypos ("illegal character " ^ yytext); continue());
98+
99+
100+
101+
102+
103+
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
Group Members
2-
Paul Cruz
3-
Rubens Farias
4-
Mike Ma
5-
6-
ECE553 Semantic Analysis Submission
7-
8-
In order to use our semantic analysis module, please compile the entire project with CM.make "sources.cm". You can then run the module on a test file using Main.parse "TESTFILE.tig"
9-
10-
As far as we understand, there are no known bugs to report during the time of submission.
11-
12-
The only files we have edited during this project included env.sml, semant.sml, main.sml, parse.sml, sources.cm, and types.sml. semant.sml contains our implementation for the semantic analysis, which follows recommendations from the textbook. Similarly, env.sml was completed using provided example code from the textbook. main.sml consists of our module for actually running the semantic analysis and viewing compilations/type checking errors. parse.sml, sources.cm, and types.sml were mostly edited in order to fixed small compilation issues regarding the starter code.
13-
14-
The semantic analysis is implemented essentially exactly the way the book recommends, therefore instead of going through all the details, we will only focus on some significant nuances/design choices that were made for the module.
15-
16-
recursive functions/types: The module type checks these by first going through the type/function headers and adding T.NAME types to the symbol table for these types. The details of each T.NAME is filled in later after each mutually recursive type/function has been added to the table so that they can be looked up during processing. This is done in the TransDec function of the module. Furthermore, it is during this phase that we check for cycles within type definitions.
17-
18-
loop break points: we track break expressions with a var called nest, which increments and decrements based on the depth of the loop.
19-
1+
Group Members
2+
Paul Cruz
3+
Rubens Farias
4+
Mike Ma
5+
6+
ECE553 Semantic Analysis Submission
7+
8+
In order to use our semantic analysis module, please compile the entire project with CM.make "sources.cm". You can then run the module on a test file using Main.parse "TESTFILE.tig"
9+
10+
As far as we understand, there are no known bugs to report during the time of submission.
11+
12+
The only files we have edited during this project included env.sml, semant.sml, main.sml, parse.sml, sources.cm, and types.sml. semant.sml contains our implementation for the semantic analysis, which follows recommendations from the textbook. Similarly, env.sml was completed using provided example code from the textbook. main.sml consists of our module for actually running the semantic analysis and viewing compilations/type checking errors. parse.sml, sources.cm, and types.sml were mostly edited in order to fixed small compilation issues regarding the starter code.
13+
14+
The semantic analysis is implemented essentially exactly the way the book recommends, therefore instead of going through all the details, we will only focus on some significant nuances/design choices that were made for the module.
15+
16+
recursive functions/types: The module type checks these by first going through the type/function headers and adding T.NAME types to the symbol table for these types. The details of each T.NAME is filled in later after each mutually recursive type/function has been added to the table so that they can be looked up during processing. This is done in the TransDec function of the module. Furthermore, it is during this phase that we check for cycles within type definitions.
17+
18+
loop break points: we track break expressions with a var called nest, which increments and decrements based on the depth of the loop.
19+
2020
main.sml: this module functions simply by using our previous parser to produce the abstract syntax tree, which is then passed to the semant.sml module for analysis.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)