Class: Kward::NativeShell::Arithmetic::Parser
- Inherits:
-
Object
- Object
- Kward::NativeShell::Arithmetic::Parser
- Defined in:
- lib/kward/shell/native_arithmetic.rb
Constant Summary collapse
- LEVELS =
[ %w[,], %w[= += -= *= /= %= <<= >>= &= ^= |=], %w[?], %w[||], %w[&&], %w[|], %w[^], %w[&], %w[== !=], %w[< <= > >=], %w[<< >>], %w[+ -], %w[* / %], %w[**] ].freeze
- PRECEDENCE =
LEVELS.each_with_index.each_with_object({}) { |(operators, index), result| operators.each { |operator| result[operator] = index + 1 } }.freeze
Instance Method Summary collapse
-
#initialize(source) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(source) ⇒ Parser
Returns a new instance of Parser.
167 168 169 170 171 |
# File 'lib/kward/shell/native_arithmetic.rb', line 167 def initialize(source) @scanner = StringScanner.new(source) @depth = 0 advance end |
Instance Method Details
#parse ⇒ Object
173 174 175 176 177 |
# File 'lib/kward/shell/native_arithmetic.rb', line 173 def parse result = expression raise Error, "unexpected token in arithmetic expression" if @token result end |