/********************************************************************************************************** Purpose: Set the Token code and attribute for a keyword or arithmetic variable identifier Author: Chris Whitten modified by Thom Palmer History/Versions: 10.19.13 Called functions: iskeyword(), strlen() Parameters: char lexeme[] Return value: Token t representing a valid keyword or valid arithmetic variable identifier Algorithm: Create a temporary Token, if lexeme is a keyword set appropriate properties of the Token and return the keyword Token, otherwise lexeme is an arithmetic variable identifier, set appropriate properties and return the Token * Assume that size_t is that same size as an int * **********************************************************************************************************/ Token aa_func02(char lexeme[]) { Token t; /* Temporary Token */ int kwIndex; /* Stores index in kw_table */ int vid_offset; /* Temporarily stores offset where vid was installed */ /* Call iskeyword to find if lexeme is a keyword */ kwIndex = iskeyword(lexeme); if( kwIndex >=0) { /* lexeme is a keyword. Set token code and attribute. */ t.code = KW_T; t.attribute.kwt_idx = kwIndex; return t; } /* lexeme is an arithmetic variable identifier. Set appropriate code. */ t.code = AVID_T; /* If lexeme is longer than VID_LEN add string terminator in lexeme at VID_LEN index */ if (strlen(lexeme) > VID_LEN) { lexeme[VID_LEN] = STRTERM; } /* Iterate until the end of the lexeme and add lexeme characters to vid_lex */ vid_offset = st_install(sym_table,lexeme, line); if(vid_offset < 0 ) { printf("\nError: The Symbol Table is full - install failed.\n"); st_store(sym_table); b_destroy(lex_buf); exit(SYM_TBL_FULL); } t.attribute.vid_offset = vid_offset; return t; }
/********************************************************************************************************** Purpose: Set the Token code and attribute for a string variable identifier Author: Chris Whitten History/Versions: 10.19.13 Called functions: strlen() Parameters: char lexeme[] Return value: Token t representing a valid string variable identifier Algorithm: Create a temporary Token, Assign a SVID_T code to the Token, Copy the SVID to the vid_lex array up to 8 characters and ensure that end of string is added to the array. Return the token. * Assume that size_t is that same size as an int * **********************************************************************************************************/ Token aa_func03(char lexeme[]) { Token t; /* Temporary Token */ int vid_offset; /* Temporarily stores offset where vid was installed */ /* lexeme is an string variable identifier. Set appropriate code. */ t.code = SVID_T; /* If lexeme is longer than VID_LEN add string terminator in lexeme at VID_LEN and # at VID_LEN-1*/ if (strlen(lexeme) > VID_LEN) { lexeme[VID_LEN-1] = '#'; lexeme[VID_LEN] = STRTERM; } vid_offset = st_install(sym_table,lexeme, line); if(vid_offset < 0) { printf("\nError: The Symbol Table is full - install failed.\n"); st_store(sym_table); b_destroy(lex_buf); exit(SYM_TBL_FULL); } t.attribute.vid_offset = vid_offset; return t; }
void setup_programs_gl(Scene *s, Object *objs) { int k, n; Object *o; for (k = 0, o = objs; o != NULL; k++, o = o->next) { switch (o->type) { case V_TRIMESH: case V_PRIM: { GLuint pid = st_lookup(o->mat->shd.name); if (pid == 0) { char *buf = fragp_init_lights(s->lights, o->mat->shd.fragp); pid = LoadProgram_GL(o->mat->shd.vertp, buf); efree(buf); st_install(o->mat->shd, pid); } o->mat->shd.id = pid; } break; case V_GROUP: setup_programs_gl(s, children_(o)); break; default: error("(setup_prog_gl) wrong type"); } } }
// Function to Traverse the Declarator's Derived types list, INPUT Top Node of Derived Type Built as // First Parameter and Input Type from type_specifiers built from bucket (ty_query) as Second Parameter. TYPE building_derived_type_and_install_st(DN dn, TYPE initialType, STDR_TAG stdr_tag) { TYPE type = initialType; //BOOLEAN val_array = TRUE; installSuccessful = FALSE; //msg("building_derived_type"); while(dn != NULL) { switch(dn->tag) { case ARRAY: if(dn->u.array_dim.dim <= 0) { error("illegal array dimension"); return; } else type = ty_build_array(type, TRUE, dn->u.array_dim.dim); break; case PTR: //fprintf(stderr, "Inside of PTR Switch\n"); type = ty_build_ptr(type, NO_QUAL); break; case FUNC: if(dn->u.param_list.pl == NULL) type = ty_build_func(type, PROTOTYPE, NULL); else type = ty_build_func(type, PROTOTYPE, dn->u.param_list.pl->prev); break; case REF: bug("Looking for REF \"stdr_dump\""); break; case ID: ; //msg("Installing"); ST_DR dr = stdr_alloc(); // Allocate space for the symtab data record dr->tag = stdr_tag; dr->u.decl.type = type; dr->u.decl.sc = NO_SC; dr->u.decl.err = FALSE; BOOLEAN result; result = st_install(dn->u.st_id.i,dr); if (!result) { error("duplicate declaration for %s", st_get_id_str(dn->u.st_id.i)); error("duplicate definition of '%s'", st_get_id_str(dn->u.st_id.i)); } result = st_tag_install(dn->u.st_id.i,dr); if (!result) { error("duplicate declaration for %s", st_get_id_str(dn->u.st_id.i)); error("duplicate definition of '%s'", st_get_id_str(dn->u.st_id.i)); } break; default: bug("where's the tag? \"stdr_dump\""); } dn = dn->n_node; } return type; }