Ok Jim, let me understand if I'm missing something with a short example.
Take this little section of the grammar

parameter_with_index
    : parameterName = 'PARAM_' parameterIndex '=' numericLiteral
    ;


It shall be changed to

parameter_with_index
    : parameterNameLiteral  parameterIndex separator numericLiteral
    ;
parameterNameLiteral
    :    PARAM_TOKEN
    ;
separator
    :    SEPARATOR_TOKEN
    ;
SEPARATOR_TOKEN
    :    '='
    ;
PARAM_TOKEN
    :    'PARAM_'
    ;

is it right?

Thank you all for your precious suggestions :)





________________________________
Da: Jim Idle <[email protected]>
A: [email protected]
Inviato: Lun 21 marzo 2011, 16:25:29
Oggetto: Re: [antlr-interest] Grammar issue

Take the 'literals' out of the parser and create real lexer tokens that
are declared before the other, more general tokens.

Using literals in the parser confuses you and will also make error
handling and tree walking more difficult.

Jim

> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of maulattu
> Sent: Monday, March 21, 2011 1:53 AM
> To: [email protected]
> Subject: Re: [antlr-interest] Grammar issue
>
> Hi all,
> for a matter of convenience I didn't write here all the rules for white
> spaces and so on, but I've them in order to skip white spaces, tab, \r,
> \n and so on.
> It seems the lexer recognize as "textLiteral" the parameter names
> (i.e.:
> "VARIABLE" and "MESSAGE_").
>
> Any suggestions?
>
> Thank you all :)
>
>
> /*----------------------------------------*/
> parametersList
>   : parametersDeclaration+ EOF
>   ;
>
> parametersDeclaration
>   : parameter_with_index /* like PARAM_1 above*/
>   | paramemter_without_index /* like VARIABILE above */
>   ;
>
> parameter_with_index
>   : parameterName = 'PARAM_' parameterIndex '=' numericLiteral
>   | parameterName = 'MESSAGE_' parameterIndex '=' textLiteral
>   ;
>
> paramemter_without_index
>   : parameterName = 'VARIABLE' '=' textLiteral
>   ;
> /*----------------------------------------*/
> parameterIndex
>   : DECIMAL_LITERAL
>   ;
>
> numericLiteral
>   :  HEX_LITERAL
>   |  DECIMAL_LITERAL
>   ;
>
> textLiteral
>   : TEXT_LITERAL
>   ;
>
> HEX_LITERAL
>   : '0' ('x' | 'X') HEX_DIGIT+
>   ;
>
> DECIMAL_LITERAL
>   : '0' | '1'..'9' '0'..'9'*
>   ;
> /*----------------------------------------*/
> fragment
> TEXT_LITERAL
>   : LETTER (LETTER | '0'..'9')*
>   ;
>
> fragment
> HEX_DIGIT
>   : ('0'..'9' | 'a'..'f' | 'A'..'F')
>   ;
>
> fragment
> LETTER
>   : 'A'..'Z'
>   | 'a'..'z'
>   | '_'
>   | '+'
>   ;
>
>
>
>
> ________________________________
> Da: Stephen Tuttlebee <[email protected]>
> A: [email protected]
> Inviato: Gio 17 marzo 2011, 13:00:59
> Oggetto: Re: [antlr-interest] Grammar issue
>
> Hi
>
> Is not the failure to parse:
>      MESSAGE_1 = this is a message
> due to the whitespace between the words in the string following the
> equals sign?
>
> Do you have a whitespace lexer rule (often called WS)? I suspect the
> parser is failing due to the fact that it parses up to 'MESSAGE_1 =
> this' just fine but then after that point it is expecting another
> 'parametersDeclaration' to follow, for which the remaining input 'is a
> message' would not have any rules that matches it (the parser would be
> expecting one of three things next, either 'PARAM_', 'MESSAGE_' or
> 'VARIABLE').
>
> I'm not an expert on ANTLR, but I think that might be your problem.
>
> Thanks
> Stephen
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address



      

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to