in reply to Re^2: please help me to resolve the Line comments and appending issue
in thread please help me to resolve the Line comments and appending issue
It sure contains some mistakes because I had to guess some things about CLI, BNE and variables. Feel free to fix it. If you would state more clearly how to distinguish between code and variables, it will be easier to write the proper code.#!/usr/bin/perl use warnings; use strict; use Getopt::Std; my %options; getopt("ivcm",\%options); do { die "Usage: $0 -i <input file> -v <variable file> -c <code file> -m < +macro file>\n" unless defined $options{$_} } for qw/i v c m/; open my $input, "<", $options{i} || die "$options{i}: $!\n"; open my $code, ">", $options{c} || die "$options{c}: $!\n"; open my $var, ">", $options{v} || die "$options{v}: $!\n"; open my $macro, ">", $options{m} || die "$options{m}: $!\n"; while (defined(my $line = <$input>)) { chomp $line; next if $line=~/^\s*$/; next if $line=~/^\s*\*/; $line=~s/EQU\s+\*//; $line=~s/\s*$//; my @fields = split /\s+/,$line,4; shift @fields until $fields[0] ne ''; if ($fields[0] eq 'BEGIN') { print $code join ("\t",@fields),"\n"; } elsif ($fields[0] =~ /^(BEGIN|L|CLI|BNE|LTR)$/) { #code pop @fields; print $code (join "\t",@fields),($fields[0] eq 'CLI' ? "" : "\ +n"); } elsif ($fields[0] =~ /^@/) { # macro print $macro (join "\t",@fields),"\n"; pop @fields; print $code (join "\t",@fields),"\n"; } elsif ($fields[1] =~ /^D[CS]$/) { #variable? my ($len) = ($fields[2] =~ /L(\d+)/); #??? my ($type) = $fields[2] =~ /^(.)/; # ??? my ($value) = ($fields[2] =~ /'(\d+)'$/); #??? print $var (join "\t",$fields[0],$len,$type,$value,$fields[3]) +,"\n"; } else { warn "Don't know what to do with line\n$line\n"; } } close $_ || die $! for ($input,$code,$var,$macro);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: please help me to resolve the Line comments and appending issue
by suno (Acolyte) on Aug 10, 2012 at 12:51 UTC | |
by aitap (Curate) on Aug 10, 2012 at 14:04 UTC | |
by aaron_baugher (Curate) on Aug 10, 2012 at 15:46 UTC |