[antlr-interest] New to ANTLR; Problems with the grammar

Rodrigo Baptista digobaptista at gmail.com
Thu Jun 1 08:28:57 PDT 2006


Im not sure but i think you just need to remove the rule :

SYS
 : "SYSTEM"
 ;

And in the lexer part just add:

tokens
{
SYS  = "SYSTEM";
}

right after this:

class L extends Lexer;

Hope it works,

Regards,

Rodrigo

On 6/1/06, Schütz Tomi (KSFC 413) <tomi.schuetz at credit-suisse.com> wrote:
>
> Hi there
>
> I would like to parse an XML file and to extract some entity information.
>
> sample.xml:
>
> <!ENTITY commonVerification SYSTEM "../includes/commonVerification.xml">
> ..
>
> My grammar looks like this...
>
> b.g:
>
> class P extends Parser;
>
> startRule
>   : (
>       PREFIX n:NAME SYS p:PATH SUFFIX
>       {
>         System.out.println("("+n.getText()+","+p.getText()+")");
>       }
>     )+
>   ;
>
> class L extends Lexer;
>
> PREFIX
>   : "<!ENTITY"
>   ;
>
> SUFFIX
>   : '>'
>   ;
>
> NAME
>   : (
>       'a'..'z' |
>       'A'..'Z' |
>       '_'
>     )+
>   ;
>
> SYS
>   : "SYSTEM"
>   ;
>
> PATH
>   : (
>       '"' |
>       'a'..'z' |
>       'A'..'Z' |
>       '.' |
>       '/'
>     )+
>   ;
>
> WS
>   : (
>       ' ' |
>       '\t' |
>       '\r' '\n' { newline(); } |
>       '\n' { newline(); }
>     )
>     {$setType(Token.SKIP);} //ignore this token
>   ;
>
> I get an error message which I don't understand and I can't find an answer
> or link which brings me further...
>
> <!ENTITY commonVerification SYSTEM "../includes/commonVerification.xml">
> line 1:29: expecting SYS, found 'SYSTEM'
>
> Could anyone point me to the problem? Any hint is very much appreciated.
>
> Thanks in advance,
> Tomi
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060601/1b8e8755/attachment.html


More information about the antlr-interest mailing list