summaryrefslogtreecommitdiff
path: root/src/parser.mly
diff options
context:
space:
mode:
authorKathy Gray2014-02-18 15:44:38 +0000
committerKathy Gray2014-02-18 15:44:38 +0000
commit31cec8cf6de8f94c642a4700322e50a26e88e32d (patch)
treefefefde5005596c3d141c31ebe7fb67d1bd723f5 /src/parser.mly
parentfa39bbcf7529903edeb178bca80211386aa817ff (diff)
Adding explicit order to for loops
Diffstat (limited to 'src/parser.mly')
-rw-r--r--src/parser.mly39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/parser.mly b/src/parser.mly
index 7b415ea0..856d3266 100644
--- a/src/parser.mly
+++ b/src/parser.mly
@@ -536,26 +536,33 @@ right_atomic_exp:
{ eloc (E_if($2,$4,$6)) }
| If_ exp Then exp
{ eloc (E_if($2,$4, eloc (E_lit(lloc L_unit)))) }
- | Foreach id Id atomic_exp Id atomic_exp By atomic_exp exp
- { if $3 <> "from" then
+ | Foreach Lparen id Id atomic_exp Id atomic_exp By atomic_exp In typ Rparen exp
+ { if $4 <> "from" then
raise (Parse_error_locn ((loc ()),"Missing \"from\" in foreach loop"));
- if $5 <> "to" && $5 <> "downto" then
+ if $6 <> "to" then
+ raise (Parse_error_locn ((loc ()),"Missing \"to\" in foreach loop"));
+ eloc (E_for($3,$5,$7,$9,$11,$13)) }
+ | Foreach Lparen id Id atomic_exp Id atomic_exp By atomic_exp Rparen exp
+ { if $4 <> "from" then
+ raise (Parse_error_locn ((loc ()),"Missing \"from\" in foreach loop"));
+ if $6 <> "to" && $6 <> "downto" then
raise (Parse_error_locn ((loc ()),"Missing \"to\" or \"downto\" in foreach loop"));
- let step =
- if $5 = "to"
- then $8
- else eloc (E_app_infix(eloc (E_lit(lloc (L_num 0))), idl (Id "-"), $8)) in
- eloc (E_for($2,$4,$6,step,$9)) }
- | Foreach id Id atomic_exp Id atomic_exp exp
- { if $3 <> "from" then
+ let order =
+ if $6 = "to"
+ then ATyp_aux(ATyp_inc,(locn 6 6))
+ else ATyp_aux(ATyp_dec,(locn 6 6)) in
+ eloc (E_for($3,$5,$7,$9,order,$11)) }
+ | Foreach Lparen id Id atomic_exp Id atomic_exp Rparen exp
+ { if $4 <> "from" then
raise (Parse_error_locn ((loc ()),"Missing \"from\" in foreach loop"));
- if $5 <> "to" && $5 <> "downto" then
+ if $6 <> "to" && $6 <> "downto" then
raise (Parse_error_locn ((loc ()),"Missing \"to\" or \"downto\" in foreach loop"));
- let step =
- if $5 = "to"
- then eloc (E_lit(lloc (L_num 1)))
- else eloc (E_lit(lloc (L_num (-1)))) in
- eloc (E_for($2,$4,$6,step,$7)) }
+ let step = eloc (E_lit(lloc (L_num 1))) in
+ let ord =
+ if $6 = "to"
+ then ATyp_aux(ATyp_inc,(locn 6 6))
+ else ATyp_aux(ATyp_dec,(locn 6 6)) in
+ eloc (E_for($3,$5,$7,step,ord,$9)) }
| letbind In exp
{ eloc (E_let($1,$3)) }