Re: Need simple parser/interpreter - reinvent the wheel?

peter@abbnm.com (Peter da Silva)
3 Jun 2000 17:35:15 -0400

          From comp.compilers

Related articles
Need simple parser/interpreter - reinvent the wheel? pld@fc.hp.com (2000-05-31)
Re: Need simple parser/interpreter - reinvent the wheel? William.H.Duquette@jpl.nasa.gov (2000-06-01)
Re: Need simple parser/interpreter - reinvent the wheel? andrew@andrewcooke.free-online.co.uk (Andrew Cooke) (2000-06-03)
Re: Need simple parser/interpreter - reinvent the wheel? peter@abbnm.com (2000-06-03)
| List of all articles for this month |
From: peter@abbnm.com (Peter da Silva)
Newsgroups: comp.compilers,comp.lang.misc
Date: 3 Jun 2000 17:35:15 -0400
Organization: ABB Network Management
References: 00-05-125
Keywords: parse, comment

Someone else suggested bootstrapping Perl or Tcl, and I would agree with that,
but if you're sing a UNIX system you can get a lot of benefit from the existing
tools:


Paul Dineen <pld@fc.hp.com> wrote:
> SCSI_disk {
> open values[1] = "-- Information Tool Log for SCSI Disk on path (.*) --";
> values[2] = "^Product ID:\\s*(\\S*)\\s*";
> values[3] = "^Firmware Rev:\\s*(\\S*)\\s";
> close values[4] = "^Serial Number:\\s*(\\S*)\\s";
> return 1-4;
> }


awk 'BEGIN {state="none"}
state=="none" && /Information Tool Log for SCSI Disk on path/ {
    state="scsi"
    path=$10
}


state=="scsi" && /^Product ID/ {
    product_id=$3
}


state=="scsi" && /^Firmware Rev/ {
    firmware_rev=$3
}


state=="scsi" && /^Serial Number/ {
    serial_number=$3
    state="none"
    print "SCSI_disk",$path,$product_id,$firmware_rev,$serial_number
}'


(this sort of thing shows you a lot about Perl's ancestry. It's a pity
that the equivalent Perl would be a lot less clean... in many ways Awk
is an improvement on its descendant)


--
In hoc signo hack, Peter da Silva <peter@baileynm.com>
[It's true, for this kind of application perl has too much Basic-Plus and
not enough RPG. -John]





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.