/* <stmt> --> id:=<expr>; <stmt> --> read(<idlist>); <stmt> --> write(<idlist>); <stmt> --> if(<idlist>){<stmtlist>}{else(<idlist>){<stmtlist>}}; <stmt> --> while(<idlist>){<stmtlist>}; */ void statement() { if(next_token == ID) { match(ID); match(ASSIGNOP); expression(); match(SEMICOLON); } else if(next_token == READ) { match(READ); match(LPAREN); id_list(); match(RPAREN); match(SEMICOLON); } else if(next_token == WRITE) { match(WRITE); match(LPAREN); id_list(); match(RPAREN); match(SEMICOLON); } else if(next_token == IF) { match(IF); match(LPAREN); bool(); match(RPAREN); match(LCURL); statement_list(); match(RCURL); if(next_token == ELSE) { match(ELSE); match(LCURL); statement_list(); match(RCURL); } } else if(next_token == WHILE) { match(WHILE); match(LPAREN); bool(); match(RPAREN); match(LCURL); statement_list(); match(RCURL); } else syntax_error(); }
void statement(void) { token tok = next_token(); expr_rec source,target; switch (tok){ case ID: /*<statement> ::= ID := <expression>; */ match(ID); target = process_id(); match(ASSIGNOP); expression(& source); match(SEMICOLON); assign(target,source); break; case READ: /*<statement> ::= READ (<id list>); */ match(READ); match(LPAREN); id_list(); match(RPAREN); match(SEMICOLON); break; case WRITE: /*<statement> ::= WRITE (<expr list>); */ match(WRITE); match(LPAREN); expr_list(); match(RPAREN); match(SEMICOLON); break; default: syntax_error(tok); break; } }
struct id_listNode* id_list() { struct id_listNode* idList; idList = make_id_list(); ttype = getToken(); if (ttype == ID) { idList->id = (char*) malloc(tokenLength+1); strcpy(idList->id, token); symAdd(idList->id); ttype = getToken(); if (ttype == COMMA) { idList->id_list = id_list(); return idList; } else { ungetToken(); return idList; } } else { return NULL; } }
struct var_declNode* var_decl() { struct var_declNode* varDecl; struct id_listNode* idList; varDecl = make_var_decl(); idList = make_id_list(); int i = 0; varDecl->id_list = NULL; ttype = getToken(); if (ttype == ID) { ungetToken(); varDecl->id_list = id_list(); ttype = getToken(); if (ttype == SEMICOLON) { //printf("ttype %d\n", ttype); return varDecl; } } return varDecl; }
SimpleExpression Parser::simple_expression(){ std::string field = id(); enum Operator oper = op(); std::string value = id_list(); if (field == "" || oper == OP_BAD_OPERATOR || value == ""){ std::cout << lexer->getLinenumber() << ": Error: Broken expression '" << field << "' '" << oper << "' '" << value <<"'\n"; exit(1); } return SimpleExpression(field, oper, value); }
Pname id_list(Pnode p, int* quanti) { if (p != NULL) { Pname lista = (Pname)newmem(sizeof(Name)); lista->name = p->value.sval; (*quanti)++; lista->next = id_list(p->brother, quanti); return lista; } else return NULL; }
/*Genera il codice per il nodo def_stat e controlla i vincoli semantici*/ Code def_stat(Pnode def_stat_node){ //Imposto le due parti del nodo Pnode type_node = def_stat_node->child; Pnode id_list_head_node = def_stat_node->child->brother; //Definisco la variabile che contiene il codice da ritornare Code def_stat_code ; def_stat_code.head = NULL; def_stat_code.tail = NULL; def_stat_code.size = 0; //Sintetizzo il type Pschema schema_type = type(type_node); //Ottengo la id_list int id_list_len; Pname id_list_name = id_list(id_list_head_node,&id_list_len); //Controllo gli errori semantici //id ripetuti Boolean repetition = repeated_names(id_list_name); if (repetition == TRUE){ semerror(def_stat_node,"More than one variable with the same name"); } //variabili già assegnate Pnode id_node; for (id_node = id_list_head_node; id_node!=NULL; id_node=id_node->brother) if (name_in_environment(valname(id_node))) semerror(id_node,"Variable already defined"); //Genero il codice per la definizione delle variabili e inserisco i nomi nel contesto for (id_node = id_list_head_node; id_node!=NULL; id_node=id_node->brother){ //Genero il codice dell'id Code id_code ; int spazio_da_allocare = get_size(schema_type); if (schema_type->type == TABLE) id_code = makecode1(T_NEWTAB,spazio_da_allocare); else id_code = makecode1(T_NEWATOM,spazio_da_allocare); //Inserisco il nome nell'ambiente insert_name_into_environment(valname(id_node)); //Inserisco il nome nella symbol table Pschema schema_symbol = clone_schema(schema_type); schema_symbol->name = valname(id_node); insert(*schema_symbol); //Appendo a def_stat_code l'id_code def_stat_code = appcode(def_stat_code,id_code); } return def_stat_code; }
void CubitUtil::list_entity_ids( const char *pre_string, const DLIList<CubitEntity*> &entity_list, int width, const char *post_string, int sort, int unique, int tab, const char *sep_string, const char *post_string_none ) { DLIList <int> id_list( entity_list.size() ); for ( int i=0; i<entity_list.size(); i++ ) id_list.append( entity_list.next(i)->id() ); list_entity_ids( pre_string, id_list, width, post_string, sort, unique, tab, sep_string, post_string_none ); }
ErrorCode ReadCGNS::create_elements(char *sectionName, const Tag *file_id_tag, const EntityType &ent_type, const int& verts_per_elem, long §ion_offset, int elems_count, const std::vector<cgsize_t>& elemsConn) { ErrorCode result; // Create the element sequence; passes back a pointer to the internal storage for connectivity and the // starting entity handle EntityHandle* conn_array; EntityHandle handle = 0; result = readMeshIface->get_element_connect(elems_count, verts_per_elem, ent_type, 1, handle, conn_array);MB_CHK_SET_ERR(result, fileName << ": Trouble reading elements"); memcpy(conn_array, &elemsConn[0], elemsConn.size() * sizeof(EntityHandle)); // Notify MOAB of the new elements result = readMeshIface->update_adjacencies(handle, elems_count, verts_per_elem, conn_array); if (MB_SUCCESS != result) return result; // ////////////////////////////////// // Create sets and tags Range elements(handle, handle + elems_count - 1); // Store element IDs std::vector<int> id_list(elems_count); // Add 1 to offset id to 1-based numbering for (cgsize_t i = 0; i < elems_count; ++i) id_list[i] = i + 1 + section_offset; section_offset += elems_count; create_sets(sectionName, file_id_tag, ent_type, elements, id_list, 0); return MB_SUCCESS; }
void CubitUtil::list_ids( const char *const heading, const DLIList<CubitEntity*> &entity_list, int should_sort, int report_once, int wrap ) { if ( entity_list.size() == 0 ) { PRINT_INFO(" No %s.\n", heading ); return; } DLIList <int> id_list( entity_list.size() ); for ( int j = 0; j < entity_list.size(); j++ ) { id_list.append( entity_list[j]->id() ); } if ( id_list.size() == 1 ) { PRINT_INFO(" The 1 %s id is %d.\n", heading, id_list[0]); return; } sort_and_print_ids( heading, id_list, should_sort, report_once, wrap ); }
int statement(int count) { char buffer[200]; token * begin; begin=c; memset(buffer, 0, sizeof buffer); //ID:=<expression>; if(c->token_number == ID) { advance(); if(c->token_number == ASSIGNOP) { advance(); if(expression()) { //advance(); if(c->token_number == SEMICOLON) { advance(); while(c!=begin) { //fprintf(of_d.temp1, "Token number %d\tToken type %s\t\tActual %s\n", begin->token_number, begin->token_type, begin->buffer); sprintf(buffer+strlen(buffer),"%s",begin->buffer); begin=(token *) begin->next; } //fprintf(of_d.temp1,"\nPROGRAM LINE: %s\n\n\n",buffer); //fprintf(of_d.listing_file, "%d:\t%s\n", count, buffer); //valid statement return 1; } else { printf("Missing semicolon\n"); return 0; } } else { //keep increment pointer until after ;? printf("Invalid expression\n"); return 0; } } else { //keep increment pointer until after ;? printf("Missing assignment operator\n"); return 0; } } //READ(<id_list>); else if (c->token_number == READ) { advance(); if (c->token_number == LPAREN) { if(id_list()==1) { advance(); if (c->token_number == RPAREN) { advance(); if (c->token_number == SEMICOLON) { advance(); while(c!=begin) { //fprintf(of_d.temp1, "Token number %d\tToken type %s\t\tActual %s\n", begin->token_number, begin->token_type, begin->buffer); sprintf(buffer+strlen(buffer),"%s",begin->buffer); begin=(token *) begin->next; } //fprintf(of_d.temp1,"\nPROGRAM LINE: %s\n\n\n",buffer); //valid statement return 1; } else { printf("Missing semicolon\n"); return 0; } } else { printf("Missing right parentheses\n"); return 0; } } else { printf("Expected at least one identifier\n"); return 0; } } else { printf("Expected left parentheses\n"); return 0; } } //WRITE(<expr_list>); else if (c->token_number == WRITE) { advance(); if (c->token_number == LPAREN) { advance(); if(expr_list()==1) { if (c->token_number == RPAREN) { advance(); if (c->token_number == SEMICOLON) { advance(); while(c!=begin) { //fprintf(of_d.temp1, "Token number %d\tToken type %s\t\tActual %s\n", begin->token_number, begin->token_type, begin->buffer); sprintf(buffer+strlen(buffer),"%s",begin->buffer); begin=(token *) begin->next; } //fprintf(of_d.temp1,"\nPROGRAM LINE: %s\n\n\n",buffer); //valid statement return 1; } else { printf("Missing semicolon\n"); return 0; } } } else { printf("Invalid expression in list\n"); return 0; } } else { printf("Expected left parentheses\n"); return 0; } } //else not a statement else { //printf("Not a statement\n"); return 0; } }
Code def_stat(Pnode p) { /* def_stat / / type ---> ID ---> ID */ int num_id = 0, op; Code c_temp, code_ret; Pname names; Pnode nodo_type = p->child; Pschema schema; switch (nodo_type->type) { case N_ATOMIC_TYPE: op = T_NEWATOM; break; case N_TABLE_TYPE: op = T_NEWTAB; break; default: noderror(p->child); } /* Operazioni comuni tra dati atomici e table */ // Carico la lista di ID delle variabili names = id_list(p->child->brother, &num_id); // Vincoli semantici if (repeated_names(names)) semerror(p, "Variable redeclaration"); // Controlliamo che nessuna variabile sia nell'environment Pname n; for (n = names; n != NULL; n = n->next) { if (name_in_environment(n->name)) semerror(p, "Variable redeclaration"); // Aggiungo la nuova variabile nell'environment insert_name_into_environment(n->name); } // Genero il codice per allocare ognuna delle variabili code_ret.head = NULL; for (n = names; n != NULL; n = n->next) { // Aggiungo il nome alla Symbol Table schema = type(nodo_type); schema->name = n->name; insert(schema); Value v1; v1.ival = get_size(schema); c_temp = makecode1(op, v1); code_ret = (code_ret.head == NULL ? c_temp : appcode(code_ret, c_temp)); } // Liberiamo la memoria free_name_list(names); return code_ret; }
void rename_op(){ match(UNARY_OP); match('['); id_list(); match(']'); }
void project_op(){ match(UNARY_OP); match('['); id_list(); match(']'); }
void def_stat(){ type(); id_list(); }