Cmdgraph - a state-graph driven command interpreter

Recalling how we built a 2d cad system back in the 1980’s I have created

https://github.com/sgeard/cmdgraph

A snippet from the extensive README:
cmdgraph is a state-graph driven command interpreter — a parsing and dispatch kernel for building interactive command shells and REPL-style workflows. It is best understood as a pushdown transducer: a finite state graph on a runtime stack, where each transition can invoke an action and carry an opaque context value into the new state.

The Fortran version builds with fpm as well as Makefiles, and ifx, gfortran and flang are known to work; it does not build with lfortran.

I could not have done this without Claude 4.7, in particular examining the code paths to get the test coverage in to the 90%s is something I could not have done, neither could I have managed a cpp port as well.

3 Likes

Looks like a more sophisticated take on Python’s cmd module. The portability is a bonus!

Could be. I don’t know anything about Python or its capabilities. I just remember that it didn’t exist when I needed to choose a scripting language, then it was either Perl or Tcl - so Tcl it was and I’ve never seen any reason to change. I don’t seem to have mentioned that there is a Tcl module as well.

1 Like

It may be just me, but I did not see a Tcl cad-2d example.

You’re right, there’s only the Fortran and C++ versions. I’ve now updated it to add tools/cad_2d.cgl as an example of using the generator, e.g.

tclsh cmdgraph_gen.tcl cad_2d.cgl tcl > cad_2d.tcl

The generated code now contains stubs to the actions and a commented-out main program to show how to use it. The same is true for the Fortran and C++ versions.