views:

21

answers:

1

For a school project, I need to implement a parser for a (probably XML-based) markup language for User Interfaces. Based on the input it generates a HTML document with various UI components (textareas, inputs, panels, dialogs etc.)

Do you have any suggestions for tools/libraries I might use for this? (At school we use Flex and Bison, but we're allowed to use modern tools -- maybe a tool that has the capabilities of both lex and yacc)

+2  A: 

If your input is, as suggested, XML and your output is HTML, then that is the basic use case for XSLT. The whole point of XML is that you don't have to write your own parser, so if this was being done as a job of work rather than as a school project that would be the first technique to use. If you can't express it as a transformation, then you might look elsewhere.

If you don't want to use XML, then modern tools for plain-text languages include parser expression grammars and DSL synthesis tools such as Microsoft M.

PEGs free you from having to separately lex and parse, so a token can be context sensitive without complicating the grammar (as many tokens are in many languages), and some implementations mean you don't have to worry about left/right recursive loops.

DSL synthesis tools combine an IDE based grammar with a runtime semantics. Martin Fowler has a book on DSLs on his site.

But for a UI definition language that is the input to a transformation, either XML or some other standard mapping of structure (JSON, YAML) which can act as the input to an XSLT processor via the SAX interface would be the first thing I would try.

Pete Kirkham
Thank you for the direction!
Dan