Sha256: d8a14a9946fa59c8c5d96c7891e11e0aea9a59f4ae749c9c6c897eb911bb7217

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

grammar Arithmetic  
  rule expression
    comparative / additive
  end
  
  rule comparative
    operand_1:additive space operator:comparison_op space operand_2:additive <BinaryOperation>
  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 <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 number
    ('-'? [1-9] [0-9]* / '0') {
      def eval(env={})
        text_value.to_i
      end
    }
  end
  
  rule space
    ' '*
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
robolson-simplesem-0.1.0 lib/simplesem/arithmetic.treetop
robolson-simplesem-0.1.1 lib/simplesem/arithmetic.treetop
robolson-simplesem-0.1.2 lib/simplesem/arithmetic.treetop
robolson-simplesem-0.1.3 lib/simplesem/arithmetic.treetop