std::string TreeBuilder::formulateError() const { std::string error("On line "); error += std::to_string(getLine()) + ", column " + std::to_string(getColumn()) + std::string("\nExpected\n`") + getExpectedTokensGrammar() + "'\nBut got `" + getCurrentLexeme() + "'"; return error; }
bool includeSourceFile(char *fileAddress, int mainSourceFileLineIndex) { LinkedListNode *currentNode = includeDataList.head; for(int i = 0; i < includeDataList.nodeCount; ++i) { IncludeData *includeData = (IncludeData *)currentNode->data; if(_stricmp(includeData->fileAddress, getCurrentLexeme()) == 0) { Debug::outputLogEvent((char *)("Warning : Duplicate file inclusion : \"" + (string)getCurrentLexeme() + "\"; include skipped").c_str()); return 1; } currentNode = currentNode->next; if(!currentNode) { break; } } IncludeData *includeData = new IncludeData(); includeData->fileAddress = new char[strlen(fileAddress) + 1]; strcpy(includeData->fileAddress, fileAddress); FILE *file; if(!(file = fopen(fileAddress, "r"))) { throwError("Could not open source file " + (string)fileAddress); return 0; } fseek(file, 0, SEEK_END); int fileSize = ftell(file); if(fileSize) { sourceCodeStreamSize += fileSize; fseek(file, 0, SEEK_SET); while(!feof(file)) { char *currentLine = new char[ES_MAX_SOURCE_LINE_LENGTH + 1]; fgets(currentLine, ES_MAX_SOURCE_LINE_LENGTH, file); includeData->sourceCode.addNode(currentLine); } fclose(file); if(includeData->sourceCode.nodeCount > 0) { sourceCode.insertLinkedListAfterIndex(&includeData->sourceCode, mainSourceFileLineIndex); } preprocessSourceFile(); } includeDataList.addNode(includeData); currentLexerState.currentLexemeStart = 0; currentLexerState.currentLexemeEnd = 0; currentLexerState.currentLineNode = sourceCode.head; currentLexerState.currentLineIndex = 0; currentLexerState.operatorIndex = 0; currentLexerState.lexerState = ES_LEXER_STATE_START; currentLexerState.currentToken = 0; copyLexerState(&previousLexerState, currentLexerState); return 1; }