Skip to content

Commit 23fb8d0

Browse files
committed
Removed Type from nonassoc in tiger.grm so that consecutive tydecs would group together
1 parent 6999925 commit 23fb8d0

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

chp4/parsetest.sml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
structure Parse :
2+
sig
3+
val parse : string -> Absyn.exp
4+
val parseTestcase : string -> Absyn.exp
5+
val parseAllTests : unit -> Absyn.exp list
6+
val test : string -> unit
7+
val testLocal : string -> unit
8+
val testAll : unit -> unit
9+
end =
10+
struct
11+
structure TigerLrVals = TigerLrValsFun(structure Token = LrParser.Token)
12+
structure Lex = TigerLexFun(structure Tokens = TigerLrVals.Tokens)
13+
structure TigerP = Join(structure ParserData = TigerLrVals.ParserData
14+
structure Lex=Lex
15+
structure LrParser = LrParser)
16+
fun parse filename =
17+
let val _ = (ErrorMsg.reset(); ErrorMsg.fileName := filename)
18+
val file = TextIO.openIn filename
19+
fun get _ = TextIO.input file
20+
fun parseerror(s,p1,p2) = ErrorMsg.error p1 s
21+
val lexer = LrParser.Stream.streamify (Lex.makeLexer get)
22+
val (absyn, _) = TigerP.parse(30,lexer,parseerror,())
23+
in TextIO.closeIn file;
24+
absyn
25+
end handle LrParser.ParseError => raise ErrorMsg.Error
26+
27+
fun parseTestcase name =
28+
parse ("../tests/" ^ name ^ ".tig")
29+
30+
fun test file =
31+
let val exp = parseTestcase file
32+
val ostream = TextIO.openOut ("./out/" ^ file ^ ".out")
33+
in
34+
PrintAbsyn.print (ostream, exp)
35+
end
36+
37+
fun testLocal file =
38+
let val exp = parse file
39+
val ostream = TextIO.openOut("./out/" ^ file ^ "_local.out")
40+
in
41+
PrintAbsyn.print (ostream, exp)
42+
end
43+
44+
fun getAllTestCases () =
45+
let val tests = ["merge", "queens"];
46+
fun addTests (0, tests) = tests
47+
| addTests (n, tests) = addTests (n - 1, ("test" ^ Int.toString n)::tests)
48+
in
49+
addTests (49, tests)
50+
end
51+
52+
fun parseAllTests () =
53+
map parseTestcase (getAllTestCases ())
54+
55+
fun testAll () =
56+
app test (getAllTestCases ())
57+
end

chp4/prabsyn.sml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fun print (outstream, e0) =
5353
sayln ","; exp(e,d+1);
5454
say ")")
5555
in indent d; say "RecordExp("; say(Symbol.name typ);
56-
sayln ",["; dolist d f fields; say "])"
56+
say ",["; dolist d f fields; say "])"
5757
end
5858
| exp(A.SeqExp l, d) = (indent d; say "SeqExp["; dolist d exp (map #1 l);
5959
say "]")

chp4/readme.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Explanation For Precedence Directives:
3232

3333
This was inserted because Tiger can have expressions for things like 3D arrays. For example, in the case of "array of array of array", this should refer to the type array of (array of array). If %left was issued, it would reduce first, and instead be recognized as (array of array) of array, which doesn't make sense.
3434

35-
%nonassoc VAR TYPE IF THEN DO FUNCTION TO LET IN ASSIGN WHILE FOR
35+
%nonassoc VAR IF THEN DO FUNCTION TO LET IN ASSIGN WHILE FOR
3636

3737
The parser should never have to determine associativity for these expressions because they should not be able to appear consecutively.
3838

chp4/sources.cm

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ errormsg.sml
55
table.sig
66
table.sml
77
symbol.sml
8-
parse.sml
8+
prabsyn.sml
9+
parsetest.sml
910
tiger.lex
1011
tiger.grm
1112
$/smlnj-lib.cm

chp4/tiger.grm

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ OF NIL
6060
%value STRING ("")
6161

6262
%right OF
63-
%nonassoc VAR TYPE IF THEN DO FUNCTION TO LET IN ASSIGN WHILE FOR
63+
%nonassoc VAR IF THEN DO FUNCTION TO LET IN ASSIGN WHILE FOR
6464
%right ELSE
6565
%left OR
6666
%left AND

0 commit comments

Comments
 (0)