summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lexer.cpp5
-rw-r--r--src/parser.cpp14
-rw-r--r--src/token.cpp1
-rw-r--r--src/token.h1
4 files changed, 21 insertions, 0 deletions
diff --git a/src/lexer.cpp b/src/lexer.cpp
index 46686c8..2521b40 100644
--- a/src/lexer.cpp
+++ b/src/lexer.cpp
@@ -70,6 +70,7 @@ Token Lexer::nextToken()
70 sBuf[iBufPos] != ' ' && sBuf[iBufPos] != '\t' && 70 sBuf[iBufPos] != ' ' && sBuf[iBufPos] != '\t' &&
71 sBuf[iBufPos] != '+' && sBuf[iBufPos] != '-' && 71 sBuf[iBufPos] != '+' && sBuf[iBufPos] != '-' &&
72 sBuf[iBufPos] != '*' && sBuf[iBufPos] != '/' && 72 sBuf[iBufPos] != '*' && sBuf[iBufPos] != '/' &&
73 sBuf[iBufPos] != '%' &&
73 sBuf[iBufPos] != '(' && sBuf[iBufPos] != ')'; 74 sBuf[iBufPos] != '(' && sBuf[iBufPos] != ')';
74 iBufPos++ ) 75 iBufPos++ )
75 { 76 {
@@ -99,6 +100,10 @@ Token Lexer::nextToken()
99 iBufPos++; 100 iBufPos++;
100 return Token( Token::tDivide ); 101 return Token( Token::tDivide );
101 102
103 case '%':
104 iBufPos++;
105 return Token( Token::tModulus );
106
102 case '(': 107 case '(':
103 iBufPos++; 108 iBufPos++;
104 return Token( Token::tOpenParen ); 109 return Token( Token::tOpenParen );
diff --git a/src/parser.cpp b/src/parser.cpp
index 5bb0aa6..df9e869 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -239,6 +239,18 @@ void Parser::unwind()
239 ); 239 );
240 } 240 }
241 break; 241 break;
242
243 case Token::tModulus:
244 {
245 Token b = tsTerminal.peekPop();
246 Token a = tsTerminal.peekPop();
247 tsTerminal.push(
248 Token( Token::tNumber,
249 new Number( deref(a) % deref(b) )
250 )
251 );
252 }
253 break;
242 254
243 case Token::tOpenParen: 255 case Token::tOpenParen:
244 tsNonTerminal.push( t ); 256 tsNonTerminal.push( t );
@@ -296,6 +308,7 @@ int Parser::reqTokens( Token::Type eType )
296 case Token::tMinus: 308 case Token::tMinus:
297 case Token::tDivide: 309 case Token::tDivide:
298 case Token::tMultiply: 310 case Token::tMultiply:
311 case Token::tModulus:
299 case Token::tEquals: 312 case Token::tEquals:
300 return 2; 313 return 2;
301 314
@@ -326,6 +339,7 @@ int Parser::getPriority( Token::Type eType )
326 339
327 case Token::tDivide: 340 case Token::tDivide:
328 case Token::tMultiply: 341 case Token::tMultiply:
342 case Token::tModulus:
329 return 2; 343 return 2;
330 344
331 case Token::tOpenParen: 345 case Token::tOpenParen:
diff --git a/src/token.cpp b/src/token.cpp
index 019e54d..5b0e6fe 100644
--- a/src/token.cpp
+++ b/src/token.cpp
@@ -59,6 +59,7 @@ Bu::Formatter &operator<<( Bu::Formatter &f, Token::Type eType )
59 case Token::tMinus: return f << "-"; 59 case Token::tMinus: return f << "-";
60 case Token::tDivide: return f << "/"; 60 case Token::tDivide: return f << "/";
61 case Token::tMultiply: return f << "*"; 61 case Token::tMultiply: return f << "*";
62 case Token::tModulus: return f << "%";
62 case Token::tOpenParen: return f << "("; 63 case Token::tOpenParen: return f << "(";
63 case Token::tCloseParen: return f << ")"; 64 case Token::tCloseParen: return f << ")";
64 case Token::tEquals: return f << "="; 65 case Token::tEquals: return f << "=";
diff --git a/src/token.h b/src/token.h
index 05a610a..1cc6516 100644
--- a/src/token.h
+++ b/src/token.h
@@ -20,6 +20,7 @@ public:
20 tMinus, 20 tMinus,
21 tDivide, 21 tDivide,
22 tMultiply, 22 tMultiply,
23 tModulus,
23 tOpenParen, 24 tOpenParen,
24 tCloseParen, 25 tCloseParen,
25 tEquals, 26 tEquals,