diff options
| author | Tom Harley | 2018-07-04 21:08:05 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-07-04 21:08:05 +0100 |
| commit | 2ac50103672df10af130d3b1003980f087bc17dd (patch) | |
| tree | 5edfb47b87829964f7affdba7b41e94312e44cc0 /src/tmachinespkg/tm.nim | |
| parent | Remove extension auto-adding (diff) | |
| download | machines-2ac50103672df10af130d3b1003980f087bc17dd.tar.gz machines-2ac50103672df10af130d3b1003980f087bc17dd.zip | |
Add nondeterminism.
Add the ability to specify non-deterministic TMs. Listing multiple outcomes for a particular state-input combo will create a non-deterministic split instead of using only the latest one in the list.
Deterministic TMs should use a .dtm suffix, and non-deterministic TMs should use .ntm. TMs with the extension .tm will be assumed to be non-deterministic for compatability.
Diffstat (limited to 'src/tmachinespkg/tm.nim')
| -rw-r--r-- | src/tmachinespkg/tm.nim | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/tmachinespkg/tm.nim b/src/tmachinespkg/tm.nim index c009a60..7849054 100644 --- a/src/tmachinespkg/tm.nim +++ b/src/tmachinespkg/tm.nim @@ -12,25 +12,25 @@ type DTM* = ref object transitions*: Table[(state, letter), transition] configuration*: configuration -proc `[]`(this: DTM, i: int): letter = +proc `[]`*(this: DTM, i: int): letter = return this.configuration[i] -proc `[]=`(this: DTM, i: int, l: letter) = +proc `[]=`*(this: DTM, i: int, l: letter) = this.configuration[i] = l -proc `$`(this: DTM): string = +proc `$`*(this: DTM): string = return $this.configuration proc make_configuration*(desc: description, input: string): configuration = return make_configuration(desc.initial_state, input) -## Construct a TM description from an iterator of rules from a description file proc parse*(description: string): description = + ## Construct a TM description from an iterator of rules from a .dtm file var noStates = -1 var statesSeen = -1 var transitions = init_table[input, transition]() var acceptingStates = init_set[state]() - var currentState = cast[state]("") + var current_state = cast[state]("") var alphabet = false for line in description.split_lines: # If the line is empty @@ -48,7 +48,7 @@ proc parse*(description: string): description = acceptingStates.incl(split[0]) # If it's the first state mentioned if statesSeen == 0: - currentState = (split[0]) + current_state = (split[0]) statesSeen += 1 # If we haven't seen the alphabet yet elif not alphabet: @@ -69,7 +69,7 @@ proc parse*(description: string): description = transitions[(ins, inl)] = transition # Next line return description( - initial_state: currentState, + initial_state: current_state, acceptingStates: acceptingStates, transitions: transitions ) |
