# The DDA Domain Specific Language¶

The DDA domain specific language, also refered to as “traditional dda”, is the C-like language invented by Bernd for his Perl’ish dda code.

It basically reads as the following snippet:

# Single-line comments are written like this

dt = const(0.5)  # constants are defined like this
y0 = const(1)

z = mult(y, y)
y = int(y, dt, y0)


As you see, variables do not even have to be introduced and can be used in any order. There is only one data type, the analog line signal which is basically a real number within a fixed interval.

Note

Interestingly, traditional DDA files are a python subset and thus can be easily parsed and generated by python syntax. That’s why the code of this PyDDA module is so short. That’s also a primary reason why DDA was rewritten in Python.

Demonstration usage of this module:

>>> traditional_dda_document='''
... # Single-line comments are written like this
...
... dt = const(0.5)  # constants are defined like this
... y0 = const(1)
...
... z = mult(y, y)
... y = int(y, dt, y0)
... '''
>>> state
State({'dt': const(0.5), 'y': int(y, dt, y0), 'y0': const(1), 'z': mult(y, y)})
# Canonical DDA file generated by PyDDA

dt = const(0.5)
y = int(y, dt, y0)
y0 = const(1)
z = mult(y, y)

dda.dsl.to_traditional_dda(state, cleanup=True, prefix='# Canonical DDA file generated by PyDDA\n', suffix='\n')[source]

Export state to canonical dda file format (i.e. without all the python).

Returns the generated DDA file as string

dda.dsl.read_traditional_dda(content, return_ordered_dict=False)[source]

Read some traditional dda file. We use the Python parser (ast builtin) for this job. This is possible because the DDA syntax is a python subset and the parser doesn’t care about semantics, only syntax.

Thanks to the ast builtin package, we can just transform the python AST to the Symbolic/State class data structures used in this module.

Note

If some of the assertions fail, you can debug your DDA file by inspecting the output of ast.parse(content) on iPython. You can also run the Python debugger (pdb) on this function, for instance in iPython:

>>> %pdb


Returns a state instance or OrderedDict, on preference.

dda.dsl.read_traditional_dda_file(filename, **kwargs)[source]

Syntactic sugar for read_traditional_dda(), so users can directly pass a filename if the have their DDA code in a file.

dda.dsl.cli_exporter()[source]

A Command Line Interface (CLI) for PyDDA.

This CLI API does mainly what the old dda2c.pl script did, i.e. translating a (traditional) DDA file to C code. There are fewer options, because –iterations, –modulus and –variables are now runtime options for the generated C program.

However, we can generate much more then C. Output is always text.

Invocation is either python -m dda --help or python -m dda.dsl --help anywhere from the system. setup.py probably also installed a pydda binary somewhere calling the same. You can also just call ./dsl.py --help.