[antlr-interest] Removing output=AST lets ANTLR fail to generate

Eric researcher0x00 at gmail.com
Fri Nov 11 16:03:41 PST 2011


On Fri, Nov 11, 2011 at 7:03 PM, Eric <researcher0x00 at gmail.com> wrote:

>
>
> On Fri, Nov 11, 2011 at 5:00 PM, Christian <chwchw at gmx.de> wrote:
>
>> > So, in other words, the feature request is that AST-related syntax be
>> > ignored if output!=AST?
>> Very well summarized! Yes.
>>
>> > The only thing I wonder is, for that not-generating-an-AST-any-more
>> > parser, wouldn't it need some different actions from the original
>> > AST-generating version in order to be any use whatsoever?
>> Sure, that will be problematic. However, I personally do not use action
>> code because I do not like to mix languages. So, for such scenarios, it
>> should be relatively easy to implement the feature. For the first
>> release, you could perhaps show a warning or even a compiler-error if
>> the grammar also contains action code.
>>
>> > If you create a combined grammar that has lexer, parser, and AST rules,
>> you
>> > could select an option to refactor the grammar into three separate
>> grammar
>> > files.
>> Nice idea, but how could rewrite rules/operators be separated from a
>> parser grammar? As I understand and use the formers, they are integrated
>> and bound to specific rules. Spontaneously, I have no idea how you could
>> separate them cleverly. Somehow, you must define and maintain a mapping.
>>
>
> Remember the pipeline is
>
> Text -> Lexer -> Lexer Tokens
> Lexer Tokens -> Parser -> Tree Tokens i.e. AST
> AST -> Tree rewrite -> AST (You can have more than one of these steps)
> AST ->  String Template -> Text
>
> So each step communicates with the next step using an array of
> tokens.  The AST is also tokens, with special UP and DOWN tokens that are
> used to define the tree.
>
> You don't see it that way because ANTLR hides it behind the ANTLR rules,
> which is code that hides another layer as lexer methods, parser methods,
> tree methods and string template methods. If you bring all of this up under
> a source code debugger you will see it.
>
> However with ANTLR v4, the AST and rewrites will probably change as I
> understand it. Instead of rewrite rules we will now use tree visitor
> patterns. See:
> http://www.antlr.org/wiki/display/~admin/2011/08/28/Squirrel+away+the+trees,+call+on+the+visitors
>
>  Eric
>
>
>
>
>
>>
>> Regards,
>> Christian
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>


More information about the antlr-interest mailing list