This weekend I've been reading about PLY. PLY is an implementation of lex and yacc parsing tools for Python. They are usually used together in Unix environments to generate parsers. I remember using them at university, but in a very limited way (and never studying its source code).

I've included some PLY features to pydsl. At this point the only available implementation is the PLYChecker, which checks if the given input follows the grammar specification.

There are more abstractions that can be easily implemented with ply in pydsl:
  • Lexer: ply includes a lex abstraction, which does exactly the same than the Lexer class
  • AST based translator: yacc allows to bundle code with any production, which is very similar with the SyntaxDirectedTranslator that is currently not working in pydsl

Hurray! more formats supported by pydsl

Update on 15/6/2013

I have added support for PLY translators to pydsl. The shell command to execute a translator is:

$ python3 bin/ -e "input:13*12" calc_ply
{'output': '156'}

calc_ply is a slightly modified version of the PLY example provided in the project website and it's included in pydsl/contrib .

Checking functionality is also available:

$ python3 bin/ -d 1 -e "1+1" calc_ply

Required changes

The following changes are required to make a PLY module work in pydsl:
  • pydsl requires the PLY module not to have any call to lex or yacc 
  • The initial symbol (statement) should store the result instead of printing the value
  • Lexer error should raise a ParseError (from pydsl.Exceptions) to enable checking functionality