Sha256: b80f4e79adc056983b491ceace3a4865e2fc88a159370f5ffbc622c3179162e2

Contents?: true

Size: 1.32 KB

Versions: 202

Compression:

Stored size: 1.32 KB

Contents

grammar Arithmetic  
  rule expression
    comparative / additive
  end
  
  rule comparative
    head:additive
    tail:(
      space operator:equality_op
      space operand:additive)* <BinaryOperation>
  end
  
  rule equality_op
    '==' {
      def apply(a, b)
        a == b
      end
    }
  end
  
  rule additive
    head:multitive
    tail:(
      space operator:additive_op
      space operand:multitive)* <BinaryOperation>
  end
  
  rule additive_op
    '+' {
      def apply(a, b)
        a + b
      end
    }
    /
    '-' {
      def apply(a, b)
        a - b
      end
    }
  end

  rule multitive
    head:primary
    tail:(
      space operator:multitive_op
      space operand:primary)* <BinaryOperation>
  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

202 entries across 187 versions & 30 rubygems

Version Path
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-input-fifo-0.9.0 vendor/bundle/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/treetop-1.4.15/examples/lambda_calculus/arithmetic.treetop