[antlr-interest] [comp.compilers.tools.pccts] Re: Is there a run-time parsing facility
micheal_jor
open.zone at virgin.net
Wed May 7 02:44:45 PDT 2003
The exchange below from the pccts newsgroup properly belongs here...
I'd just like to add that the technique Kunle describes applies to
Java as well.
Not sure about how it can be done with C++ in the general case, Ric?.
Monty?
Cheers,
Micheal
<=========== from comp.compilers.tools.pccts =============>
Soumen Sarkar wrote:
> All,
>
> Currently the parsing technology allows grammar to automation
> translation in compile time only. For example if I have to validate
a
> text stream that I am receiving, I can not load a grammar file
> dynamically and validate the text stream.
<SNIP>
> Java/C# offer reflection features which allows equivalent programs
> to be authored both at compile time or runtime.
For C#, you could investigate dymamic assemblies - assemblies that
you create at run time. Then you could:
1. Load your grammar file (note your grammar files must obviously be
error free)
2. Execute ANTLR to generate C# source
3. Create an assembly dynamically that contains your Lexer/Parser (or
better still architect your system to use a single pre-generated
Lexer)
4. Load the assembly into your AppDomain and use the parser as usual
Some issues:
1. To be able to access the functionality in dynamic assemblies, your
types should (must?) implement interfaces that your system is already
aware of. For Lexers, ANTLR already has TokenStream etc. You will
need to provide similar for Parsers and TreeParsers and use
the "classHeaderSuffix" option in your grammar files to ensure your
Parsers/TreeParsers implements them.
2. Your interface above must define a common entry point for
validation (and your grammars must implement the entry point) or you
will need to use reflection to invoke arbitary entry points.
Anyways, I guess you've got the idea...
Good luck,
Kunle
ANTLR/C# codegen team
> Therefore, my question is if there is any thought/effort to make the
> grammar to automation (a computational service) make available at
run
> time?
>
> Does this proposal/wish make sense at all?
>
> 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).
>
> Thanks,
> Soumen Sarkar.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list