[antlr-interest] Problem writting my grammar

Philippe Laval Philippe.Laval at asg.com
Thu Jan 26 02:58:46 PST 2012


Hello,

I am beginner with Antl and have this problem to solve. I want to parse an output of a tool like:

========= text to parse =========

FRU Device Description : Builtin FRU Device (ID 0)
Board Mfg Date        : Mon Jan  1 00:00:00 1996

========= grammar =========

grammar Test2;

command :    fru (NEWLINE board)? NEWLINE? EOF
                               ;

fru          :              WS? 'FRU Device Description' WS ':' WS CHAINE WS? ;
board    :              WS? 'Board Mfg Date' WS ':' WS CHAINE WS?  ;

NEWLINE
    : '\r'? '\n'
    ;
WS
    : (' '|'\t'|'\n'|'\r')+
    ;

CHAINE                : (~('\r'|'\n'))+
;

==========

I tried this grammar in ANTLWorks 1.4.3 but get a "MismatchedTokenException (0!0) under the fru node (in the Parse Tree).
Can someone give me a hint ?

In the past, I have developed a library using regular expression to parse tool output and I hoped Antlr could solve this.
Now I doubt this is the best solution since I will have to write a rule for each line (even the one I don't need) and I will have the "Device not present (Timeout)" to handle.
Can Antlr handle this problem ?


FRU Device Description : Builtin FRU Device (ID 0)
Board Mfg Date        : Mon Jan  1 00:00:00 1996

FRU Device Description : Storage (ID 1)
Device not present (Timeout)

FRU Device Description : PS 1 (ID 2)
Board Mfg Date        : Thu May  5 22:26:00 2011



Thanks
Philippe




More information about the antlr-interest mailing list