/* dirdcl: parse a direct declarator */ int dirdcl(void) { char datatype[1000]; int type; if (tokentype == '(') { /* ( dcl ) */ gettoken(); if (dcl() != 0 || tokentype != ')') { printf("error: missing )\n"); return 1; } } else if (tokentype == NAME) { /* variable name */ if (name[0] == '\0') strcpy(name, token); } else { printf("error: expected name or (dcl)\n"); return 1; } type = gettoken(); if (type == '(') { /* function */ strcat(out, " function("); gettoken(); while (tokentype != ')') { datatype[0] = '\0'; while (tokentype == SPECIFIER || tokentype == QUALIFIER) { strcat(datatype, " "); strcat(datatype, token); gettoken(); } if (dcl() != 0) return 1; strcat(out, datatype); if (tokentype == ',') { strcat(out, ","); gettoken(); } } strcat(out, " ) returning"); gettoken(); } else { while (type == BRACKETS) { strcat(out, " array"); strcat(out, token); strcat(out, " of"); type = gettoken(); } } return 0; }
/* dirdcl: parse a direct declarator */ void dirdcl(void) { int type; if (tokentype == '(') { dcl(); if (tokentype != ')') { printf("error: missing )\n"); } } else if (tokentype == NAME) { strcpy(name, token); } else { printf("error: excepted name or {dcl}\n"); } while ((type = gettoken()) == PARENS || type == BRACKETS) { if (type == PARENS) { strcat(out, " function returning"); } else { strcat(out, " array"); strcat(out, token); strcat(out, " of"); } } }
/** parse direct declaration */ void dirdcl(void) { int type; /** "( dcl )" */ if (tokentype == '(') { dcl(); if (tokentype != ')') printf("error: missing ')'\n"); } /** variable name */ else if (tokentype == NAME) strcpy(name, token); else printf("error: expected name or ( dcl )\n"); while ((type = gettoken()) == PARENS || type == BRACKETS) { if (type == PARENS) strcat(out, " function returning"); else { strcat(out, " array"); strcat(out, token); strcat(out, " of"); } } }
int main() { while (gettoken() != EOF) { if (tokentype == '*') { printf("syntax error: expected simple type (char, int) got *\n"); return 1; } // do nothing if empty input if (token[0] != '\0') { strcpy(datatype, token); out[0] = '\0'; if (dcl()) { if (tokentype == '(') { printf("syntax error: unclosed (\n"); return 1; } else if (tokentype != '\n') { printf("syntax error: expected newline got %s\n", describe_tokentype(tokentype)); return 1; } else { printf("%s:%s %s\n", name, out, datatype); return 0; } } else { // error: message should already have been printed return 1; } } } return 0; }
int main(void){ extern int tokentype; extern char token[MAX_TOKEN_SIZE]; while(gettoken() != EOF){ strcpy(datatype, token); // first token is the data type out[0] = '\0'; dcl(); if(tokentype != '\n' || error){ printf("syntax error\n"); error = 0; continue; } printf("%s: %s %s\n", name, out, datatype); } return 0; }
void dirdcl(void) { int i = 0, type; if (tokentype == '(') { dcl(); if (tokentype != ')') printf("error: missing )\n"); } else if (tokentype == NAME) strcpy(name, token); else printf("error: expected name or (dcl)\n"); while ((type = gettoken()) == ARGUMENTS || type == PARENS || type == BRACKETS) { if (type == ARGUMENTS) { strcat(out, " function accepting "); strcat(out, token); strcat(out, " and returning"); } else if (type == PARENS) strcat(out, " function returning"); else { strcat(out, " array"); strcat(out, token); strcat(out, " of"); } } }
void dirdcl(void) { int type; if (tokentype == '(') { /* (dcl) */ dcl(); if (tokentype != ')') { errmsg("error: missing )\n"); } } else if (tokentype == NAME) { /* variable name */ strncpy(name, token, MAXTOKEN); } else { errmsg("error: expected name of (dcl)\n"); } while ((type = gettoken()) == PARENS || type == BRACKETS) { if (type == PARENS) { strncat(out, " function returning", MAXTOKEN - strlen(out) - 1); } else { strncat(out, " array", MAXTOKEN - strlen(out) - 1); strncat(out, token, MAXTOKEN - strlen(out) - 1); strncat(out, " of", MAXTOKEN - strlen(out)); } } }
int main_dcl(void) { try { const int MAX_INPUT_SIZ = 256; char input[MAX_INPUT_SIZ]; while (true) { // 입력을 받고 버퍼를 초기화한다 std::cin.getline(input, MAX_INPUT_SIZ); if (input[0] == ';') { break; } StringBuffer buffer(input); // 형식을 획득한다 std::string type = get_type(buffer); while (is_space(buffer.peekc())) { // 형식과 선언자 사이의 공백을 buffer.getc(); // 무시하고 포인터를 선언자 앞으로 옮긴다 } // 선언자를 분석한다 dcl(buffer); if (buffer.peekc() != ';') // 문장 종료 기호가 없으면 예외 throw Exception("문장 종료 기호가 없습니다."); std::cout << type.c_str() << std::endl; } return 0; } catch (Exception &ex) { std::cerr << ex.c_str() << std::endl; return 1; } }
void print_sol() { int i = 0; for ( i = 0; i < tab_no; i++) printf("\t"); printf("%s: %s %s\n", name, out, datatype); if (param_no) { tab_no++; for ( i = 0; i < tab_no - 1; i++) printf("\t"); printf("with the following param:\n"); } param_no = 0; out[0] = '\0'; name[0] = '\0'; datatype[0] = '\0'; gettoken(); strcpy(datatype, token); dcl(); }
/* dirdcl: parse a direct declarator */ int dirdcl(void) { int type; if (tokentype == '(') { /* ( dcl ) */ dcl(); if (tokentype != ')') { printf("error: missing )\n"); return 0; } } else if (tokentype == NAME) /* variable name */ strcpy(name, token); else { printf("error: expected name or (dcl)\n"); return 0; } while ((type=gettoken()) == PARENS || type == BRACKETS) if (type == PARENS) strcat(out, " function returning"); else { strcat(out, " array"); strcat(out, token); strcat(out, " of"); } return 1; }
int dirdcl(void) { int type; if (tokentype == '(') { if (dcl()) { if (tokentype != ')') { printf("syntax error: expected ) got %s\n", describe_tokentype(tokentype)); return 0; } } else { return 0; } } else if (tokentype == NAME) strcpy(name, token); else { printf("syntax error: expected name or declaration got %s\n", describe_tokentype(tokentype)); return 0; } while ( (type=gettoken()) == PARENS || type == BRACKETS) if (type == PARENS) strcat(out, " function returning"); else { strcat(out, " array"); strcat(out, token); strcat(out, " of"); } if (type == -1) { return 0; } return 1; }
main() /* convert declarations to words */ { for (;;) { datatype[0] = '\0'; while (gettoken() == SPECIFIER || tokentype == QUALIFIER) { strcat(datatype, " "); strcat(datatype, token); } if (tokentype == EOF) break; if (tokentype == '\n') continue; /* skip blank lines */ name[0] = '\0'; out[0] = '\0'; if (dcl() == 0) { /* parse rest of line */ printf("%s: %s%s\n", name, out, datatype); } else { printf("%s: %s%s\n", name, out, datatype); printf("syntax error\n"); if (tokentype != '\n') next_line(); } } return 0; }
/* dirdcl: parse a direct declarator */ void dirdcl(void) { int type; void parmdcl(void); if(tokentype=='('){ dcl(); if(tokentype!=')') errmsg("error:missing )\n"); } else if(tokentype==NAME) /* variable name */ strcpy(name,token); else prevtoken = YES; while((type=gettoken())==PARENS||type==BRACKETS || type == '(') { if(type==PARENS) strcat(out,"function returning"); else if(type=='(') { strcat(out,"function expecting"); parmdcl(); strcat(out,"and returning"); } else{ strcat(out," array"); strcat(out,token); strcat(out," of"); } } }
void dirdcl(void){ int type; if (tokentype == '('){ dcl(); if (tokentype != ')') printf("Error: missing )\n"); } else if (tokentype == NAME){ strcpy(name, token); nameset = 1; } while ( (type = gettoken()) == PARENS || type == BRACKETS ){ if (type == PARENS){ strcat(out, " function"); strcat(out, token); strcat(out, " returning"); } else{ strcat(out, " array"); strcat(out, token); strcat(out, " of"); int temp[3]; } } // only a closing bracket ) or EOL should follow either PARENS or BRACKETS if (type != '\n' && type != ')'){ printf("Error: syntax error\n"); error = 1; } }
void dclspec(void) { char temp[MAXTOKEN]; temp[0]='\0'; gettoken(); do{ if(tokentype!=NAME) { prevtoken = YES; dcl(); } else if(typespec()==YES) { strcat(temp," "); strcat(temp,token); gettoken(); }else if(typequal()==YES) { strcat(temp," "); strcat(temp,token); gettoken(); } else errmsg("unknown type in parameter list \n"); }while(tokentype!=',' && tokentype!=')'); strcat(out,temp); if(tokentype==',') strcat(out,","); }
/* dirdcl: parse a direct declarator */ void dirdcl(void) { int type; if (tokentype == '(') { dcl(); if (tokentype != ')') { printf("\terror: missing )\n"); while (gettoken() != '\n') ; return ; } } else if (tokentype == NAME) strcpy(name, token); else { printf("\terror: expected name of (dcl)\n"); while (gettoken() != '\n') ; return ; } while ((type = gettoken()) == PARENS || type == BRACKETS) if (type == PARENS) { strcat(out, " function returning"); } else { strcat(out, " array"); strcat(out, token); strcat(out, " of"); } }
void dirdcl(void) { int type; if(tokentype == '(') { dcl(); if(tokentype != ')') errmsg("error: missing )\n"); } else if(tokentype == NAME){ if(name[0] == '\0') strcpy(name, token); } else //errmsg ( "error: expected name or ( dcl ) \n" ) ; prevtok = YES; while((type=gettoken()) == PARENS || type == BRACKETS || type == '(') if(type == PARENS) strcat(out, " function returning"); /* else if(type == '(') { strcat(out," function expecting"); parmdcl(); strcat(out," and returning"); }*/ else { strcat(out, " array"); strcat(out, token); strcat(out, " of"); } }
void decl(void) { char decl_type[MAXTOKEN]; decl_type[0] = '\0'; gettoken(); type(decl_type); dcl(); pprintf("%s\n", decl_type); }
void object::test <1>() { TiXmlDocument doc; TiXmlDeclaration dcl("1.0", std::string(), "no"); doc.InsertEndChild(dcl); std::ostringstream os; os<<doc; tut::ensure_equals(os.str(), std::string("<?xml version=\"1.0\" standalone=\"no\" ?>")); }
int main() { while(gettoken() != EOF) { strcpy(datatype, token); out[0] = '\0'; dcl(); if(tokentype != '\n') printf("syntax error!\n"); printf("%s: %s %s\n", name, out, datatype); } return 0; }
/* convert declaration to words */ int main(int argc, char const* argv[]) { while (gettoken() != EOF) { /* 1st token on line */ strcpy(datatype, token); /* is the datatype */ out[0] = '\0'; dcl(); /* parse rest of line */ if (tokentype != '\n') printf("syntax error\n"); printf("%s: %s %s\n", name, out, datatype); } return 0; }
main() /* convert declaration to words */ { while (gettoken() != EOF) { /* 1st token on line */ strcpy(datatype, token); /* is the datatype */ out[0] = '\0'; dcl(); /* parse rest of line */ if (tokentype != '\n') printf("syntax error\n"); printf("%s: %s %s\n", name, out, datatype); } return 0; }
/* convierte una declaracion a palabras */ int main(){ while( gettoken() != EOF ){ /* 1er. token en la linea */ strcpy( datatype, token ); /* es el tipo de dato */ out[ 0 ] = '\0'; dcl(); /* reconoce el resto de la linea */ if( tokentype != '\n' ) printf( "error de sintaxis\n" ); printf( "%s: %s %s\n", name, out, datatype ); } return 0; }
/* The difference between * int *f(); // f: function returning pointer to int * and * int (*pf)(); // pf: pointer to function returning int * illustrates the problem: * is a prefix operator and it has lower * precedence than (), so parentheses are necessary to force the proper * association. */ int main(void) /* convert declarator to words */ { while (gettoken() != EOF) { /* 1st token on line */ /* 第一次读取到的"token"应该是数据类型,保存到datatype[]数组中 */ strcpy(datatype, token); /* is the datatype */ out[0] = '\0'; dcl(); /* parse rest of line */ if (tokentype != '\n') printf("syntax error\n"); printf("\t%s: %s %s\n", name, out, datatype); } return 0; }
int main(int argc, char *argv[]) { while (gettoken() != EOF) { strcpy(datatype, token); out[0] = '\0'; if (!dcl()) return -1; if (tokentype != '\n') printf("syntax error\n"); printf("%s: %s %s\n", name, out, datatype); } return 0; }
int main(void) { while (gettoken() != EOF) { strcpy(datatype, token); out[0] = '\0'; dcl(); if (tokentype != '\n') { printf("syntax error\n"); } printf("%s: %s %s\n", name, out, datatype); } }
static node_t *make_decl(struct token *id, node_t * ty, int sclass, int fspec, declfun_p * dcl) { node_t *decl; if (sclass == TYPEDEF) decl = ast_decl(TYPEDEF_DECL); else if (isfunc(ty)) decl = ast_decl(FUNC_DECL); else decl = ast_decl(VAR_DECL); node_t *sym = dcl(id, ty, sclass, fspec); DECL_SYM(decl) = sym; return decl; }
int main(void) /* convert declaration to words */ { while (gettoken() != EOF) { /* 1st token on line */ strcpy(datatype, token); /*is the datatype*/ out[0] = '\0'; dcl(); /* parse rest of line */ if (tokentype == ']') { printf("syntax error, missing ]\n"); //while ((c = getchar()) != EOF && c != '\n') // ; } printf("%s: %s %s\n", name, out, datatype); } return 0; }
bool simplify(goal_ref const& g, pb_preproc_model_converter& mc) { reset(); normalize(g); if (g->inconsistent()) { return false; } for (unsigned i = 0; i < g->size(); ++i) { process_vars(i, g); } if (m_ge.empty()) { return false; } for (unsigned i = 0; i < m_ge.size(); ++i) { classify_vars(i, to_app(g->form(m_ge[i]))); } declassifier dcl(m_vars); expr_mark visited; for (unsigned i = 0; !m_vars.empty() && i < m_other.size(); ++i) { for_each_expr(dcl, visited, g->form(m_other[i])); } if (m_vars.empty()) { return false; } // display_annotation(tout, g); m_progress = false; // first eliminate variables var_map::iterator it = next_resolvent(m_vars.begin()); while (it != m_vars.end()) { app * e = it->m_key; rec const& r = it->m_value; TRACE("pb", tout << mk_pp(e, m) << " " << r.pos.size() << " " << r.neg.size() << "\n";); if (r.pos.empty()) { replace(r.neg, e, m.mk_false(), g); mc.set_value(e, false); } else if (r.neg.empty()) { replace(r.pos, e, m.mk_true(), g); mc.set_value(e, true); } if (g->inconsistent()) return false; ++it; it = next_resolvent(it); }
void dirdcl(StringBuffer &bin, StringList &vout) { // 직접 선언자를 분석하고 결과 출력 char ch = bin.peekc(); if (is_fnamch(ch)) { // direct-declarator: 이름 (2) std::string identifier = ""; while (bin.is_empty() == false) { ch = bin.getc(); if (is_namch(ch) == false) { bin.ungetc(); break; } identifier += ch; } if (identifier.empty()) // 식별자에 추가된 문자가 없다면 예외 throw Exception("올바른 식별자 이름이 아닙니다."); vout.push_back(identifier); } else if (ch == '(') { // direct-declarator: (declarator) (3) bin.getc(); // ( 문자를 해석해서 진입했으므로 다음으로 넘긴다 dcl(bin, vout); if (bin.peekc() != ')') // 닫는 괄호가 없으면 예외 throw Exception("닫는 괄호가 없습니다."); bin.getc(); // ) 괄호 검사를 진행했으므로 다음으로 넘긴다 } // direct-declarator: direct-declarator() (4) // direct-declarator: direct-declarator[] (5) while (bin.is_empty() == false) { ch = bin.peekc(); if (ch == '(') { // 함수 기호 획득 bin.getc(); // ( 괄호를 해석해서 진입했으므로 넘긴다 if (bin.peekc() != ')') // 닫는 괄호가 없으면 예외 throw Exception("잘못된 함수 기호입니다."); bin.getc(); // ) 괄호를 해석했으므로 다음으로 넘긴다 vout.push_back("()"); } else if (ch == '[') { // 배열 기호 획득 bin.getc(); // [ 괄호를 해석해서 진입했으므로 넘긴다 if (bin.peekc() != ']') // 닫는 괄호가 없으면 예외 throw Exception("잘못된 배열 기호입니다."); bin.getc(); // ] 괄호를 해석했으므로 다음으로 넘긴다 vout.push_back("[]"); } else { // 이외의 경우 반복문을 탈출한다 break; } } }