To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.pbforthOpen lugnet.robotics.rcx.pbforth in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / pbFORTH / 222
221  |  223
Subject: 
Whitespace and comment remover in perl
Newsgroups: 
lugnet.robotics.rcx.pbforth
Date: 
Wed, 15 Dec 1999 11:51:21 GMT
Viewed: 
1308 times
  
Hello,

i've written a little perl script, which removes white spaces and
comments from a forth source code.

If called without any parameters, it reads from STDIN and writes to
STDOUT.
If called with 1 parameter, this parameter is interpreted as an file to
read from . The result is written to STDOUT.
If called with 2 parameters, parameter one is interpreted as above but
the result is written to parameter two.

Bugs:
no error checking

Remember: there is always enough rope to hang yourself :)

File: cmprsfrth.pl
------------------------- snip here ------------------------------------
#!/usr/bin/perl
# COMPRESS FORTH
# simple whitespace and comment remover.
#
# Carsten Müller 1999

if($ARGV[0]){
  open(STDIN,$ARGV[0]);
}

if($ARGV[1]){
  open(STDOUT,">".$ARGV[1]);
}
while(<STDIN>){
  s/\\.*$//g; # remove \ commends
  s/\(.*?\)//g; # remove ( ... )
  s/^\s*//g; # remove leading whitespaces ( \t\r\n\f)
  s/\s+$//g; # remove trailing whitespaces ( \t\r\n\f)
  next if(length($_)==0);
  print $_."\n";

}
------------------------- snip here ------------------------------------



Message has 1 Reply:
  RE: Whitespace and comment remover in perl
 
(...) <snipped script> Carsten, This is a good start. Here's my comments on each of the regexp lines... By the way, my Tcl script handles most of this stuff properly, but I'm waiting until the new year to develop XMODEM uploads for it.... (...) (25 years ago, 15-Dec-99, to lugnet.robotics.rcx.pbforth)

5 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR