diff options
Diffstat (limited to 'src/tmachines.nim')
| -rw-r--r-- | src/tmachines.nim | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/tmachines.nim b/src/tmachines.nim index 2d1d190..aae5401 100644 --- a/src/tmachines.nim +++ b/src/tmachines.nim @@ -3,6 +3,27 @@ import os, strutils import docopt from tmachinespkg/tm import nil +from tmachinespkg/ntm import nil + +type Machine = enum + DTM, NTM + +proc tm_type_from_cli(value: string): Machine = + case value + of "dtm": + return DTM + of "ntm": + return NTM + else: + return NTM + +proc tm_type_from_filename(filename: string): Machine = + if filename.ends_with(".dtm"): + return DTM + elif filename.ends_with(".ntm"): + return NTM + elif filename.ends_with(".tm"): + return NTM const tmname {.strdefine.}: string = "" @@ -18,6 +39,16 @@ else: let args = docopt(doc) let file = $args["<machine>"] - if file.ends_with(".tm") or file.ends_with(".dtm"): - let tmd = tm.parse(readFile($args["<machine>"])) - echo tm.test(tm.makeDTM(tmd, $args["<input>"]), not args["--quiet"]) + var m_type: Machine + if $args["--type"] != "nil": + m_type = tm_type_from_cli($args["--type"]) + else: + m_type = tm_type_from_filename(file) + + case m_type: + of DTM: + let tmd = tm.parse(readFile($args["<machine>"])) + echo tm.test(tm.makeDTM(tmd, $args["<input>"]), not args["--quiet"]) + of NTM: + let tmd = ntm.parse(readFile($args["<machine>"])) + echo ntm.test(ntm.makeNTM(tmd, $args["<input>"]), not args["--quiet"]) |
