Runtime Syntax (Cedric LEMAIRE)
29 Dec 2004 01:40:33 -0500

          From comp.compilers

Related articles
Runtime syntax (Dhruva Krishnamurthy) (2004-12-25)
Re: Runtime syntax (Dmitry A. Kazakov) (2004-12-29)
Re: Runtime syntax (2004-12-29)
Runtime Syntax (2004-12-29)
| List of all articles for this month |

From: (Cedric LEMAIRE)
Newsgroups: comp.compilers
Date: 29 Dec 2004 01:40:33 -0500
References: 04-12-119
Keywords: parse, tools
Posted-Date: 29 Dec 2004 01:40:33 EST

> We are trying to support text parsers for slightly differing
> syntax. I was looking at developing an engine where we can supply the
> grammar at runtime. I know Yacc/Bison is at compile time, is there
> some project/working proof of concept to achieve this? Any help is
> appreciated.

If you are working in C++, you can use the C++ runtime library of
CodeWorker (distributed under LGPL and available at
""). It is both a parser interpretor and a
source code generator. The extended-BNF parse scripts can be changed
at runtime.

If you just have to select a grammar amongst some already written and
frozen, the selection depending on a pre-analysis of the text for
instance, and the grammars being almost the same, you can:
    - isolate the common BNF rules in a CW parse script, and then
include them in each grammar, which will then add their specific
                #include "common-rules.cwp"
                specific_rule_1 ::= ...;
    - overload some of the common BNF rules (' particular grammars, if required,
                #include "common-rules.cwp"
                     - use the template writing of rules
                // in "common-rules.cwp", somewhere:
                statement ::=
                        procedure_call // a non-terminal
                        assignment // another non-terminal
                        // important part of this rule:
                        // read an identifier and put it into the
                        // variable 'sKeyword'
                        // call of a template-like rule:
                        // if sKeyword is worth 'while', the BNF rule
                        // statement_keyword<"while"> should have been defined
                // in one of the particular grammars:
                // add of a new statement, the C-like 'for'
                statement_keyword<"for"> ::=
                            '(' expression ';' expression ';' expression ')'

If you want to improve the speed of parsing, you can translate the CW
parse scripts to C++, using the switch '-c++' on the command line, and
then link them with a C++ applicaton.

I have already applied these features for recognizing short Financial
news: each time a new sentence template was appearing, its BNF
expression was added to the grammar in charge of detecting interesting
news. The improvements were applied dynamically: the grammar was
changing at runtime, which isn't what you are looking for, but which
is implemented similarly in the BNF scripts. The parse tree was just
holding the semantic data resulting of the sentence analysis.

But why to rewrite a new engine? If CodeWorker doesn't suit you, I'm
sure it exists some other tools that should answer your needs.

Post a followup to this message

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