static int get_token(const char* string, int startIndex, const char* separators, int* output_index, int* token_start, int* token_length) { int past_token; int sep_pos; *token_start = ModelicaStrings_skipWhiteSpace(string, startIndex); /* Index of first char of token, after ws. */ past_token = SkipNonWhiteSpaceSeparator(string, *token_start, separators); /* Index of first char after token, ws or separator. */ sep_pos = ModelicaStrings_skipWhiteSpace(string, past_token); /* Index of first char after ws after token, maybe a separator. */ *output_index = InSet(string, sep_pos, separators) ? sep_pos + 1 : sep_pos; /* Skip any separator. */ *token_length = past_token-*token_start; if (*token_length == 0 || *token_length > MAX_TOKEN_SIZE) { /* Token missing or too long. */ *output_index = startIndex; return 0; /* error */ } return 1; /* ok */ }
/** * @function BuildManifold */ void HP2D::BuildManifold( Vertice _v0 ) { Vertice* va; Vertice vt; Vertice* vb; std::vector<Vertice> S; std::vector<Vertice*> B; InsertQueue( _v0 ); do{ va = PopQueue(); S = Successors( va ); for( int i = 0; i < S.size(); i++ ) { vt = S[i]; InsertVertice( vt ); InsertEdge( &vt, va ); if( vt.GetDist() < mDIST_MAX ) { InsertQueue( vt ); } B = GetAdjacent( va->Adjacent() ); for( unsigned j = 0; j < B.size(); j++ ) { vb = B[j]; if( InSet( vb->GetPos(), vt.Neighbors() ) ) { InsertEdge( &vt, vb ); } } } } while( GetSizeQueue() > 0 ); }
static int SkipNonWhiteSpaceSeparator(const char* string, int i, const char* separators) /* Return index in string of first character which is ws or character in separators, or position of terminating nul. */ { while (string[i-1] != '\0' && (isspace(string[i-1]) || InSet(string, i, separators))) ++i; return i; }
/** * @function Successors */ std::vector<Vertice> HP2D::Successors( Vertice *_va ) { std::vector<Vertice> S; std::vector<Eigen::Vector2i> N; Eigen::Vector2i pi; N = _va->Neighbors(); for( unsigned int i = 0; i < N.size(); i++ ) { pi = N[i]; if( IsFreeGrid( pi ) == true && InSet( pi, Vert2Pos( _va->Adjacent() ) ) == false ) { Vertice vi( pi, _va->GetDist() + 1 ); S.push_back( vi ); } } return S; }
PUBLIC void SyntaxError2( SET Expected, TOKEN CurrentToken ) { char s[2*M_LINE_WIDTH+2]; int i, j, pos, w; sprintf( s, "Syntax: Expected one of: " ); pos = 25; w = (int)(2*M_LINE_WIDTH - strlen( Tokens[CurrentToken.code] - 8 )); for ( i = 0; i < SET_SIZE; i++ ) { if ( InSet( &Expected, i ) ) { j = (int)(strlen( Tokens[i] ) + 1); if ( pos + j > w ) break; else { sprintf( s+pos, "%s ", Tokens[i] ); pos += j; } } } sprintf( s+pos, ": got %s\n", Tokens[CurrentToken.code] ); Error( s, CurrentToken.pos ); }
/** * Return pointer to next character in string in set or * return NULL pointer if no such character. */ static char *NextInSet(char *string, char *set) { /* Return NULL if given NULL */ if (string == (char *) NULL) { return (char *) NULL; } while (*string) { if (InSet(string, set)) { break; } else { string++; } } if (*string) { return string; } else { return (char *) NULL; } }
void Analyzer::Analyze( std::vector<InputLine*> &lines ) { std::vector<InputLine*>::iterator it = lines.begin(); InputLine::const_iterator line_it = (*it)->begin(); int line_number = 1; // check for main() if ((*line_it) != "main" || *(line_it+1) != "(" || *(line_it+2) != ")") { this->outputStream_ << "Line " << line_number << ": Error - " << "Program has to start with main()" << std::endl; } it++; // main loop - iterate the whole stream, line by line for ( it; it != lines.end(); it++ ) { line_it = (*it)->begin(); line_number++; // iterate a line bool prev_if = false; while (line_it != (*it)->end()) { if (InSet(*line_it, TYPES)) { std::string type = *line_it; line_it++; if (InSet(*line_it, TYPES)) { this->outputStream_ << "Line " << line_number << ": Error - " << *line_it << " after " << type << std::endl; break; } if (InSet(*line_it,RESERVD_WORDS)) { this->outputStream_ << "Line " << line_number << ": Error - Only variables can follow predefined types" << std::endl; break; } pair v = {type, *line_it}; if (Contains(v, variables)) { this->outputStream_ << "Line " << line_number << ": Error - Variable " << v.variable << "already declared" << std::endl; break; } variables.push_back(v); } else if(InSet(*line_it, PARENTHESES)) { if (!ParenthesesCheck(*line_it)) { this->outputStream_ << "Line " << line_number << ": Error - '" << *line_it << "' without '" << Match(*line_it) << "'" << std::endl; break; } } else if (*line_it == "if") { prev_if = true; } else if (*line_it == "else") { if (!prev_if) { outputStream_ << "Line " << line_number << ": Error - 'else' without 'if'" << std::endl; } } line_it++; } } PrintVariables(); }