int dodeclare ( int storage, TAG_SYMBOL *mtag, /* tag of struct whose members are being declared, or zero */ int is_struct /* TRUE if struct member is being declared, zero for union */ ) /* only matters if mtag is non-zero */ { struct varid var; /* Our little structure for iding vars */ TAG_SYMBOL *otag ; /* tag of struct object being */ /* declared */ otag=GetVarID(&var,storage); if (var.type == NO) { if (storage==EXTERNAL) var.type=CINT; else return(0); /* fail */ } if (var.type == STRUCT ) { declglb(STRUCT, storage, mtag, otag, is_struct,var.sign,var.zfar) ; return (1); } else { declglb(var.type,storage, mtag, NULL_TAG, is_struct,var.sign,var.zfar); return(1); } }
/* * parse top level declarations */ long dodcls (long stclass, TAG_SYMBOL *mtag, int is_struct) { long err; struct type t; blanks(); if (match_type(&t, NO, YES)) { if (t.type == CSTRUCT && t.otag == -1) t.otag = define_struct(t.sname, stclass, !!(t.flags & F_STRUCT)); else if (t.type == CENUM) { if (t.otag == -1) t.otag = define_enum(t.sname, stclass); t.type = enum_types[t.otag].base; } err = declglb(t.type, stclass, mtag, t.otag, is_struct); } else if (stclass == PUBLIC) return (0); else err = declglb(CINT, stclass, mtag, NULL_TAG, is_struct); if (err == 2) /* function */ return (1); else if (err) { kill(); return (0); } else ns(); return (1); }
/* definitions are legal... */ parse() { while (eof==0) /* do until no more input */ { if(amatch("char",4)){declglb(cchar);ns();} else if(amatch("int",3)){declglb(cint);ns();} else if(match("#asm"))doasm(); else if(match("#include"))doinclude(); else if(match("#define"))addmac(); else newfunc(); blanks(); /* force eof if pending */ } }