This commit is contained in:
parent
99685d17a1
commit
91e196af25
@ -5329,7 +5329,7 @@ static int deparse (ase_awk_t* awk)
|
||||
const ase_char_t* kw = ase_awk_getkw(awk,ASE_T("BEGIN"));
|
||||
if (ase_awk_putsrcstr(awk,kw) == -1) EXIT_DEPARSE ();
|
||||
if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1) EXIT_DEPARSE ();
|
||||
if (ase_awk_prnpt (awk, nde) == -1) EXIT_DEPARSE ();
|
||||
if (ase_awk_prnnde (awk, nde) == -1) EXIT_DEPARSE ();
|
||||
|
||||
if (awk->option & ASE_AWK_CRLF)
|
||||
{
|
||||
@ -5388,7 +5388,7 @@ static int deparse (ase_awk_t* awk)
|
||||
const ase_char_t* kw = ase_awk_getkw(awk,ASE_T("END"));
|
||||
if (ase_awk_putsrcstr(awk,kw) == -1) EXIT_DEPARSE ();
|
||||
if (ase_awk_putsrcstr (awk, ASE_T(" ")) == -1) EXIT_DEPARSE ();
|
||||
if (ase_awk_prnpt (awk, nde) == -1) EXIT_DEPARSE ();
|
||||
if (ase_awk_prnnde (awk, nde) == -1) EXIT_DEPARSE ();
|
||||
|
||||
/*
|
||||
if (awk->option & ASE_AWK_CRLF)
|
||||
|
@ -565,14 +565,10 @@ static int print_expression_list (ase_awk_t* awk, ase_awk_nde_t* tree)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
|
||||
static int print_statement (ase_awk_t* awk, ase_awk_nde_t* p, int depth)
|
||||
{
|
||||
ase_awk_nde_t* p = tree;
|
||||
ase_size_t i;
|
||||
|
||||
while (p != ASE_NULL)
|
||||
{
|
||||
|
||||
switch (p->type)
|
||||
{
|
||||
case ASE_AWK_NDE_NULL:
|
||||
@ -905,6 +901,16 @@ static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int print_statements (ase_awk_t* awk, ase_awk_nde_t* tree, int depth)
|
||||
{
|
||||
ase_awk_nde_t* p = tree;
|
||||
|
||||
while (p != ASE_NULL)
|
||||
{
|
||||
if (print_statement (awk, p, depth) == -1) return -1;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
@ -916,6 +922,11 @@ int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree)
|
||||
return print_statements (awk, tree, 0);
|
||||
}
|
||||
|
||||
int ase_awk_prnnde (ase_awk_t* awk, ase_awk_nde_t* tree)
|
||||
{
|
||||
return print_statement (awk, tree, 0);
|
||||
}
|
||||
|
||||
int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree)
|
||||
{
|
||||
ase_awk_nde_t* nde = tree;
|
||||
|
@ -408,7 +408,11 @@ struct ase_awk_nde_print_t
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* print the entire tree */
|
||||
int ase_awk_prnpt (ase_awk_t* awk, ase_awk_nde_t* tree);
|
||||
/* print a single top-level node */
|
||||
int ase_awk_prnnde (ase_awk_t* awk, ase_awk_nde_t* node);
|
||||
/* print the pattern part */
|
||||
int ase_awk_prnptnpt (ase_awk_t* awk, ase_awk_nde_t* tree);
|
||||
|
||||
void ase_awk_clrpt (ase_awk_t* awk, ase_awk_nde_t* tree);
|
||||
|
7
ase/test/awk/main-001.out
Normal file
7
ase/test/awk/main-001.out
Normal file
@ -0,0 +1,7 @@
|
||||
function main ()
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
return 999;
|
||||
}
|
||||
|
42
ase/test/awk/main-002.out
Normal file
42
ase/test/awk/main-002.out
Normal file
@ -0,0 +1,42 @@
|
||||
function error ()
|
||||
{
|
||||
exit 200;
|
||||
}
|
||||
|
||||
function getx ()
|
||||
{
|
||||
if ((x == 2))
|
||||
error ();
|
||||
return (x)++;
|
||||
}
|
||||
|
||||
function gety ()
|
||||
{
|
||||
return (y)++;
|
||||
}
|
||||
|
||||
function main ()
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
return 999;
|
||||
}
|
||||
|
||||
END {
|
||||
print "END OF PROGRAM";
|
||||
return 10;
|
||||
}
|
||||
END {
|
||||
print "END OF PROGRAM 2";
|
||||
exit 100;
|
||||
}
|
||||
END {
|
||||
print "END OF PROGRAM 3";
|
||||
exit 900;
|
||||
}
|
||||
0
|
||||
2
|
@ -11,8 +11,34 @@ run_script_for_init()
|
||||
"$ASEAWK" $OPTION -d -f "$script" "$data" > "$output"
|
||||
}
|
||||
|
||||
run_script_for_init_nodata()
|
||||
{
|
||||
script="$1"
|
||||
output=`echo $script | sed 's/\.awk$/.out/g'`
|
||||
|
||||
"$ASEAWK" $OPTION -d -f "$script" > "$output"
|
||||
}
|
||||
|
||||
run_script_for_init_main()
|
||||
{
|
||||
script="$1"
|
||||
output=`echo $script | sed 's/\.awk$/.out/g'`
|
||||
|
||||
"$ASEAWK" $OPTION -m main -d -f "$script" > "$output"
|
||||
}
|
||||
|
||||
run_init()
|
||||
{
|
||||
for script in simple-???.awk
|
||||
do
|
||||
run_script_for_init_nodata "$script"
|
||||
done
|
||||
|
||||
for script in main-???.awk
|
||||
do
|
||||
run_script_for_init_main "$script"
|
||||
done
|
||||
|
||||
for script in emp-???.awk
|
||||
do
|
||||
run_script_for_init "$script" "emp-en.data"
|
||||
@ -55,10 +81,86 @@ run_script_for_test()
|
||||
return 0
|
||||
}
|
||||
|
||||
run_script_for_test_nodata()
|
||||
{
|
||||
script="$1"
|
||||
output=`echo $script | sed 's/\.awk$/.out/g'`
|
||||
|
||||
echo ">> RUNNING $script"
|
||||
"$ASEAWK" $OPTION -d -f "$script" > "$output.$pid"
|
||||
|
||||
#diff -y "$output" "$output.$pid"
|
||||
diff "$output" "$output.$pid"
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
rm -f "$output.$pid"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -f "$output.$pid"
|
||||
return 0
|
||||
}
|
||||
|
||||
run_script_for_test_main()
|
||||
{
|
||||
script="$1"
|
||||
output=`echo $script | sed 's/\.awk$/.out/g'`
|
||||
|
||||
echo ">> RUNNING $script"
|
||||
"$ASEAWK" $OPTION -m main -d -f "$script" > "$output.$pid"
|
||||
|
||||
#diff -y "$output" "$output.$pid"
|
||||
diff "$output" "$output.$pid"
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
rm -f "$output.$pid"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -f "$output.$pid"
|
||||
return 0
|
||||
}
|
||||
|
||||
run_test()
|
||||
{
|
||||
pid=$$
|
||||
|
||||
for script in simple-???.awk
|
||||
do
|
||||
run_script_for_test_nodata "$script"
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "###################################"
|
||||
echo "PROBLEM(S) DETECTED IN $script.".
|
||||
echo "###################################"
|
||||
|
||||
echo "Do you want to abort? [y/n]"
|
||||
read ans
|
||||
if [ "$ans" = "y" -o "$ans" = "Y" ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
for script in main-???.awk
|
||||
do
|
||||
run_script_for_test_main "$script"
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "###################################"
|
||||
echo "PROBLEM(S) DETECTED IN $script.".
|
||||
echo "###################################"
|
||||
|
||||
echo "Do you want to abort? [y/n]"
|
||||
read ans
|
||||
if [ "$ans" = "y" -o "$ans" = "Y" ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
for script in emp-???.awk
|
||||
do
|
||||
run_script_for_test "$script" "emp-en.data"
|
||||
|
28
ase/test/awk/simple-001.out
Normal file
28
ase/test/awk/simple-001.out
Normal file
@ -0,0 +1,28 @@
|
||||
function error ()
|
||||
{
|
||||
exit 200;
|
||||
}
|
||||
|
||||
function getx ()
|
||||
{
|
||||
if ((x == 2))
|
||||
error ();
|
||||
return (x)++;
|
||||
}
|
||||
|
||||
function gety ()
|
||||
{
|
||||
return (y)++;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
x = 0;
|
||||
y = 0;
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
}
|
||||
|
||||
0
|
||||
2
|
32
ase/test/awk/simple-002.out
Normal file
32
ase/test/awk/simple-002.out
Normal file
@ -0,0 +1,32 @@
|
||||
function error ()
|
||||
{
|
||||
exit 200;
|
||||
}
|
||||
|
||||
function getx ()
|
||||
{
|
||||
if ((x == 2))
|
||||
error ();
|
||||
return (x)++;
|
||||
}
|
||||
|
||||
function gety ()
|
||||
{
|
||||
return (y)++;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
x = 0;
|
||||
y = 0;
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
}
|
||||
|
||||
END {
|
||||
print "END OF PROGRAM";
|
||||
}
|
||||
0
|
||||
2
|
||||
END OF PROGRAM
|
33
ase/test/awk/simple-003.out
Normal file
33
ase/test/awk/simple-003.out
Normal file
@ -0,0 +1,33 @@
|
||||
function error ()
|
||||
{
|
||||
exit 200;
|
||||
}
|
||||
|
||||
function getx ()
|
||||
{
|
||||
if ((x == 2))
|
||||
error ();
|
||||
return (x)++;
|
||||
}
|
||||
|
||||
function gety ()
|
||||
{
|
||||
return (y)++;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
x = 0;
|
||||
y = 0;
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
}
|
||||
|
||||
END {
|
||||
print "END OF PROGRAM";
|
||||
exit 20;
|
||||
}
|
||||
0
|
||||
2
|
||||
END OF PROGRAM
|
36
ase/test/awk/simple-004.out
Normal file
36
ase/test/awk/simple-004.out
Normal file
@ -0,0 +1,36 @@
|
||||
function error ()
|
||||
{
|
||||
exit 200;
|
||||
}
|
||||
|
||||
function getx ()
|
||||
{
|
||||
if ((x == 2))
|
||||
error ();
|
||||
return (x)++;
|
||||
}
|
||||
|
||||
function gety ()
|
||||
{
|
||||
return (y)++;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
x = 0;
|
||||
y = 0;
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
}
|
||||
|
||||
END {
|
||||
print "END OF PROGRAM";
|
||||
exit 20;
|
||||
}
|
||||
END {
|
||||
print "END OF PROGRAM 2";
|
||||
}
|
||||
0
|
||||
2
|
||||
END OF PROGRAM
|
38
ase/test/awk/simple-005.out
Normal file
38
ase/test/awk/simple-005.out
Normal file
@ -0,0 +1,38 @@
|
||||
function error ()
|
||||
{
|
||||
exit 200;
|
||||
}
|
||||
|
||||
function getx ()
|
||||
{
|
||||
if ((x == 2))
|
||||
error ();
|
||||
return (x)++;
|
||||
}
|
||||
|
||||
function gety ()
|
||||
{
|
||||
return (y)++;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
x = 0;
|
||||
y = 0;
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
}
|
||||
|
||||
END {
|
||||
print "END OF PROGRAM";
|
||||
return 10;
|
||||
}
|
||||
END {
|
||||
print "END OF PROGRAM 2";
|
||||
return 20;
|
||||
}
|
||||
0
|
||||
2
|
||||
END OF PROGRAM
|
||||
END OF PROGRAM 2
|
42
ase/test/awk/simple-006.out
Normal file
42
ase/test/awk/simple-006.out
Normal file
@ -0,0 +1,42 @@
|
||||
function error ()
|
||||
{
|
||||
exit 200;
|
||||
}
|
||||
|
||||
function getx ()
|
||||
{
|
||||
if ((x == 2))
|
||||
error ();
|
||||
return (x)++;
|
||||
}
|
||||
|
||||
function gety ()
|
||||
{
|
||||
return (y)++;
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
x = 0;
|
||||
y = 0;
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
print (getx () + gety ());
|
||||
}
|
||||
|
||||
END {
|
||||
print "END OF PROGRAM";
|
||||
return 10;
|
||||
}
|
||||
END {
|
||||
print "END OF PROGRAM 2";
|
||||
exit 100;
|
||||
}
|
||||
END {
|
||||
print "END OF PROGRAM 3";
|
||||
exit 900;
|
||||
}
|
||||
0
|
||||
2
|
||||
END OF PROGRAM
|
||||
END OF PROGRAM 2
|
Loading…
Reference in New Issue
Block a user