grammar Arithmetic rule expression comparative / additive end rule comparative operand_1:additive space operator:comparison_op space operand_2:additive end rule comparison_op '>=' { def apply(a, b) a >= b end } / '<=' { def apply(a, b) a <= b end } / '>' { def apply(a, b) a > b end } / '<' { def apply(a, b) a < b end } / '!=' { def apply(a, b) a != b end } / '=' { def apply(a, b) a == b end } end rule additive operand_1:multitive space operator:additive_op space operand_2:additive / multitive end rule additive_op '+' { def apply(a, b) a + b end } / '-' { def apply(a, b) a - b end } end rule multitive operand_1:primary space operator:multitive_op space operand_2:multitive / primary end rule multitive_op '*' { def apply(a, b) a * b end } / '/' { def apply(a, b) a / b end } end rule number ('-'? [1-9] [0-9]* / '0') { def eval(env={}) text_value.to_i end } end rule space ' '* end end