void file_watch_trigger_actions(World* world, FileWatch* watch) { // Walk through each action and execute it. for (int i = 0; i < list_length(&watch->onChangeActions); i++) { caValue* action = list_get(&watch->onChangeActions, i); Symbol label = first_symbol(action); ca_assert(label != sym_None); switch (label) { case sym_NativePatch: { caValue* moduleName = list_get(action, 1); NativePatch* nativeModule = add_native_patch(world, as_cstring(moduleName)); native_patch_load_from_file(nativeModule, as_cstring(&watch->filename)); native_patch_finish_change(nativeModule); break; } case sym_PatchBlock: { // Reload this code block. caValue* moduleName = list_get(action, 1); load_module_file(world, as_cstring(moduleName), as_cstring(&watch->filename)); break; } default: internal_error("unrecognized file watch action"); } } }
Symbol first_symbol(caValue* value) { if (is_symbol(value)) return as_symbol(value); if (is_list(value)) return first_symbol(list_get(value, 0)); return sym_None; }
int FirstFollow::main(){ //구조체 grammer 의sym_temp 객체 생성 grammer sym_temp; int i, j; //First 테이블 초기화 for(i=0;i<9;i++){ for(j=0;j<24;j++){ first[i][j]=0; } } for(i=0;i<9;i++){ // 비단말기호 , i번째 위치의 심볼 sym_temp.select=1; sym_temp.location=i; //첫번째 심볼함수 호출 first_symbol(sym_temp); } //Follow 테이블 초기화 for(i=0;i<9;i++){ for(j=0;j<23;j++){ follow[i][j]=0; } } //follow 의 시작 비단말기호와 $ 단말기호 값을 1로 follow[0][20]=1; //비단말기호 계산 for(i=0;i<9;i++){ //비단말기호 매개변수 follow_symbol(i); } return 0; }
int FirstFollow::first_symbol(grammer sym){ int top = -1; int stack[10]; if(sym.select==0) return 0; if(first[sym.location][22]==1) return 0; for(int r=0;r<23;r++){ //룰을 하나하나검사 if(sym.location == rule_v[r].left.location){ //왼쪽이 sym인 룰만 처리 if(rule_v[r].rule_len==1 && rule_v[r].right[0].select == 0 && rule_v[r].right[0].location == 22-1) //룰이 입실론이라면 퍼스트에 입실론 추가 first[sym.location][22-1]=1; else for(int i=0;i<rule_v[r].rule_len;i++){ //오른쪽의 symbol들을 하나하나처리 if(rule_v[r].right[i].select==0){ //오른쪽의 i번째 심볼이 단말기호일때 first[sym.location][rule_v[r].right[i].location]=1; break; }else if(rule_v[r].right[i].select==1){ //비단말기호일때 if(first[rule_v[r].right[i].location][22]==0){ //재귀호출이 리커시브하게 반복되면 잠시 보류해논다 if(rule_v[r].right[i].select == sym.select && rule_v[r].right[i].location == sym.location){ stack[++top] = r; break; } else first_symbol(rule_v[r].right[i]); } for(int j=0;j<22;j++) if(first[rule_v[r].right[i].location][j]==1) first[sym.location][j] =1; if(first[rule_v[r].right[i].location][21]==0) //오른쪽의 i번째 심볼이 입실론을 퍼스트로 갖고있지않다면 break; else //오른쪽의 i번째의 퍼스트가 입실론 갖고있다면 if(i==rule_v[r].rule_len-1) //i가 오른쪽에서 마지막심볼일때 sym퍼스트에 입실론 추가 first[sym.location][21]=1; } } } } if(top>=0){ if(first[sym.location][21] == 1){ while(top>=0){ int r = stack[top--]; for(int i=0;i<rule_v[r].rule_len;i++){ //오른쪽의 symbol들을 하나하나처리 if(rule_v[r].right[i].select==0){ //오른쪽의 i번째 심볼이 단말기호일때 first[sym.location][rule_v[r].right[i].location]=1; break; }else if(rule_v[r].right[i].select==1){ //비단말기호일때 if(first[rule_v[r].right[i].location][22]==0){ //재귀호출이 리커시브하게 반복되면 잠시 보류해논다 if(rule_v[r].right[i].select == sym.select && rule_v[r].right[i].location == sym.location){ ; } else first_symbol(rule_v[r].right[i]); } for(int j=0;j<22;j++) if(first[rule_v[r].right[i].location][j]==1) first[sym.location][j] =1; if(first[rule_v[r].right[i].location][21]==0) //오른쪽의 i번째 심볼이 입실론을 퍼스트로 갖고있지않다면 break; else //오른쪽의 i번째의 퍼스트가 입실론 갖고있다면 if(i==rule_v[r].rule_len-1) //i가 오른쪽에서 마지막심볼일때 sym퍼스트에 입실론 추가 first[sym.location][21]=1; } } } } } first[sym.location][22]=1; return 0; }