parent
6257495fe4
commit
ebf57591a8
@ -0,0 +1,41 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"bytes" |
||||
"fmt" |
||||
"os" |
||||
|
||||
"github.com/mediocregopher/ginger/gg" |
||||
"github.com/mediocregopher/ginger/vm" |
||||
) |
||||
|
||||
func main() { |
||||
|
||||
if len(os.Args) < 3 { |
||||
fmt.Printf(`Usage: %s <operation source> "in = <value>"\n`, os.Args[0]) |
||||
return |
||||
} |
||||
|
||||
opSrc := os.Args[1] |
||||
inSrc := os.Args[2] |
||||
|
||||
inVal, err := gg.DecodeSingleValueFromLexer( |
||||
gg.NewLexer(bytes.NewBufferString(inSrc + ";")), |
||||
) |
||||
|
||||
if err != nil { |
||||
panic(fmt.Sprintf("decoding input: %v", err)) |
||||
} |
||||
|
||||
res, err := vm.EvaluateSource( |
||||
bytes.NewBufferString(opSrc), |
||||
inVal, |
||||
vm.GlobalScope, |
||||
) |
||||
|
||||
if err != nil { |
||||
panic(fmt.Sprintf("evaluating: %v", err)) |
||||
} |
||||
|
||||
fmt.Println(res) |
||||
} |
@ -0,0 +1,19 @@ |
||||
out = { |
||||
|
||||
decr = { out = add < (in; -1;); }; |
||||
|
||||
n = tupEl < (in; 0;); |
||||
a = tupEl < (in; 1;); |
||||
b = tupEl < (in; 2;); |
||||
|
||||
out = if < ( |
||||
isZero < n; |
||||
a; |
||||
recur < ( |
||||
decr < n; |
||||
b; |
||||
add < (a;b;); |
||||
); |
||||
); |
||||
|
||||
} < (in; 0; 1;); |
Loading…
Reference in new issue