capitalex ha revisionato questo gist . Vai alla revisione
1 file changed, 6 insertions, 1 deletion
something.lua
@@ -4,5 +4,10 @@ local operations = { ... } | |||
4 | 4 | ||
5 | 5 | while #ops > 0 do | |
6 | 6 | local op = pop(operation_stack) | |
7 | - | operations[op](operation_stack, fact_pool) | |
7 | + | if operations[op] then | |
8 | + | operations[op](operation_stack, fact_pool) | |
9 | + | else | |
10 | + | if not fact_pool[op] then fact_pool[op] = 0 end | |
11 | + | fact_pool[op] = fact_pool[op] + 1 | |
12 | + | end | |
8 | 13 | end |
capitalex ha revisionato questo gist . Vai alla revisione
1 file changed, 8 insertions
something.lua(file creato)
@@ -0,0 +1,8 @@ | |||
1 | + | local operation_stack = { ... } | |
2 | + | local fact_pool = { ... } | |
3 | + | local operations = { ... } | |
4 | + | ||
5 | + | while #ops > 0 do | |
6 | + | local op = pop(operation_stack) | |
7 | + | operations[op](operation_stack, fact_pool) | |
8 | + | end |
capitalex ha revisionato questo gist . Vai alla revisione
2 files changed, 41 insertions
generate-code.lua(file creato)
@@ -0,0 +1,22 @@ | |||
1 | + | ||
2 | + | function run_rules(state) | |
3 | + | if state["flour"] >= 1 and state["sugar"] >= 1 and state["apples"] >= 1 then | |
4 | + | emit(state, "apple cake") | |
5 | + | return run_rules(state) | |
6 | + | elseif state["apples"] >= 1 and state["oranges"] >= 1 and state["cherries"] >= 1 then | |
7 | + | emit(state, "fruit salad") | |
8 | + | return run_rules(state) | |
9 | + | elseif state["fruit salad"] >= 1 and state["apple cake"] >= 1 then | |
10 | + | emit(state, "fruit cake") | |
11 | + | return run_rules(state) | |
12 | + | else | |
13 | + | end | |
14 | + | end | |
15 | + | ||
16 | + | tally(state, "sugar") | |
17 | + | tally(state, "oranges") | |
18 | + | tally(state, "apples") | |
19 | + | tally(state, "cherries") | |
20 | + | tally(state, "flour") | |
21 | + | tally(state, "apples") | |
22 | + | run_rules(state) |
linear-multiset-catlang.txt(file creato)
@@ -0,0 +1,19 @@ | |||
1 | + | function (run rules) [flour sugar apples] | |
2 | + | (> (apple cake)) (run rules) | |
3 | + | end | |
4 | + | ||
5 | + | function (run rules) [apples oranges cherries] | |
6 | + | (> (fruit salad)) (run rules) | |
7 | + | end | |
8 | + | ||
9 | + | function (run rules) [(fruit salad) (apple cake)] | |
10 | + | (> (fruit cake)) (run rules) | |
11 | + | end | |
12 | + | ||
13 | + | function (run rules) [] | |
14 | + | end | |
15 | + | ||
16 | + | (> sugar) (> oranges) | |
17 | + | (> apples) (> cherries) | |
18 | + | (> flour) (> apples) | |
19 | + | (run rules) |