From 2ac50103672df10af130d3b1003980f087bc17dd Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Wed, 4 Jul 2018 21:08:05 +0100 Subject: 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. --- src/tmachinespkg/tm.nim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/tmachinespkg/tm.nim') 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 ) -- cgit v1.2.1