Recovered from cvs revision 2007-09-01 15:43:00

This commit is contained in:
2007-09-02 00:43:00 +00:00
parent 6bd702fccf
commit c8b439dd91
20 changed files with 213 additions and 45 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.cpp,v 1.31 2007/07/20 09:23:37 bacon Exp $
* $Id: Awk.cpp,v 1.32 2007/08/26 14:33:38 bacon Exp $
*/
#include <ase/awk/StdAwk.hpp>
@ -530,6 +530,8 @@ static void print_usage (const ase_char_t* argv0)
ase_printf (ASE_T(" -w o:n Specify an old and new word pair\n"));
ase_printf (ASE_T(" o - an original word\n"));
ase_printf (ASE_T(" n - the new word to replace the original\n"));
ase_printf (ASE_T(" -ns Don't strip whitespaces\n"));
ase_printf (ASE_T(" The STRIPSPACES option is truned off\n"));
}
int awk_main (int argc, ase_char_t* argv[])
@ -561,6 +563,10 @@ int awk_main (int argc, ase_char_t* argv[])
else if (ase_strcmp(argv[i], ASE_T("-a")) == 0) mode = 5;
else if (ase_strcmp(argv[i], ASE_T("-m")) == 0) mode = 6;
else if (ase_strcmp(argv[i], ASE_T("-w")) == 0) mode = 7;
else if (ase_strcmp(argv[i], ASE_T("-ns")) == 0)
{
awk.setOption (awk.getOption () & ~TestAwk::OPT_STRIPSPACES);
}
else
{
print_usage (argv[0]);

52
ase/test/awk/asm.awk Normal file
View File

@ -0,0 +1,52 @@
#
# Taken from the book "The AWK Programming Language"
# aseawk++ -si asm.awk -ns -a asm.s
#
# ASEAWK should turn on STRIPSPACES & BASEONE to run this program.
#
BEGIN {
srcfile = ARGV[1];
ARGV[1] = "";
tempfile = "asm.temp";
n = split("const get put ld st add sub jpos jz j halt", x);
for (i = 1; i <= n; i++) op[x[i]] = i - 1;
# PASS 1
FS = "[ \t]+";
while (getline <srcfile > 0) {
sub (/#.*/, "");
symtab[$1] = nextmem;
if ($2 != "") {
print $2 "\t" $3 >tempfile;
nextmem++;
}
}
close (tempfile);
# PASS 2
nextmem = 0;
while (getline <tempfile > 0) {
if ($2 !~ /^[0-9]*$/) $2 = symtab[$2];
mem[nextmem++] = 1000 * op[$1] + $2;
}
# INTERPRETER
for (pc = 0; pc >= 0; ) {
addr = mem[pc] % 1000;
code = int(mem[pc++] / 1000);
if (code == op["get"]) { getline acc; }
else if (code == op["put"]) { print acc; }
else if (code == op["st"]) { mem[addr] = acc; }
else if (code == op["ld"]) { acc = mem[addr]; }
else if (code == op["add"]) { acc += mem[addr]; }
else if (code == op["sub"]) { acc -= mem[addr]; }
else if (code == op["jpos"]) { if (acc > 0) pc = addr; }
else if (code == op["jz"]) { if (acc == 0) pc = addr; }
else if (code == op["j"]) { pc = addr; }
else if (code == op["halt"]) { pc = -1; }
else { pc = -1; }
}
}

14
ase/test/awk/asm.s Normal file
View File

@ -0,0 +1,14 @@
ld zero # initialize sum to zero
st sum
loop get # read a number
jz done # no more input if number is zero
add sum # add in accumulated sum
st sum # store new value back in sum
j loop # go back and read another number
done ld sum # print sum
put
halt
zero const 0
sum const

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.c,v 1.12 2007/06/20 03:48:02 bacon Exp $
* $Id: awk.c,v 1.13 2007/08/26 14:33:38 bacon Exp $
*/
#include <ase/awk/awk.h>
@ -907,7 +907,7 @@ static int awk_main (int argc, ase_char_t* argv[])
ASE_AWK_SHIFT |
ASE_AWK_EXTIO |
ASE_AWK_BLOCKLESS |
ASE_AWK_STRBASEONE |
ASE_AWK_BASEONE |
ASE_AWK_STRIPSPACES |
ASE_AWK_NEXTOFILE /*|
ASE_AWK_ARGSTOMAIN*/;