#include "ccg"/* cc9 *//* *Declare a static variable *  (i.e. define for use) * * makes an entry in the symbol * table so subsequent * references can call symbol by name * * typ is cchar or cint * sclass = extern or global  */declglb(typ,sclass)int typ,sclass;$(int k,j;char sname[namesize];char *ptr;/* ptr to sym table entry to** check extern*/while(1)$(while(1)$(if(endst())return;/* do line */k=1;/* assume 1 element */if(match("*"))/* pointer ? */j=pointer;/* yes */else j=variable; /* no */if(symname(sname)==0) /* name ok? */illname(); /* no... */if(ptr=findglb(sname))/* already there?*/if(ptr[storage]==extrn&& sclass != extrn)ptr[storage]=global;else if(sclass != extrn)multidef();if(match("["))$(/* array? */k=needsub();/* get size */if(k)j=array;/* !0=array */else$(j=pointer; /* 0=ptr */k=2;$)$)addglb(sname,j,typ,k,sclass); /* add symbol */break;$)if(match(",")==0)return; /* more? */$)$)/*** Declare local variables** (i.e. define for use)**** works just like "declglb" but** modifies machine stack** and adds symbol table entry with** appropriate** stack offset to find it again*/declloc(typ)/* typ is cchar or cint */int typ;$(int k,j;char sname[namesize];while(1)$(while(1)$(if(endst())return;if(match("*"))j=pointer;else j=variable;if (symname(sname)==0)illname();if(findloc(sname))multidef(sname);if (match("["))$(k=needsub();if(k)$(j=array;if(typ==cint)k=k+k;$)else$(j=pointer;k=2;$)$)elseif((typ==cchar)&(j!=pointer))k=1;else k=2;/* change machine stack (stack points to TOS) */addloc(sname,j,typ,oursp+2);oursp=modstk(oursp+k);break;$)if (match(",")==0) return;$)$)/* dump names of globals */dumpnams()$(char code;cptr=startglb;while(cptr<glbptr)$(if(cptr[ident]==function)$(if(cptr[offset]!=function)code=135;else code=136;$)else$(if(cptr[storage]==extrn)code=135;else code=136;$)outgoe(code,cptr);cptr=cptr+symsiz;$)$)/* end of cc9 */