00001 # define DEBUG
00002 # undef DEBUG
00003 # include "parm.h"
00004
00005 # include <stdio.h>
00006
00007 # include "stree/ststructs.mh"
00008
00009 extern FILE * unparse_file;
00010
00011 # ifdef BAD
00012 extern boolean BADflag;
00013 # endif
00014
00015 NODE * cor_cond();
00016
00017 NODE * cand_cond();
00018
00019 NODE ** outermost_op();
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 NODE * mkappl2(h,t)
00035 NODE ** h,
00036 ** t;
00037 {
00038 NODE ** op,
00039
00040 * result,
00041 * left_arg,
00042 * right_arg,
00043 ** rest = t+1;
00044
00045
00046 # ifdef DEBUG
00047
00048 if ( h == t + 1 ) {
00049 dbgmsg("\nmkappl2: empty array - %o, %o\n", h, t);
00050 abort();
00051 }
00052 # endif
00053
00054
00055
00056
00057 if ( h == t ) {
00058
00059 if ( is_list(*h) ) {
00060
00061 return ( copylist(*h) );
00062 } else {
00063 return ( mklist(*h, -1) );
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074 op = outermost_op( h,t );
00075
00076 if( op == NIL ) {
00077
00078 if (!is_list(*h)) {
00079
00080 rest = h+2;
00081 right_arg = mkappl2( h+1, h+1);
00082 lock(right_arg);
00083 left_arg = emptylist();
00084 lock(left_arg);
00085 op = h;
00086 } else {
00087
00088 yyperror("Improperly bracketed expression");
00089 return( mklist(emptylist(), -1) );
00090 }
00091 } else {
00092
00093
00094 if ( op == h )
00095 left_arg = emptylist();
00096 else
00097 left_arg = mkappl2( h, op-1 );
00098 lock(left_arg);
00099
00100
00101 if ( op == t )
00102 right_arg = emptylist();
00103 else
00104 right_arg = mkappl2( op+1, t );
00105 lock(right_arg);
00106 }
00107
00108
00109
00110 switch ( (*op) -> kind ) {
00111 case WORDCAND:
00112
00113 single_arg(left_arg); single_arg(right_arg);
00114 result = cand_cond(left_arg, right_arg);
00115 vfree(unlock(left_arg)); vfree(unlock(right_arg));
00116 break;
00117 case WORDCOR:
00118
00119 single_arg(left_arg); single_arg(right_arg);
00120 result = cor_cond(left_arg, right_arg);
00121 vfree(unlock(left_arg)); vfree(unlock(right_arg));
00122 break;
00123 default:
00124 unlock(left_arg); unlock(right_arg);
00125 result = mknode(APPLICATION, *op, conc(left_arg,right_arg));
00126
00127 while (rest <= t) {
00128 result = mknode(APPLICATION, result,
00129 mkappl2( rest, rest ));
00130 rest++;
00131 }
00132 }
00133
00134
00135 # ifdef BAD
00136 if (BADflag)
00137 flcheck(0,0);
00138 else
00139 flcheck(0,1);
00140 # endif
00141
00142 return ( mklist(result, -1) );
00143 }