Sha256: f44952c37585b86a2470246a715073fa49223010e33e4f7e99e47cdacdb98e3d

Contents?: true

Size: 1.32 KB

Versions: 112

Compression:

Stored size: 1.32 KB

Contents

grammar Arithmetic  
  rule expression
    comparative / additive
  end
  
  rule comparative
    operand_1:additive space operator:equality_op space operand_2:additive <BinaryOperation>
  end
  
  rule equality_op
    '==' {
      def apply(a, b)
        a == b
      end
    }
  end
  
  rule additive
    operand_1:multitive
    space operator:additive_op space
    operand_2:additive <BinaryOperation>
    /
    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 <BinaryOperation>
    /
    primary
  end
  
  rule multitive_op
    '*' {
      def apply(a, b)
        a * b
      end
    }
    /
    '/' {
      def apply(a, b)
        a / b
      end
    }
  end  
  
  rule primary
    variable
    /
    number
    /
    '(' space expression space ')' {
      def eval(env={})
        expression.eval(env)
      end
    }
  end

  rule variable
    [a-z]+ {
      def eval(env={})
        env[name]
      end
      
      def name
        text_value
      end
    }
  end

  rule number
    ([1-9] [0-9]* / '0') {
      def eval(env={})
        text_value.to_i
      end
    }
  end
  
  rule space
    ' '*
  end
end

Version data entries

112 entries across 82 versions & 10 rubygems

Version Path
depengine-0.0.22 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.21 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.21 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.20 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.20 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.19 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.19 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.18 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.18 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.17 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.17 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.16 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.16 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.15 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.15 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.14 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.14 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.13 etc/isolate/jruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.13 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop
depengine-0.0.12 etc/isolate/ruby-1.8/gems/treetop-1.4.8/examples/lambda_calculus/arithmetic.treetop