/** * define a new structure * * @param[in] sem is the semantic table to which to add the structure * @param[in] label a c-string label for this structures * @param[in] structure_def the STRUCTURE_DEF definitions * @returns the new structure def * * <b>Examples (from test suite):</b> * @snippet spec/def_spec.h testDefStructure */ Structure _d_define_structure(SemTable *sem,char *label,T *structure_def,Context c) { T *def = _t_new_root(STRUCTURE_DEFINITION); T *l = _t_newr(def,STRUCTURE_LABEL); _t_new_str(l,ENGLISH_LABEL,label); if (structure_def) _t_add(def,structure_def); return _d_define(sem,def,SEM_TYPE_STRUCTURE,c); }
/** * add a symbol definition to a symbol defs tree * * @param[in] sem is the semantic table to which to add the symbol * @param[in] s the structure type for this symbol * @param[in] label a c-string label for this symbol * @param[in] the context in which this symbol is being declared * @returns the new symbol * @todo this is not thread safe! * * <b>Examples (from test suite):</b> * @snippet spec/def_spec.h testDefSymbol */ Symbol _d_define_symbol(SemTable *sem,Structure s,char *label,Context c){ __d_validate_structure(sem,s,label); T *def = _t_new_root(SYMBOL_DEFINITION); T *l = _t_newr(def,SYMBOL_LABEL); _t_new_str(l,ENGLISH_LABEL,label); _t_news(def,SYMBOL_STRUCTURE,s); return _d_define(sem,def,SEM_TYPE_SYMBOL,c); }
void addCommand(Receptor *r,ReceptorAddress ox,char *command,char *desc,T *code,T *bindings_handler) { T *expect = _t_new_root(PATTERN); T *s = _t_news(expect,SEMTREX_GROUP,SHELL_COMMAND); T *cm = _sl(s,SHELL_COMMAND); T *vl = _t_newr(cm,SEMTREX_VALUE_LITERAL); T *vls = _t_newr(vl,SEMTREX_VALUE_SET); _t_new_str(vls,VERB,command); T *p = _t_new_root(SAY); __r_make_addr(p,TO_ADDRESS,ox); _t_news(p,ASPECT_IDENT,DEFAULT_ASPECT); _t_news(p,CARRIER,NULL_SYMBOL); // if code is actually an INITIATE then we will have a bindings handler // to which we want to add the SAY command as the ACTUAL_PROCESS // and we will replace the p with code which does the proper protocol // initiation. Kinda weird, I know... if (bindings_handler) { char proc_name[255] = "handle "; strcpy(&proc_name[7],command); int pt1[] = {2,1,TREE_PATH_TERMINATOR}; _t_new(p,PARAM_REF,pt1,sizeof(int)*3); Process proc = _r_define_process(r,p,proc_name,"long desc...",NULL,NULL); _t_news(bindings_handler,ACTUAL_PROCESS,proc); p = code; } else { _t_add(p,code); } Process proc = _r_define_process(r,p,desc,"long desc...",NULL,NULL); T *act = _t_newp(0,ACTION,proc); _r_add_expectation(r,DEFAULT_ASPECT,SHELL_COMMAND,expect,act,0,0,NULL,NULL); }
/** * add a name to a definition * * @param[in] sem is the semantic table where symbols and structures are defined * @param[in] s the semantic id of the definition to add a label to * @param[in] label_type is a symbol of the label type to add * @param[in] label text of the label * * <b>Examples (from test suite):</b> * @snippet spec/semtable_spec.h testSemGetByLabel */ void _sem_add_label(SemTable *sem,SemanticID s,Symbol label_type,char *label) { T *def = _sem_get_def(sem,s); T *labels = _t_child(def,DefLabelIdx); _t_new_str(labels,label_type,label); }