Class: CodeParsesQInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/code/code_parses_q.rb

Overview

pops the top :code item; pushes a new :bool with value true if the :code can be parsed

needs: 1 :code

pushes: 1 :bool

Instance Attribute Summary

Attributes inherited from Instruction

#context

Instance Method Summary collapse

Methods inherited from Instruction

all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode

Constructor Details

This class inherits a constructor from Instruction

Instance Method Details

#cleanupObject



20
21
22
# File 'lib/instructions/code/code_parses_q.rb', line 20

def cleanup
  pushes :bool, @result
end

#deriveObject



16
17
18
19
# File 'lib/instructions/code/code_parses_q.rb', line 16

def derive
  answer = NudgeProgram.new(@arg1).parses? ? true : false
  @result = ValuePoint.new("bool", answer)
end

#preconditions?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/instructions/code/code_parses_q.rb', line 10

def preconditions?
  needs :code, 1
end

#setupObject



13
14
15
# File 'lib/instructions/code/code_parses_q.rb', line 13

def setup
  @arg1 = @context.pop_value(:code)
end