Related articles |
---|
Runtime syntax Dhruva.Krishnamurthy@in.bosch.com (Dhruva Krishnamurthy) (2004-12-25) |
Re: Runtime syntax mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2004-12-29) |
Re: Runtime syntax nmm1@cus.cam.ac.uk (2004-12-29) |
Runtime Syntax codeworker@free.fr (2004-12-29) |
From: | codeworker@free.fr (Cedric LEMAIRE) |
Newsgroups: | comp.compilers |
Date: | 29 Dec 2004 01:40:33 -0500 |
Organization: | http://groups.google.com |
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
"http://www.codeworker.org"). 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
rules,
#include "common-rules.cwp"
...
specific_rule_1 ::= ...;
- overload some of the common BNF rules ('
#include "common-rules.cwp"
...
// 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'
#readIdentifier:sKeyword
// call of a template-like rule:
// if sKeyword is worth 'while', the BNF rule
// statement_keyword<"while"> should have been defined
statement_keyword<sKeyword>
|
...
;
------------------------
// in one of the particular grammars:
// add of a new statement, the C-like 'for'
statement_keyword<"for"> ::=
'(' expression ';' expression ';' expression ')'
statement
;
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.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.