[antlr-interest] simple annotation parser

Jim Idle jimi at temporal-wave.com
Thu Mar 10 06:42:46 PST 2011


Use the debugger, not the interpreter. However your parsing rules are
ambiguous - switch from literals to real lexer tokens and look at the
error messages that ANTLR works gives you if you try to debug this.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Ben Corne
> Sent: Thursday, March 10, 2011 5:55 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] simple annotation parser
>
> Hello
>
> I'm trying to parse the examplary lines:
> example1: "//@author Ben Corne"
> example2: "//@ this is an example docstring"
>
> However, when running this in the interpreter window on example 1 or 2,
> it always seems to cut off the last last part of the letters in the
> resulting
> tree:
> http://igor.rave.org/annotation.png
>
> here's my attempt so far:
> -------------------------------
> grammar Annotation;
>
> options {
>   language  = Java;
>   output    = AST;
> }
>
> @header{
>   package edu.vub.at.parser;
> }
> @lexer::header{
>   package edu.vub.at.parser;
> }
>
> annotation
>   : '//@'  rule
>   ;
>
> rule
>   : ('\t'|'\n'|' '|'\r')* author
>   | docstring
>   ;
>
> // Documentation rules
> author
>   : 'author'!
>     (( '\t' | ' ' )+)!
>     .*
>     EOF
>   ;
>
> docstring
>   : (( '\t' | ' ')+)!
>     .*
>     EOF
>   ;
> -------------------------------
>
> 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