Related articles |
---|
Grammar to automation translation at runtime (NOT at compile time)? sarkar_soumen@yahoo.com (2003-05-14) |
RE: Grammar to automation translation at runtime (NOT at compile time) qjackson@shaw.ca (Quinn Tyler Jackson) (2003-05-16) |
From: | Quinn Tyler Jackson <qjackson@shaw.ca> |
Newsgroups: | comp.compilers |
Date: | 16 May 2003 21:56:09 -0400 |
Organization: | Compilers Central |
References: | 03-05-085 |
Keywords: | parse |
Posted-Date: | 16 May 2003 21:56:09 EDT |
> Therefore, my question is if there is any thought/effort to make the
> grammar to automation (a computational service) make
> available at run
> time? I am interested in CFG based generators (current impls are
> JavaCC, ANTLR).
>
> If this would be possible, I just have to supply a grammar
> file at run
> time to validate an ASCII stream -- I do not have to make a
> commitment
> at compile time. Only commitment I make that I will supply a valid
> grammar file to which the ASCII stream is validated (no nore grammar
> to Java/C# codegen/compile/write code on top of generated code).
>
> I took a look at Recursive Adaptive Grammar (which blurs the
> distinction between grammar vs automation) and it may hold certian
> potential towards dynamic grammar based validation.
Meta-S allows grammars to be instantiated at run-time from strings
(which could be stored in text files). The CLpmGrammar class has a
member function:
bool InstantiateFromString(const CShuString& ssGrammar, bool
bDoSemanticChecks);
So, for instance, if your grammar is saved as an .abn file, which in
flat ASCII, looks something like this:
grammar TheGrammar
{
S ::= A B C;
A ::= /* whatever */;
// etc;
};
You do something like this:
CLpmGrammar gmr;
CShuString ssGrammar = LoadFromFile("the_grammar.abn");
CShuString ssTestInput = LoadFromFile("test_input.txt");
if(gmr.InstantiateFromString(ssGrammar, false))
{
if(gmr.Accept(ssTestInput))
{
// you can now traverse the parse tree
}
else
{
// grammar did not accept input
}
}
You can effectively do the above with the ABN2CPP utility (included
with Meta-S) thusly:
abn2cpp the_grammar.abn -i test_input.txt
You can develop your grammars either in a simple text editor, in
Meta-S Lite, or in Meta-S, a graphical grammar development environment
which allows you to debug the grammar against test input.
For more information, either visit http://www.meta-s.com or email me
directly.
Cheers.
--
Quinn Tyler Jackson
Return to the
comp.compilers page.
Search the
comp.compilers archives again.