5 ms·
The major parser libraries that I could find don't allow adding syntax at runtime or to add operators to the expression hierarchy at runtime. Many (though not a
by wbhart 14y ago
The major parser libraries that I could find don't allow adding syntax at runtime or to add operators to the expression hierarchy at runtime. Many (though not all) of them also make it difficult to do custom error reporting. These were my major motivations.
- _delirium 14y agoAh right, interesting use-case. I usually think of combinator parsing's advantages versus table-driven parsing (e.g. LALR) being primarily its expressiveness (and amenability to a functional-programming style), but it has a nice runtime-modifiable aspect as well. I wonder how hard it'd be to build a runtime-modifiable table-driven parser, though. Assuming table compilation is fast enough, the most straightforward approach might be to just link in the grammar-compilation code so it's available at runtime, and rebuild the table each time a modification is made. I don't think you'd want to be doing complex incremental surgery on a table-driven parser, but you might not need to.
- alok-g 14y agoDoesn't Boost.Spirit [1] allow adding syntax and operators at runtime? (Seriously asking; have never used Spirit) [1] http://boost-spirit.com/home/ http://boost-spirit.com/home/
- _stephan 14y agoFParsec's OperatorPrecedenceParser component[1] does support adding (and removing) operators to the expression grammar at runtime. [1] http://www.quanttec.com/fparsec/reference/operatorprecedenceparser.html http://www.quanttec.com/fparsec/reference/operatorprecedence...
- beagle3 14y agoNot C .. but are you familiar with Ometa (and its variations, Ometa/JS, Ometa#, PyMeta, etc?) http://tinlizzie.org/ometa/ http://tinlizzie.org/ometa/ It's a turing-complete parser specification language with an interpreter that is very close to being a packrat parser, which embraces adding and extending syntax (in a more general way than your library does, if I understand correctly). Implementing the same idea in C should be possible. I have no idea why you want to add syntax at runtime, but the Ometa model might fit your plans better.