aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-09-26 22:55:05 +0200
committerAdrian Kummerlaender2014-09-26 22:55:05 +0200
commit1479b2ab1ae2e5a82ab6ac79663939ae651000fd (patch)
treedf44330796c7567961908e25057353306529d549 /src
parenta0b3e97d555ee504636c06fd3a72983b95c3bfb6 (diff)
downloadSimpleParser-1479b2ab1ae2e5a82ab6ac79663939ae651000fd.tar
SimpleParser-1479b2ab1ae2e5a82ab6ac79663939ae651000fd.tar.gz
SimpleParser-1479b2ab1ae2e5a82ab6ac79663939ae651000fd.tar.bz2
SimpleParser-1479b2ab1ae2e5a82ab6ac79663939ae651000fd.tar.lz
SimpleParser-1479b2ab1ae2e5a82ab6ac79663939ae651000fd.tar.xz
SimpleParser-1479b2ab1ae2e5a82ab6ac79663939ae651000fd.tar.zst
SimpleParser-1479b2ab1ae2e5a82ab6ac79663939ae651000fd.zip
Replaced array-like accesses with their named member method counterparts
Diffstat (limited to 'src')
-rw-r--r--src/tree.cc8
-rw-r--r--src/utils.cc8
-rw-r--r--src/utils.h5
3 files changed, 13 insertions, 8 deletions
diff --git a/src/tree.cc b/src/tree.cc
index 11bb299..900d891 100644
--- a/src/tree.cc
+++ b/src/tree.cc
@@ -117,7 +117,7 @@ Node* Tree::buildTree(const std::string& term) {
elementIterator != topElements.end();
++elementIterator ) {
const std::string& element = *elementIterator;
- const TokenType elementToken = determineToken(element[0]);
+ const TokenType elementToken = determineToken(element.front());
if ( elementToken != TokenType::VALUE_NUMBER &&
elementToken != TokenType::VALUE_IDENTIFIER &&
@@ -151,18 +151,18 @@ Node* Tree::buildTree(const std::string& term) {
};
if ( subElements.size() == 1 ) {
- switch ( determineToken(subElements[0][0]) ) {
+ switch ( determineToken(subElements.front()) ) {
case TokenType::VALUE_NUMBER:
case TokenType::OPERATOR_MINUS: {
operands.push(this->addNode<OperandNode>(
- doubleToString(subElements[0])
+ doubleToString(subElements.front())
));
break;
}
case TokenType::VALUE_IDENTIFIER: {
operands.push(this->addNode<ConstantNode>(
- subElements[0],
+ subElements.front(),
this->constants_
));
diff --git a/src/utils.cc b/src/utils.cc
index 752b774..832b701 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -34,6 +34,10 @@ TokenType determineToken(const char tmp) {
}
}
+TokenType determineToken(const std::string& tmp) {
+ return determineToken(tmp.front());
+}
+
PrecedenceLevel precedence(const TokenType token) {
switch ( token ) {
case TokenType::VALUE_NUMBER:
@@ -61,7 +65,7 @@ PrecedenceLevel precedence(const TokenType token) {
}
}
-std::vector<std::string> lexer(std::string term) {
+std::vector<std::string> lexer(const std::string& term) {
std::vector<std::string> resultBuffer;
std::string levelBuffer;
@@ -185,7 +189,7 @@ std::vector<std::string> lexer(std::string term) {
if ( previousToken == TokenType::PARENTHESES_CLOSE &&
resultBuffer.size() == 1 ) {
- resultBuffer = lexer(resultBuffer[0]);
+ resultBuffer = lexer(resultBuffer.front());
}
return resultBuffer;
diff --git a/src/utils.h b/src/utils.h
index ca2c77f..63ccf55 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -28,9 +28,10 @@ enum class TokenType {
VALUE_IDENTIFIER,
};
-TokenType determineToken(char);
+TokenType determineToken(const char);
+TokenType determineToken(const std::string&);
PrecedenceLevel precedence(TokenType);
-std::vector<std::string> lexer(std::string);
+std::vector<std::string> lexer(const std::string&);
double doubleToString(const std::string&);