[antlr-interest] Lexer grammar in AntlrWorks 1.4.3

Stefan Mätje Stefan.Maetje at esd-electronics.com
Fri Mar 2 04:03:05 PST 2012


Hi Daniela,

I should not respond to emails on the list after a long workday %-)

I've overseen that you talked about running/debugging the lexer grammer with 
AntlrWorks. If I try to debug I get the same erroneous output as you get. 
Sorry.

To get the grammar through AntlrWorks you may change the grammar as follows:
------------------------------------------------------------------
/*lexer */grammar testRE;

tokens: .+;

ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;
WS      :       (' ' | '\t' | '\n' | '\r' )+
        ;
-------------------------------------------------------------------

Then you can debug it and feed it some input. But you will only be able to see 
the token stream. AntlrWorks doesn't let you see how the lexer walks through 
the input text.

Regards,
	Stefan

Am 01.03.2012 20:13:43 schrieb(en) Daniela da Cruz:
> Hi Stefan,
> 
> I have named the file that contains the lexer grammar as testRE.g. Exactly
> as I do with combined grammars.
> Are you able to run the file attached with success in AntlrWorks?
> 
> thanks
> daniela
> 
> On Thu, Mar 1, 2012 at 18:47, Stefan Mätje <
> Stefan.Maetje at esd-electronics.com> wrote:
> 
> > Hi,
> >
> > it seems to me that you have either the lexer grammar not named properly 
> or
> > perhaps not saved with the same name as it is given in your lexer grammar
> > ("testRE") below.
> >
> > AntlrWorks runs the compiler himself but has given the compiler the name
> > "null.java". The name string internal of AntlrWorks seemed to be a null
> > reference -> null+".java". I would have expected "testRE.java".
> >
> > Same accounts for the error message of the compiler for __Test__.java. Id
> > was
> > missing because of empty lexer name ...
> >
> >
> > Am 01.03.2012 16:08:59 schrieb(en) Daniela da Cruz:
> > > Hi.
> > >
> > > I have been creating a very simple lexer in AntlrWorks but when trying 
> to
> > > run it I got the following errors:
> > >
> > > [15:01:29] javac: file not found:
> > > C:\Users\Utilizador\Desktop\output\null.java
> >
> > Bad file name from null reference?   ^^^^
> >
> > > [15:01:29] Usage: javac <options> <source files>
> > > [15:01:29] use -help for a list of possible options
> > > [15:01:31] C:\Users\Utilizador\Desktop\output\__Test__.java:12:
> > > <identifier> expected
> > > [15:01:31]  g = new (tokens, 49100, null);
> > > [15:01:31]         ^
> >
> > Missing lexer class  ^^^^ name.
> >
> > > [15:01:31] 1 error
> > >
> > > It seems that is looking for the parser file that usually exists on a
> > > combined grammar.
> > > Was anyone able to run a lexer grammar in AntlrWorks?
> > >
> > > My lexer was something like:
> > >
> > > ---------------------------------------------------
> > > lexer grammar testRE;
> > >
> > > ID: '0'..'9'+ ;
> > > ---------------------------------------------------
> >
> > This worked for me in AntlrWorks 1.4.3
> >
> > Regards,
> >        Stefan
> >
> >
> >
> 




More information about the antlr-interest mailing list