home
/
code
/
tiger.ml.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove stand-alone ty grammar rule
[tiger.ml.git]
/
tiger
/
src
/
lib
/
tiger
/
tiger_parser.mly
diff --git
a/tiger/src/lib/tiger/tiger_parser.mly
b/tiger/src/lib/tiger/tiger_parser.mly
index
157a8a6
..
2cd530d
100644
(file)
--- a/
tiger/src/lib/tiger/tiger_parser.mly
+++ b/
tiger/src/lib/tiger/tiger_parser.mly
@@
-82,13
+82,20
@@
exp:
{
sprintf "negation[%s]" $2
}
{
sprintf "negation[%s]" $2
}
- |
type_id
LBRACK exp RBRACK OF exp
+ |
ID
LBRACK exp RBRACK OF exp
{
{
- sprintf "array[type[%s], size[%s], val[%s]]" $1 $3 $6
+ let type_id = $1 in
+ let exp_1 = $3 in
+ let exp_2 = $6 in
+ sprintf "array[type[%s], size[%s], val[%s]]" type_id exp_1 exp_2
}
}
- |
type_id
LBRACE rec_field_assignments RBRACE
+ |
ID
LBRACE rec_field_assignments RBRACE
{
{
- sprintf "record[type[%s], rec_field_assignments[%s]]" $1 $3
+ let type_id = $1 in
+ let rec_field_assignments = $3 in
+ sprintf
+ "record[type[%s], rec_field_assignments[%s]]"
+ type_id rec_field_assignments
}
| lvalue
{
}
| lvalue
{
@@
-102,9
+109,16
@@
exp:
{
sprintf "string[%S]" $1
}
{
sprintf "string[%S]" $1
}
- |
fun_call
+ |
ID LPAREN RPAREN
{
{
- $1
+ let id = $1 in
+ sprintf "fun_call[%s, []]" id
+ }
+ | ID LPAREN fun_args RPAREN
+ {
+ let id = $1 in
+ let fun_args = $3 in
+ sprintf "fun_call[%s, %s]" id fun_args
}
| exp op exp
{
}
| exp op exp
{
@@
-125,7
+139,7
@@
exp:
{
sprintf "while[%s, do[%s]]" $2 $4
}
{
sprintf "while[%s, do[%s]]" $2 $4
}
- | FOR
id
ASSIGN exp TO exp DO exp
+ | FOR
ID
ASSIGN exp TO exp DO exp
{
let id = $2 in
let e1 = $4 in
{
let id = $2 in
let e1 = $4 in
@@
-137,27
+151,28
@@
exp:
{
"break[]"
}
{
"break[]"
}
- | LPAREN
seq
RPAREN
+ | LPAREN
exps
RPAREN
{
{
- sprintf "
seq
[%s]" $2
+ sprintf "
exps
[%s]" $2
}
}
- | LET decs IN
seq
END
+ | LET decs IN
exps
END
{
let decs = $2 in
{
let decs = $2 in
- let
seq
= $4 in
- sprintf "let[decs[%s], in[
seq[%s]]]" decs seq
+ let
exps
= $4 in
+ sprintf "let[decs[%s], in[
exps[%s]]]" decs exps
}
}
- |
unit
+ |
LPAREN RPAREN
{
{
- $1
+ (* Perhaps "void"? *)
+ "unit[]"
}
}
-
seq
:
+
exps
:
| exp
{
sprintf "%s" $1
}
| exp
{
sprintf "%s" $1
}
- | exp SEMICOLON
seq
+ | exp SEMICOLON
exps
{
sprintf "%s; %s" $1 $3
}
{
sprintf "%s; %s" $1 $3
}
@@
-178,14
+193,20
@@
dec:
| fundec {$1}
fundec:
| fundec {$1}
fundec:
- | FUNCTION id LPAREN tyfields RPAREN EQ exp
+ | FUNCTION ID LPAREN RPAREN EQ exp
+ {
+ let id = $2 in
+ let exp = $6 in
+ sprintf "fundec[%s, arguments[], exp[%s]]" id exp
+ }
+ | FUNCTION ID LPAREN tyfields RPAREN EQ exp
{
let id = $2 in
let tyfields = $4 in
let exp = $7 in
{
let id = $2 in
let tyfields = $4 in
let exp = $7 in
- sprintf "fundec[%s,
tyfield
s[%s], exp[%s]]" id tyfields exp
+ sprintf "fundec[%s,
argument
s[%s], exp[%s]]" id tyfields exp
}
}
- | FUNCTION
id LPAREN tyfields RPAREN COLON type_id
EQ exp
+ | FUNCTION
ID LPAREN tyfields RPAREN COLON ID
EQ exp
{
let id = $2 in
let tyfields = $4 in
{
let id = $2 in
let tyfields = $4 in
@@
-197,42
+218,43
@@
fundec:
}
vardec:
}
vardec:
- | VAR
id
ASSIGN exp
+ | VAR
ID
ASSIGN exp
{
let id = $2 in
let exp = $4 in
sprintf "vardec[%s, exp[%s]]" id exp
}
{
let id = $2 in
let exp = $4 in
sprintf "vardec[%s, exp[%s]]" id exp
}
- | VAR
id COLON type_id
ASSIGN exp
+ | VAR
ID COLON ID
ASSIGN exp
{
let id = $2 in
{
let id = $2 in
- let tyid = $4 in
+ let ty
pe_
id = $4 in
let exp = $6 in
let exp = $6 in
- sprintf "vardec[%s, type_id[%s], exp[%s]]" id tyid exp
+ sprintf "vardec[%s, type_id[%s], exp[%s]]" id ty
pe_
id exp
}
tydec:
}
tydec:
- | TYPE
type_id EQ ty
+ | TYPE
ID EQ ID
{
{
- sprintf "tydec[%s, %s]" $2 $4
+ let type_id_new = $2 in
+ let type_id_orig = $4 in
+ sprintf "tydec_alias[from[%s], to[%s]]" type_id_new type_id_orig
}
}
-
-ty:
- | type_id
- {$1}
- | LBRACE RBRACE
+ | TYPE ID EQ LBRACE RBRACE
{
{
- "record[]"
+ let type_id = $2 in
+ sprintf "tydec_empty_record[%s]" type_id
}
}
- | LBRACE tyfields RBRACE
+ |
TYPE ID EQ
LBRACE tyfields RBRACE
{
{
- let tyfields = $2 in
- sprintf "record[%s]" tyfields
+ let type_id = $2 in
+ let tyfields = $5 in
+ sprintf "tydec_record[%s, fields[%s]]" type_id tyfields
}
}
- |
ARRAY OF type_id
+ |
TYPE ID EQ ARRAY OF ID
{
{
- let type_id = $3 in
- sprintf "array_of_type[%s]" type_id
+ let type_id = $2 in
+ let element_type_id = $6 in
+ sprintf "tydec_array[%s, elements_of_type[%s]]" type_id element_type_id
}
tyfields:
}
tyfields:
@@
-247,50
+269,26
@@
tyfields:
}
tyfield:
}
tyfield:
- |
id COLON type_id
+ |
ID COLON ID
{
let id = $1 in
let type_id = $3 in
sprintf "tyfield[%s, %s]" id type_id
}
{
let id = $1 in
let type_id = $3 in
sprintf "tyfield[%s, %s]" id type_id
}
-id:
- | ID
- {
- sprintf "id[%S]" $1
- }
-
-/* Perhaps "void"? */
-unit:
- | LPAREN RPAREN
- {
- "unit[]"
- }
-
-type_id:
- | id
- {
- sprintf "type_id[%S]" $1
- }
-
rec_field_assignments:
rec_field_assignments:
- |
id
EQ exp
+ |
ID
EQ exp
{
{
- sprintf "%S = %s" $1 $3
- }
- | id EQ exp COMMA rec_field_assignments
- {
- sprintf "%S = %s, %s" $1 $3 $5
- }
-
-fun_call:
- | id unit
- {
- sprintf "fun_call[%s, %s]" $1 $2
+ let id = $1 in
+ let exp = $3 in
+ sprintf "%S = %s" id exp
}
}
- |
id LPAREN fun_args RPAREN
+ |
ID EQ exp COMMA rec_field_assignments
{
{
- sprintf "fun_call[%s, %s]" $1 $3
+ let id = $1 in
+ let exp = $3 in
+ let rec_field_assignments = $5 in
+ sprintf "%S = %s, %s" id exp rec_field_assignments
}
fun_args:
}
fun_args:
@@
-318,17
+316,22
@@
op:
| OR {"|"}
lvalue:
| OR {"|"}
lvalue:
- |
id
+ |
ID
{
{
- sprintf "lvalue[%s]" $1
+ let id = $1 in
+ sprintf "lvalue[%s]" id
}
}
- | lvalue DOT
id
+ | lvalue DOT
ID
{
{
- sprintf "get_record_field[%s, %s]" $1 $3
+ let record = $1 in
+ let field = $3 in
+ sprintf "get_record_field[%s, %s]" record field
}
| lvalue LBRACK exp RBRACK
{
}
| lvalue LBRACK exp RBRACK
{
- sprintf "get_array_subscript[%s, %s]" $1 $3
+ let array = $1 in
+ let subscript = $3 in
+ sprintf "get_array_subscript[%s, %s]" array subscript
}
%%
}
%%
This page took
0.055297 seconds
and
4
git commands to generate.