%{ /* oakland university compiler design course nasser abbasi 3/4/88 yacc program for parsing pascal program will generate parse tree at the end of the run and print it */ #include #include # include #define symtable_size 500 #define inttable_size 500 #define realtable_size 500 #define stringtable_size 250 #define tree_size 2000 #define SUBTREE 1 #define LITERAL 2 #define IDENT 3 #define TOKEN 4 #define INTEGER_IDENT 5 #define REAL_IDENT 6 #define STRING_IDENT 7 #define EMPTY 8 int comment=0; int ident_index=0; int int_index=0; int real_index=0; int string_index=0; int string_last = 0; int symtable_last = 0; int inttable_last = 0; int realtable_last = 0; int tree_last = -1; int debug=1; char *symtable[symtable_size]; char *inttable[inttable_size]; char *realtable[realtable_size]; char *stringtable[stringtable_size]; struct tree_defn { int rhsn; int rhstype[10]; int rhsindx[10]; }; struct tree_defn tree[tree_size]; %} %token TKASG TKNE TKLE TKGE TKDTDT %token TKABSOLUTE TKAND TKARRAY TKBEGIN TKCASE TKCONST TKDIV TKDO TKDOWNTO %token TKELSE TKEND %token TKEXTERNAL TKFILE TKFORWARD TKFOR TKFUNCTION TKGOTO TKINLINE TKIF TKIN %token TKLABEL TKMOD %token TKNIL TKNOT TKOVERLAY TKOF TKOR TKPACKED TKPROCEDURE TKPROGRAM TKRECORD %token TKREPEAT TKSET %token TKSHL TKSHR TKSTRING TKTHEN TKTYPE TKTO TKUNTIL TKVAR TKWHILE TKWITH %token TKXOR TKTEXT TKCHAR TKREADLN TKWRITELN %token TKREAL TKBOOLEAN TKINTEGER TKREAD TKWRITE TKTRUE TKFALSE %token string real %token ident integer %% goal : program { if (debug) printf("goal-> program\n"); treedump(); } ; program : TKPROGRAM pgm_name ';' pblk pblock '.' { if (debug) printf("pgm-> TKPROGRAM pgm_name ; pblk pblock .\n"); $$ = build6g(TKPROGRAM,$2,';',$4,$5,'.');} ; pblk : { if(debug) printf("pblk-> **empty **\n");} ; pgm_name : ident { if (debug) printf("pgm_name-> ident\n"); $$ = buildident(ident_index);} ; pblock :label_dcl const_dcl type_dcl var_dcl plist pbegin statment_list TKEND { if(debug) printf("pblock->label_dcl const_dcl type_dcl"); if(debug) printf("var_dcl plist pbegin statment_list TKEND\n"); $$= build8g1($1,$2,$3,$4,$5,$6,$7,TKEND);} ; pbegin : TKBEGIN { if(debug) printf("pbegin-> BEGIN\n"); $$ = buildtoken(TKBEGIN);} ; plist : plist pfdcl {if(debug) printf("plist-> plist pfdcl\n"); $$= build2($1,$2); } | { if (debug) printf("plist-> ** empty ** \n"); $$ = buildempty();} ; pfdcl : procdecl { if(debug) printf("pfdcl-> procdcl\n");} | funcdecl {if(debug) printf("pfdcl-> funcdcl\n");} ; label_dcl : TKLABEL stmt_label ';' { if(debug) printf("label_dcl-> LABEL stmt_label ;\n"); $$ = build3kk(TKLABEL,$2,';');} | { $$ = buildempty();} ; stmt_label : stmt_label ',' int_or_ident { if(debug) printf("stmt_label-> stmt_label , int_or_ident\n"); $$ = build3($1,',',$3);} | int_or_ident { if (debug) printf("stmt_label-> int_or_ident\n");} ; int_or_ident : ident {if(debug)printf("int_or_ident-> ident\n"); $$ = buildident(ident_index);} | integer {if(debug) printf("int_or_ident->integer\n"); $$ = buildint(int_index);} ; const_dcl : TKCONST const_def ';' {if(debug) printf("const_dcl-> CONST const_def ; \n"); $$ = build3kk(TKCONST,$2,';');} | { $$ = buildempty();} ; const_def : const_def ';' equate_stmt { if(debug) printf("const_def-> const_def ; equate_stmt\n"); $$ = build3($1,';',$3);} | equate_stmt {if(debug) printf("const_def-> equate_stmt\n");} | { $$ = buildempty();} ; equate_stmt : ident '=' integer {if(debug) printf("equate_stmt-> ident = integer \n"); $$ = build3(ident_index,'=',int_index);} ; type_dcl : TKTYPE type_def ';' { if(debug) printf("type_dcl-> TYPE type_def ;\n"); $$ = build3kk(TKTYPE,$2,';');} | { $$ = buildempty();} ; type_def : type_def ';' type_item {if(debug) printf("type_def-> type_def ; type_item\n"); $$ = build3($1,';',$3);} | type_item { if(debug) printf("type_def -> type_item\n");} ; type_item : ident '=' type { if(debug) printf("type_item-> ident = type\n"); $$ = build3a2(ident_index,'=',$3);} ; type : datatype { if(debug) printf("type-> datatype\n");} | filetype { if (debug) printf("type-> filetype\n");} ; datatype : simptype {if(debug) printf("datatype-> simptype\n");} | enumtype {if(debug) printf("datatype-> enumtype\n");} | subrangetype {if(debug) printf("datatype-> subrangetype\n");} | pointertype {if(debug) printf("datatype-> pointertype\n");} | arraytype {if(debug) printf("datatype-> arraytype\n");} | recordtype {if(debug) printf("datatype-> recordtype\n");} | settype {if(debug) printf("datatype-> settype\n");} ; simptype : ident {if(debug) printf("simptype-> ident\n"); $$ = buildident(ident_index);} | TKREAL { if(debug) printf("simptype-> REAL\n"); $$ = buildtoken(TKREAL);} | TKBOOLEAN { if(debug) printf("simptype-> BOOLEAN\n"); $$ = buildtoken(TKBOOLEAN);} | TKINTEGER { if(debug) printf("simptype-> INTEGER\n"); $$ = buildtoken(TKINTEGER);} | TKCHAR { if(debug) printf("simptype-> CHAR\n"); $$ = buildtoken(TKCHAR);} ; enumtype : '(' ident_list ')' { if(debug) printf("( ident_list )\n"); $$ = build3a('(',$2,'(');} ; subrangetype: integer TKDTDT integer {if(debug) printf("subrangetype->integer .. integer\n"); $$ = build3b(int_index,TKDTDT,int_index);} ; pointertype : '^' ident {if(debug) printf("pointertype-> ^ ident\n"); $$ = build2d('^',ident_index);} ; arraytype : packedarray { if(debug) printf("arraytype-> packedarray\n");} | unpackedarray { if(debug) printf("arraytype-> upackedarray\n");} ; packedarray : TKPACKED TKARRAY '[' array_dims ']' TKOF type { if(debug) printf("packedarray-> PACKED ARRAY [ array_dims ] OF type\n"); $$ = build7b(TKPACKED,TKARRAY,'[',$4,']',TKOF,$7);} ; unpackedarray : TKARRAY '[' array_dims ']' TKOF type { if(debug) printf("upackedarray-> ARRAY [ array_dims ] OF type\n"); $$ = build6b (TKARRAY,'[',$3,']',TKOF,$6);} ; array_dims : array_dim { if (debug) printf("array_dims-> array_dim\n");} | array_dims ',' array_dim {if(debug) printf("array_dims->array_dims , array_dim\n"); $$ = build3($1,',',$3);} ; array_dim : sint TKDTDT sint {if(debug) printf("array_dim-> sint TKDTDT sint\n"); $$ = build3k($1,TKDTDT,$3);} ; recordtype : TKRECORD field_list TKEND { if(debug) printf("recordtype-> RECORD field_list END\n"); $$ = build3c (TKRECORD,$2,TKEND);} ; field_list : ident_list ':' type { if(debug) printf("field_list-> ident_list : type\n"); $$ = build3($1,':',$3);} | ident_list ':' type ';' field_list { if(debug) printf("field_list-> ident_list : type ; field_list\n"); $$ = build5a($1,':',$3,';',$5);} | TKCASE simptype TKOF caselist { if(debug) printf("field_list-> CASE simptype OF caselist\n"); $$ = build4(TKCASE,$2,TKOF,$4);} ; ident_list : ident_list ',' ident { if(debug) printf("ident_list-> ident_list , ident\n"); $$ = build3d($1,',',ident_index);} | ident { if(debug) printf("ident_list-> ident\n"); $$ = buildident(ident_index);} ; caselist : caseitem ';' caselist { if(debug) printf("caselist-> caseitem ; caselist\n"); $$ = build3($1,';',$3);} | caseitem { if(debug) printf("caselist-> caseitem\n");} ; caseitem : constlist ':' '(' field_list ')' { if(debug) printf("caseitem-> constlist : (field_list)\n"); $$=build5c($1,':','(',$4,')');} ; filetype : TKFILE TKOF datatype { if(debug) printf("filetype-> FILE OF datatype\n"); $$ = build3f(TKFILE,TKOF,$3);} ; settype : TKSET TKOF enumtype { if(debug) printf("settype-> SET OF enumtype\n"); $$ = build3f(TKSET,TKOF,$3);} | TKSET TKOF subrangetype {if(debug) printf("setype-> SET OF subrangetype\n"); $$ = build3f(TKSET,TKOF,$3);} ; var_dcl : TKVAR varlist ';' absoption {if (debug) printf("var_dcl-> VAR varlist ; absolute\n"); $$ = build4a(TKVAR,$2,';',$4); } | { $$ = buildempty();} ; absoption : TKABSOLUTE constant TKDTDT constant ';' {if (debug) printf("absolute-> ABSOLUTE constant..constant ;\n"); $$ = build5f(TKABSOLUTE,$2,TKDTDT,$4,';');} | { if (debug) printf("absolute-> ***empty***\n"); $$= buildempty ();} ; varlist : varlist ';' varitem { if (debug) printf("varlist-> varlist ; varitem\n"); $$ = build3($1,';',$3); } | varitem {if (debug) printf("varlist-> varitem\n");} ; varitem : ident_list ':' type {if (debug) printf("varitem-> identlist : type\n"); $$ = build3($1,':',$3); } ; procdecl : prochead parms ';' pblk pblock ';' {if (debug) printf("procdcl-> prochead parms; pblk pblock ;\n"); $$ = build6g1($1,$2,';',$4,$5,';');} ; prochead : TKPROCEDURE ident {if (debug) printf("prochead-> PROCEDURE ident\n"); $$ = build2e(TKPROCEDURE,ident_index);} ; funcdecl : funchead parms ':' simptype ';' fblk pblock ';' {if (debug) printf("funcdcl-> funchead parms :simpletype ; fblk pblock ;\n"); $$ = build8g( $1,$2,':',$4,';',$6,$7,';');} ; fblk : {if(debug) printf("fblk-> **empty**\n");} ; funchead : TKFUNCTION ident {if (debug) printf("funchead-> FUNCTION ident\n"); $$ = build2e(TKFUNCTION,ident_index);} ; parms : {if (debug) printf("parms-> ***empty***\n"); $$ = buildempty();} | '(' parmlist ')' {if (debug) printf("parms-> ( parmlist )\n"); $$ = build3h('(',$2,')');} ; parmlist : parmlist ';' parm {if (debug) printf("parmlist-> parmlist ; parm\n"); $$ = build3( $1,';',$3);} | parm { if (debug) printf("parmlist-> parm\n");} ; parm : TKVAR ident_list ':' simptype {if (debug) printf("parm-> VAR ident_list : simpletype\n"); $$= build4a(TKVAR,$2,':',$4);} | ident_list ':' simptype {if (debug) printf("parm-> ident_list : simpltype\n"); $$= build3($1,':',$3);} ; statment_list : statment_list ';' stmt {if (debug) printf("statment_list-> statment_list ; stmt\n"); $$ = build3($1,';',$3);} | stmt {if (debug) printf("statment_list-> stmt\n");} stmt : TKIF expr TKTHEN stmt TKELSE stmt {if (debug) printf("stmt-> IF expr THEN stmt ELSE stmt\n"); $$ = build6(TKIF,$2,TKTHEN,$4,TKELSE,$6);} |TKIF expr TKTHEN stmt {if (debug) printf("stmt-> IF expr THEN stmt\n"); $$ = build4(TKIF,$2,TKTHEN,$4);} | TKWHILE expr TKDO stmt {if (debug) printf("stmt->WHILE expr DO stmt\n"); $$ = build4(TKWHILE,$2,TKDO,$4);} | TKREPEAT statment_list TKUNTIL expr {if (debug) printf("stmt-> REPEATE stmt UNTIL bollean\n"); $$ = build4(TKREPEAT,$2,TKUNTIL,$4);} | TKFOR varhead TKASG expr TKTO expr fup stmt {if (debug) printf("stmt-> FOR varhead := expr TO expr fup stmt\n"); $$ = build8a(TKFOR,$2,TKASG,$4,TKTO,$6,$7,$8);} | TKFOR varhead TKASG expr TKDOWNTO expr fup stmt {if (debug) printf("stmt-> FOR varhead := expr DOWNTO expr fup stmt\n"); $$ = build8a(TKFOR,$2,TKASG,$4,TKDOWNTO,$6,$7,$8);} | TKGOTO integer { if (debug) printf("stmt-> GOTO integer\n"); $$ = build2d(TKGOTO,int_index);} | TKGOTO ident {if (debug) printf("stmt->GOTO ident\n"); $$ = build2e (TKGOTO,ident_index);} | TKBEGIN statment_list TKEND { if (debug) printf("stmt-> BEGIN stmtlist END\n"); $$ = build3c(TKBEGIN,$2,TKEND);} | TKWITH ident_list TKDO stmt {if (debug) printf("WITH ident_list DO stmt\n"); $$ = build4(TKWITH,$2,TKDO,$4);} | variable TKASG expr {if (debug) printf("stmt-> variable := expr\n"); $$ = build3k($1,TKASG,$3);} | TKCASE expr TKOF casestmt optionalelse TKEND {if (debug) printf("stmt-> CASE expr OF casestmt optionalelse END\n"); $$=build6a(TKCASE,$2,TKOF,$4,$5,TKEND);} | ident '(' exprlist ')' {if (debug) printf("stmt->function_ident ( exprlist )\n"); $$ = build4d(ident_index,'(',$3,')'); } | integer ':' stmt { if (debug) printf("stmt-> integer : stmt\n"); $$ = build3a1(int_index,';',$3); } | { if (debug) printf("stmt-> ** empty**\n"); $$ = buildempty();} | ident { if (debug) printf("stmt-> ident\n"); buildident(ident_index); } | readwrite { if (debug) printf("stmt-> readwrite \n"); } ; readwrite : TKWRITE writearg {if (debug) printf("readwrite-> WRITE args\n"); $$=build2c(TKWRITE,$2);} | TKWRITELN writearg {if(debug) printf("readwrite-> WRITELN args\n"); $$ = build2c(TKWRITELN,$2);} | TKREAD readarg {if(debug) printf("readwrite-> READ readargs\n"); $$ = build2c(TKREAD,$2);} | TKREADLN readarg {if (debug) printf("readwrite-> READLN readargs\n"); $$ = build2c(TKREADLN,$2);} ; writearg : '(' iolist ')' {if(debug) printf("writearg-> ( iolist )\n"); $$ = build3a('(',$2,')');} | {if(debug) printf("writearg-> ** empty ** \n"); $$ = buildempty();} ; readarg : '(' variable ')' {if(debug) printf("readarg-> ( variable ) \n"); $$ = build3a('(',$2,')');} | {if(debug) printf("readarg-> **empty**\n"); $$= buildempty();} ; iolist : iolist ',' ioitem {if (debug) printf("iolist -> iolist , ioitem\n"); $$ = build3($1,',',$3);} | ioitem { if(debug) printf("iolist -> ioitem\n");} ; ioitem : string { if (debug) printf("ioitem-> string\n"); $$ = buildstring(string_index);} | variable format { if(debug) printf("ioitem->variable format\n"); $$ = build2($1,$2);} ; format : ':' integer ':' integer { if (debug) printf("format-> : integer : integer\n"); $$ = build4mn(':',int_index,':',int_index);} | {if(debug) printf("format-> ** empty **\n"); $$ = buildempty();} ; exprlist : exprlist ',' expr {if(debug) printf("exprlist-> exprlist , expr\n"); $$ = build3($1,',',$3);} | expr { if (debug) printf("exprlist-> expr\n");} ; optionalelse : TKELSE stmt {if (debug) printf("optionalelse-> ELSE stmt\n"); $$ = build2c(TKELSE,$2); } casestmt : casestmt ';' caseitem {if (debug) printf("casestmt-> casestmt ; caseitem\n"); $$=build3($1,';',$3);} | caseitem {if (debug) printf("casestmt-> caseitem\n");} ; caseitem : constlist ':' stmt {if (debug) printf("caseitem-> constlist : stmt\n"); $$ = build3($1,':',$3);} ; constlist : constlist ',' constant { if (debug) printf("sonstlist-> constlist , constant\n"); $$ = build3($1,',',$3);} | constant {if (debug) printf("constlist-> constant\n");} ; fup : TKDO { if(debug) printf("fup-> DO\n"); $$ = buildtoken(TKDO);} ; expr : expr relop simpleexpr { if (debug) printf("expr-> expr relop simple_expr\n"); $$ = build3l($1,$2,$3);} | simpleexpr { if (debug) printf("expr-> simple_expr\n"); } ; relop : '<' {if (debug) printf("relop-> <\n"); $$ = build1('<');} | '>' {if (debug) printf("relop-> >\n"); $$ = build1('>');} | TKLE {if (debug) printf("relop-> LE\n"); $$ = buildtoken(TKLE);} | TKGE {if (debug) printf("relop-> GE\n"); $$ = buildtoken(TKGE);} | '=' {if (debug) printf("relop-> =\n"); $$ = build1('=');} | TKNE {if (debug) printf("relop-> NE\n"); $$ = buildtoken(TKNE);} | TKIN {if (debug) printf("relop-> IN\n"); $$ = buildtoken(TKIN);} ; simpleexpr : '+' termlist { if (debug) printf("simple_expr-> + termlist\n"); $$ = build2f('+',$2);} | '-' termlist { if(debug) printf("simple_expr-> - termlist\n"); $$ = build2f('-',$2);} | termlist { if (debug) printf("simple_expr-> termlist\n");} ; termlist : termlist '+' term { if (debug) printf("termlist-> termlist + term\n"); $$ = build3($1,'+',$3);} | termlist '-' term { if (debug) printf("termlist-> termlist - term\n"); $$ = build3($1,'-',$3);} | termlist TKOR term { if (debug) printf("termlist-> termlist OR term\n"); $$ = build3k($1,TKOR,$3);} | termlist TKXOR term {if(debug) printf("termlist-> termlist XOR term\n"); $$ = build3k($1,TKXOR,$3); } |term { if (debug) printf("termlist -> term\n");} ; term : term '*' unary {if(debug) printf("term-> term * term\n"); $$ = build3($1,'*',$3);} | term '/' unary {if(debug) printf("term-> term / unary\n"); $$ = build3($1,'/',$3);} | term TKMOD unary {if(debug) printf("term-> term MOD unary\n"); $$ = build3k($1,TKMOD,$3);} | term TKDIV unary {if(debug) printf("term-> term DIV unary\n"); $$ = build3k($1,TKDIV,$3);} | term TKSHL unary {if(debug) printf("term-> term SHL unary\n"); $$ = build3k($1,TKSHL,$3);} | term TKSHR unary {if(debug) printf("term-> term SHR unary\n"); $$ = build3k($1,TKSHR,$3);} | unary {if(debug) printf("term-> unary\n");} ; unary : primary {if(debug) printf("unary-> primary\n");} /* | '-' primary {if(debug) printf("unary-> - primary\n"); $$ = build2f('-',$2);} */ ; primary : '(' expr ')' {if(debug) printf("primary-> ( expr )\n"); $$ = build3h('(',$2,')');} | variable {if(debug) printf("primary-> variable\n");} | constant {if(debug) printf("primary-> constant\n");} | TKNOT primary { if (debug)printf("primary-> NOT primary\n"); $$=build2c(TKNOT,$2);} ; variable : varhead varexten {if(debug) printf("variable-> varhead varextn\n"); $$ = build2($1,$2);} ; varhead : ident {if(debug) printf("varhead-> ident\n"); $$ = buildident(ident_index);} ; varexten : varexten varext {if(debug) printf("varexten-> varexten varext\n"); $$ = build2($1,$2);} | {if(debug) printf("varexten-> **empty**\n"); $$ = buildempty();} ; varext : '[' boollist ']' {if(debug) printf("varext-> [ boolist ]\n"); $$ = build3h('[',$2,']');} | '.' ident {if(debug) printf("varext-> . ident\n"); $$ = build2b('.',ident_index);} | '(' expr ')' { if(debug) printf("varext-> ( expr ) \n"); $$ = build3h('(',$2,')');} ; boollist : boollist ',' expr {if(debug) printf("boolist-> boolist , expr\n"); $$ = build3($1,',',$3);} | expr { if(debug) printf("boollist-> expr\n");} ; constant : real {if(debug) printf("constant->real\n"); $$ = buildreal(real_index);} | integer {if(debug) printf("constant-> integer\n"); $$ = buildint(int_index);} | TKTRUE {if(debug) printf("constant-> TRUE\n"); $$ = buildtoken(TKTRUE);} | TKFALSE {if(debug) printf("constant-> FALSE\n"); $$ = buildtoken(TKFALSE);} ; sint : integer {if(debug) printf("sint-> integer\n"); $$ = buildint(int_index);} | '-' integer {if(debug) printf("sint-> - integer\n"); $$ = build2g('-',int_index);} |ident {if(debug) printf("sint-> ident\n"); $$ = buildident(ident_index);} ; %% # include "lex.yy.cc" /******************/ int buildempty() { tree_last++; tree[tree_last].rhsn = 1; tree[tree_last].rhstype[1] = EMPTY ; tree[tree_last].rhsindx[1] = 0; /* whatever iam not gonna use it any way*/ return(tree_last); } /****************************************************/ int build1(a) /* ('') */ int a; { int debug=0; if (debug) printf(" in build literak %c= treelast = %d",a,tree_last); else ; tree_last++; tree[tree_last].rhsn = 1; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; return(tree_last); } /**************************************************/ int buildint(a) /* (int_index) */ int a; { int debug=0; if (debug) printf(" in build integer the index= %d treelast = %d",int_index,tree_last); else ; tree_last++; tree[tree_last].rhsn = 1; tree[tree_last].rhstype[1] = INTEGER_IDENT; tree[tree_last].rhsindx[1] = a; return(tree_last); } /************************/ int buildstring(a) /* (string_index) */ int a; { int debug=0; if (debug) printf(" in build string the index= %d treelast = %d",int_index,tree_last); else ; tree_last++; tree[tree_last].rhsn = 1; tree[tree_last].rhstype[1] = STRING_IDENT; tree[tree_last].rhsindx[1] = a; return(tree_last); } /*************************************************************/ int buildreal(a) /* (real_index) */ int a; { int debug=0; if (debug) printf(" in build real the treelast = %d",tree_last); else ; tree_last++; tree[tree_last].rhsn = 1; tree[tree_last].rhstype[1] = REAL_IDENT; tree[tree_last].rhsindx[1] = a; return(tree_last); } /******************************************************************/ int buildident(a) /* (ident_index) */ int a; { int debug=0; if (debug) printf(" in build idnet the index= %d treelast = %d",ident_index,tree_last); else ; tree_last++; tree[tree_last].rhsn = 1; tree[tree_last].rhstype[1] = IDENT; tree[tree_last].rhsindx[1] = a; return(tree_last); } /*******************************************/ int buildtoken(a) /* (token) */ int a; { int debug=0; if(debug) printf(" in build token the treelast = %d",tree_last); else ; tree_last++; tree[tree_last].rhsn = 1; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; return(tree_last); } /**********************************************************/ int build2h(a,b) /* intindex,'') */ int a,b; { int debug=0; if (debug) printf(" in build2h treelast = %d",tree_last); else ; tree_last++; tree[tree_last].rhsn=2; tree[tree_last].rhstype[1] =INTEGER_IDENT; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; return(tree_last); } /**************************************/ int build2k(a,b) /* (ident_index,'') */ int a,b; { int debug=0; if (debug) printf(" in build 2k treelast = %d",tree_last); else ; tree_last++; tree[tree_last].rhsn=2; tree[tree_last].rhstype[1] = IDENT; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; return(tree_last); } /*************************************************************/ int build2(a,b) /* ($,$) */ int a,b; { tree_last++; tree[tree_last].rhsn = 2; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; return(tree_last); } /************************************************************/ int build2a(a,b) /* ($,'') */ int a,b; { tree_last++; tree[tree_last].rhsn = 2; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; return(tree_last); } /*******************************************/ int build2b(a,b) /* ('',ident_index) */ int a,b; { tree_last++; tree[tree_last].rhsn = 2; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = IDENT; tree[tree_last].rhsindx[2] = b; return(tree_last); } /***********************************/ int build2c(a,b) /* (token,$) */ int a,b; { tree_last++; tree[tree_last].rhsn = 2; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; return(tree_last); } /***********************************************/ int build2d(a,b) /* (token,int_index) */ int a,b; { tree_last++; tree[tree_last].rhsn = 2; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = INTEGER_IDENT; tree[tree_last].rhsindx[2] = b; return(tree_last); } /*******************************************************************/ int build2f(a,b) /* ('',$) */ int a,b; { tree_last++; tree[tree_last].rhsn = 2; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; return(tree_last); } /**********************************/ int build2g(a,b) /* ('',int_index) */ int a,b; { tree_last++; tree[tree_last].rhsn = 2; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = INTEGER_IDENT; tree[tree_last].rhsindx[2] = b; return(tree_last); } /*******************************************/ int build2e(a,b) /* (token,ident_index) */ int a,b; { tree_last++; tree[tree_last].rhsn = 2; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = IDENT; tree[tree_last].rhsindx[2] = b; return(tree_last); } /*****************************************************************/ int build3(a,b,c) /* ($,'',$) */ int a,b,c; { int debug=0; if (debug) printf(" in build3 tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; return(tree_last); } /*************************/ int build3kh(a,b,c) /* ('',identindex,'') */ int a,b,c; { int debug=0; if (debug) printf(" in build3kh tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = IDENT; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; return(tree_last); } /*****************************/ int build3kk(a,b,c) /* (token,$,'') */ int a,b,c; { int debug=0; if (debug) printf(" in build3kk tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; return(tree_last); } /********************************/ int build3a1(a,b,c) /* (int_index,'',$) */ int a,b,c; { int debug=0; if (debug) printf(" in build3a1 tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = INTEGER_IDENT; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; return(tree_last); } /**********************************/ int build3a2(a,b,c) /* (ident_index ,'',$) */ int a,b,c; { int debug=0; if (debug) printf(" in build3a2 tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1]= IDENT; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; return(tree_last); } /********************************/ int build3a(a,b,c) /* ('',$,'') */ int a,b,c; { int debug=0; if (debug) printf(" in build3a tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; return(tree_last); } /**********************************/ int build3a3(a,b,c) /* (ident_index,token,$) */ int a,b,c; { int debug=0; if (debug) printf(" in build3a3 tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn=3; tree[tree_last].rhstype[1] = IDENT; tree[tree_last].rhstype[1] = a; tree[tree_last].rhstype[2] = TOKEN; tree[tree_last].rhstype[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhstype[3] = c; return(tree_last); } /*****************************************/ int build3b(a,b,c) /* (int_index,token,int_index) */ int a,b,c; { int debug=0; if (debug) printf(" in build3b tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = INTEGER_IDENT; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = TOKEN; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = INTEGER_IDENT; tree[tree_last].rhsindx[3] = c; return(tree_last); } /*********************************************/ int build3c(a,b,c) /* (token,$,token) */ int a,b,c; { int debug=0; if (debug) printf(" in build3c tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; return(tree_last); } /**********************************************************/ int build3d(a,b,c) /* ($,'',ident_index) */ int a,b,c; { int debug=0; if (debug) printf(" in build3d tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = IDENT; tree[tree_last].rhsindx[3] = c; return(tree_last); } /******************************************/ int build3e(a,b,c) /* ($,'',int_index) */ int a,b,c; { int debug=0; if (debug) printf(" in build3e tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = INTEGER_IDENT; tree[tree_last].rhsindx[3] = c; return(tree_last); } /*******************************************/ int build3f(a,b,c) /* (token,token,$) */ int a,b,c; { int debug=0; if (debug) printf(" in build3f tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = TOKEN; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; return(tree_last); } /*********************************************************/ int build3h(a,b,c) /* ('',$,'') */ int a,b,c; { int debug=0; if (debug) printf(" in build3h tree index =%d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; return(tree_last); } /*****************************************************************/ int build3k(a,b,c) /* ($,token,$) */ int a,b,c; { tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = TOKEN; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; return(tree_last); } /*********************************/ int build3l(a,b,c) /* ($,$,$) */ int a,b,c; { int debug=0; if (debug) printf (" in build3l tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; return(tree_last); } /************************************/ int build3g(a,b,c) /* (token.'',$) */ int a,b,c; { int debug=0; if (debug) printf (" in build3g tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 3; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; return(tree_last); } /*************************************/ int build4(a,b,c,d) /* (token,$,token,$) */ int a,b,c,d; { int debug=0; if (debug) printf (" in build4 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 4; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; return(tree_last); } /***********************/ int build4mn(a,b,c,d) /* ('',int_index,'',int_index */ int a,b,c,d; { int debug=0; if (debug) printf (" in build4 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 4; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = INTEGER_IDENT; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = INTEGER_IDENT; tree[tree_last].rhsindx[4] = d; return(tree_last); } /*********************************/ int build4a(a,b,c,d) /* (token,$,'',$) */ int a,b,c,d; { int debug=0; if (debug) printf (" in build4a tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 4; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; return(tree_last); } /*************************************/ int build4d3(a,b,c,d) /* (token,$,token,'') */ int a,b,c,d; { int debug=0; if (debug) printf (" in build4d3 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 4; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = LITERAL; tree[tree_last].rhsindx[4] = d; return(tree_last); } /*************************************/ int build4d2(a,b,c,d) /* (int_index,token,int)index,'') */ int a,b,c,d; { int debug=0; if (debug) printf (" in build4d2 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 4; tree[tree_last].rhstype[1] = INTEGER_IDENT; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = TOKEN; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = INTEGER_IDENT; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = LITERAL; tree[tree_last].rhsindx[4] = d; return(tree_last); } /******************/ int build4d1(a,b,c,d) /* (ident_index,'',int_index,'') */ int a,b,c,d; { int debug=0; if (debug) printf (" in build4d1 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 4; tree[tree_last].rhstype[1] = IDENT; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = INTEGER_IDENT; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = LITERAL; tree[tree_last].rhsindx[4] = d; return(tree_last); } /*******************************************************/ int build4c(a,b,c,d) /* ($,'',$,'') */ int a,b,c,d; { int debug=0; if (debug) printf (" in build4c tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 4; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = LITERAL; tree[tree_last].rhsindx[4] = d; return(tree_last); } /******************************/ int build4d(a,b,c,d) /* (ident_index,'',$,'') */ int a,b,c,d; { int debug=0; if (debug) printf (" in build4d tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 4; tree[tree_last].rhstype[1] = IDENT; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = LITERAL; tree[tree_last].rhsindx[4] = d; return(tree_last); } /***************************************/ int build5(a,b,c,d,e) /* ($,$,'',$,'') */ int a,b,c,d,e; { int debug=0; if (debug) printf (" in build5 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 5; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; return(tree_last); } /*******************/ int build5c1(a,b,c,d,e) /* (token,$,'',$,'') */ int a,b,c,d,e; { int debug=0; if (debug) printf (" in build5c1 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 5; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; return(tree_last); } /*********************/ int build5f(a,b,c,d,e) /* (token,$,token,$,'') */ int a,b,c,d,e; { int debug=0; if (debug) printf (" in build5f tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 5; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; return(tree_last); } /***************************************/ int build5d1(a,b,c,d,e) /* (token,$,'',token,'') */ int a,b,c,d,e; { int debug=0; if (debug) printf (" in build5d1 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 5; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = TOKEN; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; return(tree_last); } /****************************************/ int build5a(a,b,c,d,e) /* ($,'',$,'',$) */ int a,b,c,d,e; { int debug=0; if (debug) printf (" in build5a tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 5; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = LITERAL; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = SUBTREE; tree[tree_last].rhsindx[5] = e; return(tree_last); } /*********************/ int build5d(a,b,c,d,e) /* (token,identindex,'',$,'') */ int a,b,c,d,e; { int debug=0; if (debug) { printf (" in build5d MINE LINE tree index = %d\n",tree_last); printf (" ident index = %d",ident_index); } else ; tree_last++; tree[tree_last].rhsn = 5; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = IDENT; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; return(tree_last); } /****************************************/ int build5b(a,b,c,d,e) /* ($,$,'',token,'') */ int a,b,c,d,e; { int debug=0; if (debug) printf (" in build5b tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 5; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = TOKEN; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; return(tree_last); } /*******************************************/ int build5c(a,b,c,d,e) /* ($,'','',$,'') */ int a,b,c,d,e; { tree_last++; tree[tree_last].rhsn = 5; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; return(tree_last); } /******************************************/ int build6(a,b,c,d,e,f) /* (token,$,token,$,token,$) */ int a,b,c,d,e,f; { int debug=0; if (debug) printf (" in build6 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 6; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = TOKEN; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = SUBTREE; tree[tree_last].rhsindx[6] = f; return(tree_last); } /******************/ int build6a(a,b,c,d,e,f) /* (token,$,token,$,'',$) */ int a,b,c,d,e,f; { int debug=0; if (debug) printf (" in build6a tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 6; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = TOKEN; tree[tree_last].rhsindx[6] = f; return(tree_last); } /**********************/ int build6c(a,b,c,d,e,f) /* (token,$,token,$,$,token) */ int a,b,c,d,e,f; { int debug=0; if (debug) printf (" in build6a tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 6; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = SUBTREE; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = TOKEN; tree[tree_last].rhsindx[6] = f; return(tree_last); } /**********************/ int build6g(a,b,c,d,e,f) /* (token,$,'',$,$,'') */ int a,b,c,d,e,f; { int debug=0; if (debug) printf (" in build6g tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 6; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = SUBTREE; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = LITERAL; tree[tree_last].rhsindx[6] = f; return(tree_last); } /***************/ int build6h(a,b,c,d,e,f) /* ($,$,$,$,$,$) */ int a,b,c,d,e,f; { int debug=0; if (debug) printf (" in build6h tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 6; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = SUBTREE; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = SUBTREE; tree[tree_last].rhsindx[6] = f; return(tree_last); } /*****************/ int build6g1(a,b,c,d,e,f) /* ($,$,'',$,$,'') */ int a,b,c,d,e,f; { int debug=0; if (debug) printf (" in build6h tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 6; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = SUBTREE; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = LITERAL; tree[tree_last].rhsindx[6] = f; return(tree_last); } /****************/ int build6b(a,b,c,d,e,f) /* (token,'',$,'',token,$) */ int a,b,c,d,e,f; { int debug=0; if (debug) printf (" in build6b tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 6; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = LITERAL; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = TOKEN; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = LITERAL; tree[tree_last].rhsindx[6] = f; return(tree_last); } /**************************************/ int build7(a,b,c,d,e,f,g) /* ('',$,tpken,$,'',token,$) */ int a,b,c,d,e,f,g; { int debug=0; if (debug) printf (" in build7 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 7; tree[tree_last].rhstype[1] = LITERAL; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = TOKEN; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = SUBTREE; tree[tree_last].rhsindx[7] = g; return(tree_last); } /*************************/ int build7b(a,b,c,d,e,f,g) /* (token,token,'',$,'',tok,$) */ int a,b,c,d,e,f,g; { int debug=0; if (debug) printf (" in build7b tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 7; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = TOKEN; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = TOKEN; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = SUBTREE; tree[tree_last].rhsindx[7] = g; return(tree_last); } /*******************/ int build7d1(a,b,c,d,e,f,g) /* ($,$,$,$,$,$,$) */ int a,b,c,d,e,f,g; { int debug=0; if (debug) printf (" in build7d1 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 7; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = SUBTREE; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = SUBTREE; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = SUBTREE; tree[tree_last].rhsindx[7] = g; return(tree_last); } /**************************************/ int build7f(a,b,c,d,e,f,g) /* ($,$,'',ident_index,'',$,'') */ int a,b,c,d,e,f,g; { int debug=0; if (debug) printf (" in build7 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 7; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = IDENT; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = SUBTREE; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = LITERAL; tree[tree_last].rhsindx[7] = g; return(tree_last); } /****************************************************/ int build7a(a,b,c,d,e,f,g) /* ($,$,'',ident_index,'',token,'') */ int a,b,c,d,e,f,g; { int debug=0; if (debug) printf (" in build7a tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 7; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = IDENT; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = TOKEN; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = LITERAL; tree[tree_last].rhsindx[7] = g; return(tree_last); } /**********************************************/ int build8g(a,b,c,d,e,f,g,h) /* ($,$,'',$,'',$,$,'') */ int a,b,c,d,e,f,g,h; { int debug=0; if (debug) printf (" in build8g tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 8; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = LITERAL; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = SUBTREE; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = SUBTREE; tree[tree_last].rhsindx[7] = g; tree[tree_last].rhstype[8] = LITERAL; tree[tree_last].rhsindx[8] = h; return(tree_last); } /*************/ int build8(a,b,c,d,e,f,g,h) /* (token,'',$,token,$,'',tken,$)*/ int a,b,c,d,e,f,g,h; { int debug=0; if (debug) printf (" in build8 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 8; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = LITERAL; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = TOKEN; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = SUBTREE; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = LITERAL; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = TOKEN; tree[tree_last].rhsindx[7] = g; tree[tree_last].rhstype[8] = SUBTREE; tree[tree_last].rhsindx[8] = h; return(tree_last); } /***********************/ int build8g1(a,b,c,d,e,f,g,h) /* ($,$,$,$,$.$.$.token)*/ int a,b,c,d,e,f,g,h; { int debug=0; if (debug) printf (" in build8g1 trebe index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 8; tree[tree_last].rhstype[1] = SUBTREE; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = SUBTREE; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = SUBTREE; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = SUBTREE; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = SUBTREE; tree[tree_last].rhsindx[7] = g; tree[tree_last].rhstype[8] = TOKEN; tree[tree_last].rhsindx[8] = h; return(tree_last); } /*************************************************/ int build8a(a,b,c,d,e,f,g,h) /* (token,$,token,$,token,$,$,$) */ int a,b,c,d,e,f,g,h; { int debug=1; tree_last++; tree[tree_last].rhsn = 8; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = SUBTREE; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = TOKEN; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = TOKEN; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = SUBTREE; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = SUBTREE; tree[tree_last].rhsindx[7] = g; tree[tree_last].rhstype[8] = SUBTREE; tree[tree_last].rhsindx[8] = h; return(tree_last); } /*********************/ int build9(a,b,c,d,e,f,g,h,k) /* (token,token,'',$,token,$,'',token,$) */ int a,b,c,d,e,f,g,h,k; { int debug=0; if (debug) printf (" in build8 tree index = %d\n",tree_last); else ; tree_last++; tree[tree_last].rhsn = 9; tree[tree_last].rhstype[1] = TOKEN; tree[tree_last].rhsindx[1] = a; tree[tree_last].rhstype[2] = TOKEN; tree[tree_last].rhsindx[2] = b; tree[tree_last].rhstype[3] = LITERAL; tree[tree_last].rhsindx[3] = c; tree[tree_last].rhstype[4] = SUBTREE; tree[tree_last].rhsindx[4] = d; tree[tree_last].rhstype[5] = TOKEN; tree[tree_last].rhsindx[5] = e; tree[tree_last].rhstype[6] = SUBTREE; tree[tree_last].rhsindx[6] = f; tree[tree_last].rhstype[7] = LITERAL; tree[tree_last].rhsindx[7] = g; tree[tree_last].rhstype[8] = TOKEN; tree[tree_last].rhsindx[8] = h; tree[tree_last].rhsindx[9] = SUBTREE; tree[tree_last].rhsindx[9] = k; return(tree_last); } /****************************************************************/ treedump() { int i; printf(" Welcome to Pascal Parsor By Nasser Abbasi version 1.0\n All Rights Reserved\n\n\n"); printf("n The following is the PARSE tree generated \n"); for ( i=0 ; i <= tree_last ; i++ ) dumpnode(i); } /**********/ dumpnode(i) int i; { int j; printf("\n%5d ",i); for ( j=1 ; j<=tree[i].rhsn ; j++ ) switch (tree[i].rhstype[j]) { case SUBTREE: printf ("(%d) ",tree[i].rhsindx[j]); break; case LITERAL: printf ("%c ",tree[i].rhsindx[j]); break; case IDENT: printf ("%s ",symtable[tree[i].rhsindx[j]]); break; case INTEGER_IDENT: printf ("%s ",inttable[tree[i].rhsindx[j]]); break; case REAL_IDENT: printf ("%s ",realtable[tree[i].rhsindx[j]]); break; case TOKEN: print_token(tree[i].rhsindx[j]); break; case STRING_IDENT: printf ("%s ",stringtable[tree[i].rhsindx[j]]); break; case EMPTY: printf("*empty*"); break; default: printf ("\n error cannot recorgize type in tree"); break; } } /********************************************************************/ print_token(a) int a; { switch (a) { case TKASG: printf(":= "); break; case TKNE: printf("NE "); break; case TKLE: printf("LE "); break; case TKGE: printf("GE "); break; case TKDTDT: printf(".. "); break; case TKABSOLUTE: printf("ABSOLUTE "); break; case TKAND: printf("AND "); break; case TKARRAY: printf("ARRAY "); break; case TKBEGIN: printf("BEGIN "); break; case TKCASE: printf("CASE "); break; case TKCONST: printf("CONST "); break; case TKDIV: printf("DIV "); break; case TKDO: printf("DO "); break; case TKDOWNTO: printf("DOWNTO "); break; case TKELSE: printf("ELSE "); break; case TKEND: printf("END "); break; case TKEXTERNAL: printf("EXTERNAL "); break; case TKFILE: printf("FILE "); break; case TKFORWARD: printf("FORWARD "); break; case TKFOR: printf("FOR "); break; case TKFUNCTION: printf("FUNCTION "); break; case TKGOTO: printf("GOTO "); break; case TKINLINE: printf("INLINE "); break; case TKIF: printf("IF "); break; case TKIN: printf("IN "); break; case TKLABEL: printf("LABEL "); break; case TKMOD: printf("MOD "); break; case TKNIL: printf("NIL "); break; case TKNOT: printf("NOT "); break; case TKOVERLAY: printf("OVERLAY "); break; case TKOF: printf("OF "); break; case TKOR: printf("OR "); break; case TKPACKED: printf("PACKED "); break; case TKPROCEDURE: printf("PROCEDURE "); break; case TKPROGRAM: printf("PROGRAM "); break; case TKRECORD: printf("RECORD "); break; case TKREPEAT: printf("REPEAT "); break; case TKSET: printf("SET "); break; case TKSHL: printf("SHL "); break; case TKSHR: printf("SHR "); break; case TKSTRING: printf("STRING "); break; case TKTHEN: printf("THEN "); break; case TKTYPE: printf("TYPE "); break; case TKTO: printf ("TO "); break; case TKUNTIL: printf("UNTIL "); break; case TKVAR: printf("VAR "); break; case TKWHILE: printf("WHILE "); break; case TKWITH: printf("WITH "); break; case TKXOR: printf("XOR "); break; case TKREAL: printf("REAL "); break; case TKBOOLEAN: printf("BOOLEAN "); break; case TKINTEGER: printf("INTEGER "); break; case TKREAD: printf("READ "); break; case TKWRITE: printf("WRITE "); break; case TKTRUE: printf("TRUE "); break; case TKFALSE: printf ("FALSE "); break; case TKWRITELN: printf("WRITELN "); break; case TKREADLN: printf("READLN "); break; default: printf ("error in printf token unknown token number");break; } } /*******************/ main(argc,argv) char *argv[]; int argc; { init_compiler(); yyparse(); } /***********/ init_compiler() { /* some init stuff for later enhancments */ } /************/ yyerror() { printf (" An error was detected the following is the tree at the time \n"); treedump(); exit(); }