From 3143763fc098ce2c46b84e38c6cedabbf4622fa2 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sun, 13 May 2018 23:53:42 +0100 Subject: Reorganise project structure --- src/mt.nim | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/mt.nim (limited to 'src/mt.nim') diff --git a/src/mt.nim b/src/mt.nim new file mode 100644 index 0000000..8055921 --- /dev/null +++ b/src/mt.nim @@ -0,0 +1,41 @@ +import uuid +import sets +import os +import tables +import strutils + +import lib + +proc accept( + this: var ttable, + initialState: state, + input: string, + u: string +): state {.discardable.} = + var cs = initialState + for c in input: + if not this.hasKey((cs, c)): + this[(cs, c)] = (u, '_', Inc) + cs = this[(cs, c)].newState + return cs + +proc esarp(content: string): description = + var tt = initTable[input, transition]() + var ac = initSet[state]() + var i = 0 + const initialState = "S" + for line in content.splitLines: + if line.len <= 0: continue + let split = line.split(' ') + if split[1].parseBool(): + ac.incl tt.accept(initialState, split[0], $i) + i += 1 + return (initialState, ac, tt) + +const tmname {.strdefine.}: string = "addition" +const desc = esarp(slurp(tmname & ".tmt")) + +if paramCount() >= 1: + echo makeDTM(desc, paramStr(1)).test(true) +else: + echo desc.toFile() -- cgit v1.2.1