Simple examples:
js> db = CallDB.INSTANCE
net.cscott.sdr.calls.CallDB@1d66e22
js> db.parse(Program.BASIC, "double pass thru")
(Apply double pass thru)
js> db.parse(Program.BASIC, "square thru three and a half")
(Apply square thru (Apply 3 1/2))
As a convenience, we also allow numbers specified with digits
(even though this is never produced by the spoken language recognizer):
js> db = CallDB.INSTANCE ; undefined
js> db.parse(Program.BASIC, "square thru 3 1/2")
(Apply square thru (Apply 3 1/2))
We use a precedence grammar to resolve some ambiguities:
js> db = CallDB.INSTANCE ; undefined
js> db.parse(Program.BASIC, "do one half of a trade")
(Apply _fractional (Apply 1/2) (Apply trade))
js> db.parse(Program.PLUS, "do one half of a trade and roll")
(Apply _and_roll (Apply _fractional (Apply 1/2) (Apply trade)))
js> db.parse(Program.PLUS, "trade twice and roll")
(Apply _and_roll (Apply _fractional (Apply 2) (Apply trade)))
js> db.parse(Program.PLUS, "trade and roll twice")
(Apply _fractional (Apply 2) (Apply _and_roll (Apply trade)))
Semicolon-separated calls are also used in the typed
(not the spoken) grammar:
js> db = CallDB.INSTANCE ; undefined
js> db.parse(Program.PLUS, "circulate; trade; u turn back")
(Apply and (Apply circulate) (Apply trade) (Apply u turn back))
Parentheses can be used in the typed (not spoken) grammar:
js> db = CallDB.INSTANCE ; undefined
js> db.parse(Program.PLUS, "do one half of a trade and roll")
(Apply _and_roll (Apply _fractional (Apply 1/2) (Apply trade)))
js> db.parse(Program.PLUS, "do one half of a ( trade and roll )")
(Apply _fractional (Apply 1/2) (Apply _and_roll (Apply trade)))
Ensure we throw an exception if the call is unrecognized or
not on level:
js> db = CallDB.INSTANCE ; undefined
js> try {
> db.parse(Program.C4, "@trade")
> } catch (e) {
> print(e.javaException)
> }
net.cscott.sdr.calls.BadCallException: Not on list: @trade
js> try {
> db.parse(Program.C4, "foobar bat")
> } catch (e) {
> print(e.javaException)
> }
net.cscott.sdr.calls.BadCallException: Not on list: foobar bat
js> try {
> db.parse(Program.MAINSTREAM, "trade and roll")
> } catch (e) {
> print(e.javaException)
> }
net.cscott.sdr.calls.BadCallException: Not on list: trade and roll