Re: Choosing a parser for Mathematica input

"Ira Baxter" <idbaxter@semdesigns.com>
Fri, 26 Nov 2010 11:54:08 -0600

          From comp.compilers

Related articles
Choosing a parser for Mathematica input drkirkby@gmail.com (David Kirkby) (2010-11-07)
Re: Choosing a parser for Mathematica input jthorn@astro.indiana-zebra.edu (Jonathan Thornburg \[remove -animal to reply\]) (2010-11-09)
Re: Choosing a parser for Mathematica input haberg-news@telia.com (Hans Aberg) (2010-11-09)
Re: Choosing a parser for Mathematica input drkirkby@gmail.com (David Kirkby) (2010-11-09)
Re: Choosing a parser for Mathematica input winkzhang@gmail.com (Wink Zhang) (2010-11-13)
Re: Choosing a parser for Mathematica input idbaxter@semdesigns.com (Ira Baxter) (2010-11-26)
Re: Choosing a parser for Mathematica input drkirkby@gmail.com (David Kirkby) (2010-11-26)
Re: Choosing a parser for Mathematica input drkirkby@gmail.com (David Kirkby) (2010-11-27)
| List of all articles for this month |

From: "Ira Baxter" <idbaxter@semdesigns.com>
Newsgroups: comp.compilers
Date: Fri, 26 Nov 2010 11:54:08 -0600
Organization: Compilers Central
References: 10-11-017
Keywords: parse
Posted-Date: 26 Nov 2010 23:29:43 EST

"David Kirkby" <drkirkby@gmail.com> wrote in message
> I'd like to write a program that uses a Mathematica-like syntax. Not a
> 100% clone, but as close to Mathematica input as reasonably practical.
> Can anyone suggest a suitable front end parser? I was thinking of
> using LLVM for the back end.


Others have noted that LLVM is much more than a parser. Are you
trying to generate *code* from MMa syntax? Are you trying to generate
code from pure MMa equations or from actual MMa programs?


> Here's a description of the syntax
>
> http://reference.wolfram.com/mathematica/guide/Syntax.html
> http://reference.wolfram.com/mathematica/tutorial/TheSyntaxOfTheMathematicaLanguage.html
>
> Things to note in particular is that whitespace can often mean
> multiplication. i.e.


> I've never written a compiler, beyond noddy calculators in
> introductory books, so I suspect this language is not an ideal one to
> learn with. But I'd be interested in what, if any tools would be
> capable of handling such a complex language,


MMa (equations or programs) isn't a particularly complex language,
either conceptually or from the point of view of a parser.
Mostly it is Lisp S-expressions using xyz[...] instead of (xyz ...).
*Executing* MMa code is a bit messier; you need a program
transformation system to do pattern-match/rewrites to implement
much of the semantics. And of course of your code contains any
complicated formulas needing simplification,
you might need all of MMa proper to provide the necessary
set of rewrites that encode all that math knowledge.


FWIW, our DMS Software Reengineering Toolkit (a program
transformation system) has a working MMa langauge parser
as an available option (see website for more details).
We use a GLR parser for all of our parsers;
I suspect that's overkill for the MMa grammar but it seems to work fine.


--
Ira Baxter, CTO
www.semanticdesigns.com


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.