Read the common instructions first if you have not read them. Don't forget to read the REPL section.
sbt new kaist-plrg-cs320/srbfae.g8
SRBFAE extends BFAE with generalized sequencing and mutable records. Implement an interpreter for SRBFAE.
Generalized sequencing allows one or more subexpressions, instead of exactly two subexpressions.
test(run("""{
b => {
b.set((2 + b.get));
b.set((3 + b.get));
b.set((4 + b.get));
b.get
}
}(Box(1))"""), "10")
Unlike records in MRFVAE, records in SRBFAE are mutable. { e1.f = e2 }
changes the value of a field f
in the record produced by e1
. The value of
e2
determines the field's new value, and that value is also the result of the
expression.
test(run("""{
r => {
{ r.x = 5 };
r.x
}
}({ x = 1 })"""), "5")
As in MRFVAE, the interpreter must throw an exception whose message
includes "not a record"
when updating a field of a non-record value and "no such field"
when updating a field not in a given record value.
We use the extended Backus-Naur form.
Note that { }
denotes a repetition of zero or more times.
expr ::= ...
| "{" expr {";" expr} "}"
| "{" "}"
| "{" field "=" expr {"," field "=" expr} "}"
| expr "." field
| "{" expr "." field "=" expr "}"
Expressions are defined in core/src/main/scala/cs320/Expr.scala
, and values
are defined in core/src/main/scala/cs320/Value.scala
.