Skip to content

Commit

Permalink
fix ref bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hsk committed Feb 11, 2015
1 parent d24ac0a commit e2a3677
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scala/mincaml2js.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ object parse extends RegexParsers {
EVar(a)
} |
"begin" ~> exp <~ "end" |
"!" ~> simple_exp ^^ { a => EBin(a,".", EVar("ref")) } |
"(" ~> exp <~ ")"

def exp: Parser[E] =
Expand Down Expand Up @@ -174,7 +175,6 @@ object parse extends RegexParsers {
def sub: Parser[E] =
"-." ~> app ^^ { a => EPre("-", a) } |
"-" ~> app ^^ { a => EPre("-", a) } |
"!" ~> app ^^ { a => EBin(a,".", EVar("ref")) } |
app

def app: Parser[E] =
Expand Down
2 changes: 1 addition & 1 deletion src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ simple_exp:
| IDENT { Var($1) }
| simple_exp DOT LPAREN exp RPAREN { Get($1, $4) }
| simple_exp DOT IDENT { Get($1, Str $3) }
| EXCLAM exp %prec DOT { Bin($2,".",Var "ref") }

field:
| IDENT EQUAL exp { ($1, $3) }
Expand All @@ -93,7 +94,6 @@ exp:
| Float(f) -> Float(-.f)
| e -> Pre("-", e)
}
| EXCLAM exp %prec prec_unary_minus { Bin($2,".",Var "ref") }
| exp CONS exp { CApp("Cons", Tuple[$1; $3]) }
| exp AT exp { App(Var "concat", [$1; $3]) }
| exp AS IDENT { Bin($1, "as", Var $3) }
Expand Down
2 changes: 1 addition & 1 deletion src2/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ let rec simple_exp i = i |> (
(ident >>> (fun a -> Var a)) <|>
(cident <~> rep1(str "." >> ident) >>> (fun (a,b) -> Var (String.concat "." (a::b) ))) <|>
(str "begin" >> exp << str "end" >>> (fun e -> e)) <|>
((str "!" >> simple_exp) >>> (fun a -> Get(a, Str "ref") )) <|>
(str "(" >> exp << str ")" >>> (fun e -> e))
)
and field i = i |> (
Expand Down Expand Up @@ -192,7 +193,6 @@ and sub i = i |> (
| Float(f) -> Float (-. f)
| a -> Pre("-", a)
)) <|>
((str "!" >> app) >>> (fun a -> Get(a, Str "ref") )) <|>
app
)
and app i = i |> (
Expand Down
7 changes: 6 additions & 1 deletion test/ref.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ a := b + 1;
print_int(!a);
a := !a + 1;
print_int(!a);
print_newline()
print_newline();
let rec f a1 =
a := 1000;
a1
in print_int(f !a);
print_newline()

0 comments on commit e2a3677

Please sign in to comment.