Long story longer, I'm trying to convert a templating language from Perl to C#. I finally settled on ANTLR because of ANTLRWorks. It's invaluable for someone like me just starting.
I got my ANTLR Reference from Amazon yesterday and joined the list so I could avoid email bombing our BDFL. :-) As I see it, I have the basic direction ahead of me: Create a grammar: - 1 grammar: split code from HTML and express code syntax - 2 grammars: one to split code/html, one for just the code syntax Translate to C#: - no tree, output C# - AST tree, then translate AST to C# After a first pass through the book, it seems an AST tree means I can create multiple targets, allowing people to reuse my grammar/lexer/parser to output other language versions (VB.NET, MSIL), assuming I'm good about keeping any target specific language out of the lexer/parser grammar. A few things I'm unclear about... First, I didn't see in the book, what's the best way to perform multiple passes against an AST tree? Is that just a matter of creating multiple tree grammar files, and sending one CommonTree into another CommonTree in code? What about the initial steps of dealing with code and html in a file? IIRC, Terence mentioned that StringTemplate does multi pass... once to separate the html block form the code, then more code the code itself. Is that lexing/parsing the file, then each block, is is that multiple grammars against the same tokenized output? Here's a sample template: Hello [% GET World %]. [% IF name %] Hello [% GET name %]. [% END %] I assume that the IF/END blocks need to stay together and that in some pass, any text in between %] [% get's turned into string literals. "Hello " [% GET World %] "." [% IF name %]" Hello "[% GET name %]"."[% END %] I've also wondered what would happen if the file is reversed right up front by replacing tags and trying to do it in one pass turning the blocks into strings that are just printed out later in their proper order. [%Hello %] GET World [%. %] IF name [% Hello %] GET name [%. ]% END Yes, I have no idea what I'm doing, or should be doing. :-) I have managed to get enough of a grammar together to get some working GET/SET statements, run the lexer/parser and output a tree. -=Chris List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-interest@googlegroups.com To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---