Value* Procedure::addBoolConstant(TriState triState) { int32_t value = 0; switch (triState) { case FalseTriState: value = 0; break; case TrueTriState: value = 1; break; case MixedTriState: return nullptr; } return addIntConstant(Int32, value); }
Token Lexer::getNext() { try { } catch(int i) { } skipWhitespacesAndComments(); AutoCounter ac(currentPos, currentPos, currentColumn); if(inputLeft()) { if(isdigit(input[currentPos])) { std::stringstream buffer; buffer << input[currentPos]; currentPos++; while(inputLeft() && isdigit(input[currentPos])) { buffer << input[currentPos]; currentPos++; } if(inputLeft() && input[currentPos] == '.') { currentPos++; buffer << '.'; while(inputLeft() && isdigit(input[currentPos])) { buffer << input[currentPos]; currentPos++; } auto element = std::stod(buffer.str(), nullptr); auto index = addRealConstant(element); return Token(TokenType::REAL, index, currentColumn, currentLine); } else { auto element = std::stoi(buffer.str(), nullptr); auto index = addIntConstant(element); return Token(TokenType::INT, index, currentColumn, currentLine); // INT } } else if(isalpha(input[currentPos]) || input[currentPos] == '_') { std::stringstream buffer; buffer << input[currentPos]; currentPos++; while(inputLeft() && (isalnum(input[currentPos]) || input[currentPos] == '_')) { buffer << input[currentPos]; currentPos++; } auto identifierValue = buffer.str(); if(identifierValue == "true") { return Token(TokenType::BOOL, 1, currentColumn, currentLine); } else if(identifierValue == "false") { return Token(TokenType::BOOL, 0, currentColumn, currentLine); } else if(identifierValue == "return") { return Token(TokenType::RETURN, currentColumn, currentLine); } else if(identifierValue == "if") { return Token(TokenType::IF, currentColumn, currentLine); } else if(identifierValue == "else") { return Token(TokenType::ELSE, currentColumn, currentLine); } else if(identifierValue == "loop") { return Token(TokenType::LOOP, currentColumn, currentLine); } int index = identifier.size(); identifier.push_back(buffer.str()); return Token(TokenType::IDENTIFIER, index, currentColumn, currentLine); } else { switch(input[currentPos]) { case '+': currentPos++; return Token(TokenType::OPERATOR, 0, currentColumn, currentLine); case '-': currentPos++; return Token(TokenType::OPERATOR, 1, currentColumn, currentLine); case '*': currentPos++; return Token(TokenType::OPERATOR, 2, currentColumn, currentLine); case '/': currentPos++; return Token(TokenType::OPERATOR, 3, currentColumn, currentLine); case '<': currentPos++; if(inputLeft() && input[currentPos] == '=') { currentPos++; return Token(TokenType::OPERATOR, 5, currentColumn, currentLine); } return Token(TokenType::OPERATOR, 4, currentColumn, currentLine); case '>': currentPos++; if(inputLeft() && input[currentPos] == '=') { currentPos++; return Token(TokenType::OPERATOR, 7, currentColumn, currentLine); } return Token(TokenType::OPERATOR, 6, currentColumn, currentLine); case '(': currentPos++; return Token(TokenType::LPAR, 0, currentColumn, currentLine); case ')': currentPos++; return Token(TokenType::RPAR, 0, currentColumn, currentLine); case '{': currentPos++; return Token(TokenType::LBLOCK, 0, currentColumn, currentLine); case '}': currentPos++; return Token(TokenType::RBLOCK, 1, currentColumn, currentLine); case '=': currentPos++; if(inputLeft() && input[currentPos] == '=') { currentPos++; return Token(TokenType::OPERATOR, 8, currentColumn, currentLine); } else if( inputLeft() && input[currentPos] == '>') { currentPos++; return Token(TokenType::OPERATOR, 12, currentColumn, currentLine); } return Token(TokenType::ASSIGN, currentColumn, currentLine); case '!': currentPos++; if(inputLeft() && input[currentPos] == '=') { currentPos++; return Token(TokenType::OPERATOR, 9, currentColumn, currentLine); } return Token(TokenType::UNARYOPERATOR, 0, currentColumn, currentLine); case '&': currentPos++; if(inputLeft() && input[currentPos] == '&') { currentPos++; return Token(TokenType::OPERATOR, 10, currentColumn, currentLine); } return Token(TokenType::ERROR, currentColumn, currentLine); case '|': currentPos++; if(inputLeft() && input[currentPos] == '|') { currentPos++; return Token(TokenType::OPERATOR, 11, currentColumn, currentLine); } return Token(TokenType::ERROR, currentColumn, currentLine); case '%': currentPos++; return Token(TokenType::OPERATOR, 13, currentColumn, currentLine); case ';': currentPos++; return Token(TokenType::SEMICOLON, currentColumn, currentLine); case ',': currentPos++; return Token(TokenType::SEPARATOR, currentColumn, currentLine); case ':': currentPos++; if(inputLeft() && input[currentPos] == '=') { currentPos++; return Token(TokenType::DEFINE, currentColumn, currentLine); } return Token(TokenType::ERROR, currentColumn, currentLine); default: break; } } } else { return Token(TokenType::EOI, currentColumn, currentLine); } currentPos++; return Token(TokenType::ERROR, currentColumn, currentLine); }
Value* Procedure::addIntConstant(Value* likeValue, int64_t value) { return addIntConstant(likeValue->origin(), likeValue->type(), value); }
Value* Procedure::addBottom(Origin origin, Type type) { return addIntConstant(origin, type, 0); }