[antlr-interest] How to retrieve free-form text between delimiters?
    Andrew Lentvorski 
    bsder at allcaps.org
       
    Mon Jul 23 00:46:47 PDT 2007
    
    
  
I'm trying to create a parser for a VCD (Verilog change dump) file.  I'm 
trying to pull the free-form text from between delimiters.  My VCD file 
looks like this:
$date
         Fri Jan 26 11:28:51 2007
$end
$comment
         Could be anything! 12345 #12345
$end
$comment Could be anything 2! 12345 #12345 $end
How do I retreive the text from between the $date ... $end or $comment 
... $end pairs?
I tried this grammar:
grammar vcdfile;
vcd	:	declaration_command+ EOF
	;
declaration_command
	: date_dcmd | comment_dcmd
	;
date_dcmd:	'$date' ( options {greedy=false;} : . )* '$end' 
{System.out.println("D:"+$date_dcmd.text);} ;
comment_dcmd:	'$comment' ( options {greedy=false;} : . )* '$end' 
{System.out.println("C:"+$comment_dcmd.text);};
INT	:	'0'..'9'+;
WS	:	(' '|'\t'|'\n'|'\r')+ {skip();} ;
However, I wind up with a bunch of errors like this:
line 2:8 no viable alternative at character 'F'
line 2:9 no viable alternative at character 'r'
line 2:10 no viable alternative at character 'i'
<... lots more deleted ...>
And output like this:
D:$date261128512007$end
C:$comment1234512345$end
C:$comment21234512345$end
Any suggestions as to what I need to do?  I thought that a . was 
supposed to match *anything*, but clearly my definition of anything and 
ANTLR's definition of anything don't correspond.
Any advice for solving this?
Thanks,
-a
    
    
More information about the antlr-interest
mailing list