[viff-devel] Small VIFF language parser

Martin Geisler mg at daimi.au.dk
Mon Jul 7 14:00:02 PDT 2008


Hi everybody,

We have talked on and off about making a front-end compiler for VIFF and
today I figured that I would try making such a guy...

So far it can only parse a simple language and spit out something which
looks like equivalent Python code in which both branches of
if-statements are run. So a program like this:

  if a:
    x = y
    if b:
      x = z
    else:
      x = w
    fi
  fi

is transformed into this

  x = (a * y + (1 - a) * x)
  x = (a * b * z + (1 - a * b) * x)
  x = ((1 - a * b) * w + (1 - (1 - a * b)) * x)

which one could plug into a VIFF skeleton and run (not yet done).

The idea is that the conditions in if-statements are pushed down to all
assignments done in the then- and else-branches, nothing more.

This is just a quick test to make people start thinking about what we
want in such a language and to make people think about what kind of
transformation we can do and which we cannot do.

The program is attached below -- you will need to grab simplegeneric and
PLY (Python Lex-Yacc) to use it, but both modules are easy to install:

  http://pypi.python.org/pypi/simplegeneric
  http://www.dabeaz.com/ply/

You run the program by giving it the name of a file to parse and it will
tell you the results on stdout.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: parser.py
Type: text/x-python
Size: 6007 bytes
Desc: not available
URL: <http://lists.viff.dk/pipermail/viff-devel-viff.dk/attachments/20080707/3458b0df/attachment.py>
-------------- next part --------------

-- 
Martin Geisler


More information about the viff-devel mailing list