Class: Prattle::AST::Operator

Inherits:
Node
  • Object
show all
Defined in:
lib/prattle/ast/operator.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Node

#run

Constructor Details

- (Operator) initialize(operator, lhs, rhs)

Returns a new instance of Operator



10
11
12
13
14
# File 'lib/prattle/ast/operator.rb', line 10

def initialize(operator, lhs, rhs)
  @operator = operator
  @lhs = lhs
  @rhs = rhs
end

Instance Attribute Details

- (Object) lhs (readonly)

Returns the value of attribute lhs



16
17
18
# File 'lib/prattle/ast/operator.rb', line 16

def lhs
  @lhs
end

- (Object) operator (readonly)

Returns the value of attribute operator



16
17
18
# File 'lib/prattle/ast/operator.rb', line 16

def operator
  @operator
end

- (Object) rhs (readonly)

Returns the value of attribute rhs



16
17
18
# File 'lib/prattle/ast/operator.rb', line 16

def rhs
  @rhs
end

Class Method Details

+ (Object) grammar(g)



18
19
20
21
22
23
24
25
26
# File 'lib/prattle/ast/operator.rb', line 18

def self.grammar(g)
  g.operators = g.any("+", "-", "*", "/", ">=", ">", "<=", "<")
  g.operator = g.seq(:operator, :sp, :operators, :sp, :level2) { |l,_,o,_,r|
                    Operator.new(o,l,r)
                  } \
             | g.seq(:level2, :sp, :operators, :sp, :level2) { |l,_,o,_,r|
                    Operator.new(o,l,r)
                  }
end

+ (Object) rule_name



6
7
8
# File 'lib/prattle/ast/operator.rb', line 6

def self.rule_name
  "operator"
end

Instance Method Details

- (Object) bytecode(g)



28
29
30
31
32
# File 'lib/prattle/ast/operator.rb', line 28

def bytecode(g)
  @lhs.bytecode(g)
  @rhs.bytecode(g)
  g.send @operator.to_sym, 1
end