Class: TuringMachine::InstructionsParser
- Inherits:
-
Object
- Object
- TuringMachine::InstructionsParser
- Defined in:
- lib/turing_machine/instructions_parser.rb
Overview
Public: Parser for a newline separated instruction set.
Instruction format
Here is an example file with four instructions :
“‘ 0 A => 1 R B 1 A => 1 L B 0 B => 1 L A 1 B => 1 R HALT “`
So each instruction is :
“‘ scanned-symbol current-state => symbol-to-write move next-state “`
‘symbol-to-write` is usually `1` or `0`. Note that `N` is a special symbol meaning «write nothing».
‘move` could be either `L` for left, `R` for right, or `N` for no movement.
Instance Method Summary collapse
-
#initialize(raw_instructions) ⇒ InstructionsParser
constructor
A new instance of InstructionsParser.
- #parse ⇒ Object
Constructor Details
#initialize(raw_instructions) ⇒ InstructionsParser
Returns a new instance of InstructionsParser.
30 31 32 33 |
# File 'lib/turing_machine/instructions_parser.rb', line 30 def initialize(raw_instructions) @lines = raw_instructions.split("\n") @instructions = {} end |
Instance Method Details
#parse ⇒ Object
35 36 37 38 |
# File 'lib/turing_machine/instructions_parser.rb', line 35 def parse build_instructions @instructions end |