[IPython-dev] IPython-dev Digest, Vol 131, Issue 2
Kyle Rawlins
rawlins at gmail.com
Wed Dec 3 12:44:04 EST 2014
On Dec 3, 2014, at 11:37 AM, ipython-dev-request at scipy.org wrote:
> Date: Wed, 3 Dec 2014 17:37:14 +0100
> From: Joachim Wuttke <j.wuttke at fz-juelich.de>
> Subject: [IPython-dev] How to parse a domain-specific language on top
> of Python
> To: <ipython-dev at scipy.org>
> Message-ID: <547F3C3A.6050106 at fz-juelich.de>
> Content-Type: text/plain; charset="utf-8"
>
> ((cross-posting from http://stackoverflow.com/questions/27274607
> where this question gets close votes for being "too broad":))
>
>
> I want to construct a domain-specific language as a superset of Python.
> Cryptic commands like
>
> f7:10y=x^2
>
> designed to minimize typing shall be parsed into plain Python
>
> for k in range(7,10):
> f[k].set_y( expr='x^2' )
>
> before being executed. Probably, the command-line interface shall be
> IPython.
>
> What would be an appropriate architecture: Shall I implement the
> cryptic-to-plain-Python translation in the IPython command-line shell or
> in its kernel daemon? Are there helpful libraries / tutorials / examples?
I think the most straightforward approach would be to do this kind of thing using IPython magics, probably in IPython notebook. For an (alpha) example of this, you may find it helpful to look at my IPython Lambda Notebook project which uses cell magics to interface notebooks with a parser for a domain-specific mini-language (the domain is linguistics, in particular linguistic semantics, so the mini-language is a typed logic/lambda calculus). The magics pass things to the parser, and variable assignments in the mini-language are injected back into the environment in a very straightforward way, so it’s easy to switch back and forth between the mini-language and python code. I wouldn’t really recommend my approach to parsing and interpreting the mini-language, though, which is tailored to an extremely specific brand of scientific computing (and not for actually doing efficient parsing or computation).
https://github.com/rawlins/lambda-notebook
Less relevant to this mailing list but I’d also caution against literally targeting a superset of python, this will be really, really hard to get right. At least start with a domain-specific language that is python-like but tractable.
Best,
-kyle
--
Kyle Rawlins
http://sites.krieger.jhu.edu/rawlins/
Department of Cognitive Science
Johns Hopkins University
More information about the IPython-dev
mailing list