| 682 | } |
| 683 | |
| 684 | bool ParserState::Parse() |
| 685 | { |
| 686 | ZoneScoped; |
| 687 | |
| 688 | //PreprocessorParseTrace( stdout, "parser: " ); |
| 689 | void* parser = ParseAlloc( malloc ); |
| 690 | |
| 691 | m_symbols->EnterScope(); |
| 692 | |
| 693 | ScannerToken token; |
| 694 | |
| 695 | bool done = false; |
| 696 | while( !done ) |
| 697 | { |
| 698 | PreprocessorToken ppToken; |
| 699 | PreprocessorScanResult scanCode = GetPreprocessorToken( ppToken ); |
| 700 | switch( scanCode ) |
| 701 | { |
| 702 | case PPSR_ERROR: |
| 703 | ParseFree( parser, free ); |
| 704 | return false; |
| 705 | case PPSR_EOF: { |
| 706 | if( m_fileStack.size() > 1 ) |
| 707 | { |
| 708 | m_fileStack.pop_back(); |
| 709 | } |
| 710 | else |
| 711 | { |
| 712 | done = true; |
| 713 | break; |
| 714 | } |
| 715 | } |
| 716 | break; |
| 717 | case PPSR_OK: |
| 718 | if( !ConvertToScannerToken( *this, ppToken, token ) ) |
| 719 | { |
| 720 | ShowMessage( ppToken.fileLocation, EC_SYNTAX_ERROR, ToString( ppToken.string ).c_str() ); |
| 721 | ParseFree( parser, free ); |
| 722 | return false; |
| 723 | } |
| 724 | //printf( "token: %04i %s\n", token.type, ToString( ppToken.string ).c_str() ); |
| 725 | ::Parse( parser, token.type, token, this ); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | token.type = 0; |
| 730 | ::Parse( parser, 0, token, this ); |
| 731 | ParseFree( parser, free ); |
| 732 | |
| 733 | m_symbols->LeaveScope(); |
| 734 | |
| 735 | return m_root && !m_hasErrors; |
| 736 | } |
| 737 | |
| 738 | bool ConvertToPreprocessorToken( int& type ) |
| 739 | { |
no test coverage detected