Jonathan C Dickinson Jonathan C Dickinson 7, 4 4 gold badges 34 34 silver badges 46 46 bronze badges. Gian Marco Gian Marco Kevin Kelley Kevin Kelley 21 2 2 bronze badges. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 8. Related Hot Network Questions.
View code. It can be overloaded in derived classes. Overloading of base methods char comparison, substring search, eoi detection or etc also supported.
It is possible to use user defined methods in any part of syntax definition they declared as abstract in parser. Whole document consist of four parts: "above lines", class definition, bnf grammar and "below lines". Each entity defines possible structure of input which can be parsed.
Possible terminals:. Escaping in symbols and strings as in C. Ranges acceps backslash-octal-value escaping. Class contains service, parser, auxiliary and abstract methods. Service methods are used to detect terminals or end of input. Parser methods have same names as bnf entities and used to detect correspondent pattern. Auxiliary methods usually called from parser methods. They exist due to construction logic of parser methods code. In a meanwhile, Marpa::R2 based on libmarpa does exactly what you need -- takes a string describing BNF and lexer rules and builds the recognizer -- a parser you can use directly to produce an AST or evaluate it via semantic actions.
There are efforts to wrap libmarpa conveniently to do what you said 1 , 2. There is also a Kollos project aimed at extending and wrapping libmarpa using Lua. If your intention is to parse only small files for the purpose of "is this valid syntax", you might do this with an Early parser. Big files parsed this way will be pretty slow.
Your problem will be defining tokens; if you Earley-parse at the character level, you will get a parse but it will be worse than Early-parsing on language tokens. If you want larger scale parsing, you'll need a tool that lets you define tokens and grammars. This is the very thing you say you don't want. If you want a tool that produces trees , you might be able to modify the Earley parser to produce trees. But back to efficiency: if you want some scale, you're likely to need a library for managing the tree nodes.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more.
C library that takes a BNF definition and parses accordingly? Asked 7 years, 1 month ago.
0コメント