views:

1573

answers:

5

I find myself drawn to the Parsing Expression Grammar formalism for describing domain specific languages, but so far the implementation code I've found has been written in languages like Java and Haskell that aren't web server friendly in the shared hosting environment that my organization has to live with.

Does anyone know of any PEG libraries or PackRat Parser Generators for Javascript or PHP? Of course code generators in any languages that can produce Javascript or PHP source code would do the trick.

+6  A: 

There is in fact one for Javascript: OMeta. http://www.cs.ucla.edu/~awarth/ometa/

I also implemented a version of this in Python: http://launchpad.net/pymeta

Allen
Updated link for [OMeta](http://www.tinlizzie.org/ometa/)
benizi
A: 

Have you looked at ANTLR? It produces lexer and parser code, handles abstract syntax trees, lets you insert code the grammar to be injected into the lexer/parser code, and its available for a variety of languages!

Joe Skora
ANTLR does a lot of stuff, but it doesn't do PEGs.
Allen
A: 

look at http://www.codeplex.com/NPEG can easily be converted into php. Parse tree is created with anonymous functions.

A: 

There's also Kouprey for JavaScript, which is a very easy to use PEG generator/library.

+1  A: 

I have recently written PEG.js, PEG-based parser generator for JavaScript. It can be used from a command-line or you can try it from your browser.

David Majda