Problems parsing with Parse::RecDescent

Colin Kuskie ckuskie at dalsemi.com
Tue Jul 9 17:29:21 CDT 2002


I'm having problems trying to grok Parse::RecDescent.  As part of a
much larger grammar, I'm trying to parse lines that look like these:

Xname node1 node2 node3 model
Xname node1 node2 node3 model parName=parValue parName=parValue

with this set of rules:

#!/usr/bin/perl -w

use strict;
use lib '~/perl/modules';
use Parse::RecDescent;
use Data::Dumper;

my ($dump,$tree) = (0,0);

$Data::Dumper::Purity = 1;

$RD_HINT = 1;

my $grammar = <<'EOGRAMMAR';

#rules

netlist : element(s)

element : comment_line
        | subckt

comment_line : '*' comment

{ bless { comment => $item{comment} }, $item[0] }

subckt : <skip: qr/[ \t]*/> /x/i name node(s) /.*/ "\n"

{
  bless { name   => $item{name},
	  nodes  => $item{node} }, $item[0]
}

node : /\w+/
{ $item[1] }

name : /\w+/
{ $item[1] }

comment : /.*/
{ $item[1] }

EOGRAMMAR

#----------------------------------------------------------------

my $parse = Parse::RecDescent->new($grammar)
  or die "bad grammar";

undef $/;
my $text = <<EOT;
* # FILE NAME: /DESIGN/NWDC/NEWDESIGN/DSB17/SIM/HSPICE/CKUSKIE/
* translinear1/hspiceS/schematic/netlist/translinear1.c.raw
* Netlist output for hspiceS.
* Generated on Jul 5 14:17:15 2002
* File name: DSB17_translinear1_schematic.S.
* Subcircuit for cell: translinear1.
* Generated for: hspiceS.
* Generated on Jul  5 14:17:15 2002.
XP2 VDD VOUT PBBAS IOUT PCH4_D6W_1  
XP2a VDD VOUT PBBAS IOUT PCH4_D6W_1  M=1.0
XP1 VDD IOUT N2 VDD PCH4_D6W_1  M=1.0
XP0 VDD N2 N2 VDD PCH4_D6W_1  M=1.0
XQ4 IINP N2 IT2 AGND NPN8P0_D6W_G1  M=5.0
XQ3 IREF IOUT IT2 AGND NPN8P0_D6W_G1  M=5.0
XQ2 IT1 IT1 IREF AGND NPN8P0_D6W_G1  M=5.0
XQ1 IT1 IT1 IINP AGND NPN8P0_D6W_G1  M=5.0
EOT

my $net = $parse->netlist($text)
  or die "bad netlist";

print Dumper($net);

--------------------------------------------------------------

The output is generates says it parses all the "comment" lines, but
fails to parse any of the "subckt" lines:

$VAR1 = [
          bless( {
                   'comment' => '# FILE NAME: /DESIGN/NWDC/NEWDESIGN/DSB17/SIM/HSPICE/CKUSKIE/'
                 }, 'comment_line' ),
          bless( {
                   'comment' => 'translinear1/hspiceS/schematic/netlist/translinear1.c.raw'
                 }, 'comment_line' ),
          bless( {
                   'comment' => 'Netlist output for hspiceS.'
                 }, 'comment_line' ),
          bless( {
                   'comment' => 'Generated on Jul 5 14:17:15 2002'
                 }, 'comment_line' ),
          bless( {
                   'comment' => 'File name: DSB17_translinear1_schematic.S.'
                 }, 'comment_line' ),
          bless( {
                   'comment' => 'Subcircuit for cell: translinear1.'
                 }, 'comment_line' ),
          bless( {
                   'comment' => 'Generated for: hspiceS.'
                 }, 'comment_line' ),
          bless( {
                   'comment' => 'Generated on Jul  5 14:17:15 2002.'
                 }, 'comment_line' )
        ];


Does anybody have any ideas about a better grammar to use?

Colin
TIMTOWTDI



More information about the Pdx-pm-list mailing list