| 207 | std::vector<std::shared_ptr<Statement>> statements; |
| 208 | |
| 209 | void BuildTokens(std::string& input){ |
| 210 | int lineNum = 1; |
| 211 | int linePos = 0; |
| 212 | |
| 213 | std::string buf; |
| 214 | for(auto it = input.begin(); it != input.end(); it++){ |
| 215 | char c = *it; |
| 216 | linePos++; |
| 217 | |
| 218 | auto appendIdentifier = [lineNum, linePos](std::string& buf) { |
| 219 | if(buf.length()){ |
| 220 | tokens.push_back(Token(lineNum, linePos, TokenIdentifier, buf)); |
| 221 | buf.clear(); |
| 222 | } |
| 223 | }; |
| 224 | |
| 225 | switch (c) |
| 226 | { |
| 227 | case ',': |
| 228 | appendIdentifier(buf); |
| 229 | tokens.push_back(Token(lineNum, linePos, TokenComma)); |
| 230 | break; |
| 231 | case ')': |
| 232 | appendIdentifier(buf); |
| 233 | tokens.push_back(Token(lineNum, linePos, TokenRightParens)); |
| 234 | break; |
| 235 | case '(': |
| 236 | appendIdentifier(buf); |
| 237 | tokens.push_back(Token(lineNum, linePos, TokenLeftParens)); |
| 238 | break; |
| 239 | case '}': |
| 240 | appendIdentifier(buf); |
| 241 | tokens.push_back(Token(lineNum, linePos, TokenRightBrace)); |
| 242 | break; |
| 243 | case '{': |
| 244 | appendIdentifier(buf); |
| 245 | tokens.push_back(Token(lineNum, linePos, TokenLeftBrace)); |
| 246 | break; |
| 247 | case '\n': |
| 248 | appendIdentifier(buf); |
| 249 | tokens.push_back(Token(lineNum, linePos, TokenEndline)); |
| 250 | lineNum++; |
| 251 | linePos = 0; |
| 252 | break; |
| 253 | case '-': |
| 254 | appendIdentifier(buf); |
| 255 | |
| 256 | if(*(it + 1) == '>'){ // Response token is '->' so look ahead by one character |
| 257 | tokens.push_back(Token(lineNum, linePos, TokenResponse)); |
| 258 | it++; |
| 259 | } else { |
| 260 | printf("error: [line %d:%d] Unsupported character '%c'\n", lineNum, linePos, c); |
| 261 | exit(2); |
| 262 | } |
| 263 | break; |
| 264 | case ' ': // Eat whitespaces |
| 265 | appendIdentifier(buf); |
| 266 | break; |