| 416 | } |
| 417 | |
| 418 | Expr* Parser::parsePrimaryExpr() |
| 419 | { |
| 420 | lexer->getToken(token); |
| 421 | |
| 422 | switch (token.type) |
| 423 | { |
| 424 | case Token::TYPE_BOOLEAN_LITERAL: |
| 425 | return new BooleanLiteralExpr(token.text == "true"); |
| 426 | |
| 427 | case Token::TYPE_INT_LITERAL: |
| 428 | { |
| 429 | const char* p = token.text.c_str(); |
| 430 | size_t len = strlen(p); |
| 431 | int base = len > 2 && tolower(p[1]) == 'x' ? 16 : 10; |
| 432 | long long val = strtoll(p, NULL, base); |
| 433 | |
| 434 | return new IntLiteralExpr((int) val, base == 16); |
| 435 | } |
| 436 | |
| 437 | case Token::TYPE_IDENTIFIER: |
| 438 | { |
| 439 | string text = token.text; |
| 440 | |
| 441 | if (lexer->getToken(token).type == Token::TYPE_DOUBLE_COLON) |
| 442 | { |
| 443 | getToken(token, Token::TYPE_IDENTIFIER); |
| 444 | map<string, BaseType*>::iterator it = typesByName.find(text); |
| 445 | |
| 446 | if (it == typesByName.end() || it->second->type != BaseType::TYPE_INTERFACE) |
| 447 | error(token, string("Interface '") + text + "' not found."); |
| 448 | |
| 449 | return new ConstantExpr(static_cast<Interface*>(it->second), token.text); |
| 450 | } |
| 451 | else |
| 452 | { |
| 453 | lexer->pushToken(token); |
| 454 | return new ConstantExpr(interface, text); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | case Token::TYPE_DOUBLE_COLON: |
| 459 | getToken(token, Token::TYPE_IDENTIFIER); |
| 460 | return new ConstantExpr(nullptr, token.text); |
| 461 | |
| 462 | default: |
| 463 | syntaxError(token); |
| 464 | return NULL; // warning |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | void Parser::checkType(TypeRef& typeRef) |
| 469 | { |