[antlr-interest] not parsing to end of input

Mark Volkmann r.mark.volkmann at gmail.com
Mon Dec 10 13:08:16 PST 2007


Okay, here's a new, short grammar that illustrates the problem. Try
feeding the following two lines into it using the ANTLRWorks debugger.
You'll see that it stops before the semicolon on the first line and
doesn't parse the rest.

print f(x);
print a;

---

grammar problem;

options {
  output = AST;
}

tokens {
  PRINT;
  SCRIPT;
}

print
  : 'print' NAME '(' v=(NUMBER | NAME) ')' -> ^(PRINT NAME $v)
  | 'print' NAME -> ^(PRINT NAME)
  ;

script: (print TERMINATOR)* EOF -> ^(SCRIPT print*);
  	
NAME: 'a'..'z';
NEWLINE: '\r'? '\n' { $channel = HIDDEN; };
NUMBER: '0'..'9';		
TERMINATOR: ';';
WHITESPACE: (' '|'\t')+ { $channel = HIDDEN; };

On Dec 10, 2007 2:35 PM, Mark Volkmann <r.mark.volkmann at gmail.com> wrote:
> On Dec 10, 2007 11:27 AM, Tom Smith <yotommy at gmail.com> wrote:
> > When I ran this through the ANTLRworks debugger, it parsed all the
> > input properly.
> >
> > When you invoked "Debug" are you selecting the 'script' rule as the start rule?
>
> No, I didn't. That was my problem for this small grammar. However,
> there is still a problem with my larger grammar. I'll try again to
> reduce it to something smaller that exhibits the problem and send it
> out again. Thanks for looking at this!
>
>
> > On Dec 10, 2007 12:08 PM, Mark Volkmann <r.mark.volkmann at gmail.com> wrote:
> > > I've stripped down my grammar to the smallest size that reproduces the
> > > problem. When I run "print x;" through this grammar using the
> > > ANTLRWorks debugger, it doesn't process the semicolon. It stops
> > > parsing at that point and throws the rest of the input away. In my
> > > real grammar this ends up being multiple lines of lost input. Any idea
> > > what I'm doing wrong?
> > >
> > > grammar problem;
> > >
> > > options {
> > >   output = AST;
> > > }
> > >
> > > script: print ';';
> > > print: 'print' LETTER -> ^('print');
> > >
> > > LETTER: 'a'..'z';
> > > WHITESPACE: ' '+ { $channel = HIDDEN; };
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>



-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list