⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.cpp

📁 Full support for extended regular expressions (those with intersection and complement); Support for
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			return result;
		}
		else
		{
			if(typeid(*input_symbol)!=typeid(TerminalError))
				report_error(cout, input_symbol);
			if(!recover_from_error())
				return NULL;
		}
	}
}

void Whale::Parser::initialize()
{
	state_stack.push_back(0);
	input_symbol=lexical_analyzer.get_token();
}

Whale::Parser::~Parser()
{
}


void Whale::Parser::report_error(std::ostream &os, const Terminal *t) const
{
	os << "Syntax error at ";
	t->print_location(os);
	os << ".\n";
}

bool Whale::Parser::recover_from_error()
{
	int stack_pos;
	int new_state=-1;
	int number_of_symbols_discarded=0;
	for(stack_pos=state_stack.size()-1; stack_pos>=0; stack_pos--)
	{
		int state=state_stack[stack_pos];
		LRAction lr_action=access_action_table(state, error_terminal_number);
		if(lr_action.is_shift())
		{
			new_state=lr_action.shift_state();
			break;
		}
		number_of_symbols_discarded++;
	}
	if(new_state==-1) return false;
	
	TerminalError *error_token=new TerminalError;
	error_token->line=input_symbol->line;
	error_token->column=input_symbol->column;
	
	for(unsigned int stack_pos_ii=stack_pos; stack_pos_ii<symbol_stack.size(); stack_pos_ii++)
		error_token->garbage.push_back(symbol_stack[stack_pos_ii]);
	error_token->error_position=error_token->garbage.size();
	
	for(int j=0; j<number_of_symbols_discarded; j++)
	{
		state_stack.pop_back();
		symbol_stack.pop_back();
	}
	
	// shifting error token.
	symbol_stack.push_back(error_token);
	state_stack.push_back(new_state);
	
	for(;;)
	{
		int state=state_stack[state_stack.size()-1];
		LRAction lr_action(access_action_table(state, input_symbol->number()));
		if(!lr_action.is_error()) return true;
		
		error_token->garbage.push_back(input_symbol);
		if(input_symbol->number()==eof_terminal_number) return false;
		input_symbol=lexical_analyzer.get_token();
	}
	
}

void Whale::Parser::print_stack(ostream &os) const
{
	for(unsigned i=0; i<state_stack.size(); i++)
	{
		os << "[" << state_stack[i] << "]";
		if(i==symbol_stack.size()) break;
		os << " " << typeid(*symbol_stack[i]).name() << " ";
	}
	os << "\n";
}

ostream &Whale::print_terminal_location(ostream &os, const Terminal *t)
{
	return os << "line " << t->line << " column " << t->column;
}

const Whale::Parser::StateData Whale::Parser::states[Whale::Parser::number_of_lr_states]={
	{ false, -1, 0, -1 },
	{ false, 45, 2, 12 },
	{ true, 69, 2, 0 },
	{ false, 82, 4, 0 },
	{ false, 107, 6, 0 },
	{ false, 147, 8, 19 },
	{ true, 68, 2, 0 },
	{ true, 67, 2, 0 },
	{ true, 66, 2, 0 },
	{ true, 65, 2, 0 },
	{ true, 64, 2, 0 },
	{ true, 1, 10, 0 },
	{ true, -40, 12, 0 },
	{ false, 185, 14, 0 },
	{ true, 29, 16, 0 },
	{ true, 30, 16, 0 },
	{ true, 31, 16, 0 },
	{ false, 225, 18, 21 },
	{ false, 225, 18, 23 },
	{ false, 225, 18, 25 },
	{ true, 23, 20, 0 },
	{ true, 24, 20, 0 },
	{ true, -46, 22, 0 },
	{ true, -47, 22, 0 },
	{ true, -48, 22, 0 },
	{ false, 256, 4, 0 },
	{ false, 274, 4, 0 },
	{ true, -55, 24, 19 },
	{ true, 70, 2, 0 },
	{ false, 299, 26, 25 },
	{ false, 331, 28, 27 },
	{ false, 147, 30, 43 },
	{ false, 350, 20, 19 },
	{ true, 28, 16, 0 },
	{ false, 390, 32, 45 },
	{ false, 225, 18, 47 },
	{ false, 225, 18, 49 },
	{ true, 16, 20, 0 },
	{ true, 17, 20, 0 },
	{ true, 12, 2, 0 },
	{ false, 225, 18, 51 },
	{ false, 430, 34, 42 },
	{ false, 473, 20, 19 },
	{ false, 513, 36, 19 },
	{ false, 551, 38, 19 },
	{ false, 589, 40, 55 },
	{ false, 147, 30, 57 },
	{ false, 225, 18, 59 },
	{ false, 299, 26, 56 },
	{ false, 331, 28, 58 },
	{ false, 299, 26, 70 },
	{ false, 331, 28, 72 },
	{ false, 626, 42, 80 },
	{ true, 73, 42, 0 },
	{ true, 71, 42, 0 },
	{ true, 4, 2, 0 },
	{ true, -102, 12, 0 },
	{ true, -103, 12, 0 },
	{ true, -104, 12, 0 },
	{ true, -105, 12, 0 },
	{ false, 638, 44, 0 },
	{ false, 682, 30, 0 },
	{ true, -111, 12, 0 },
	{ false, 677, 46, 75 },
	{ true, 87, 46, 0 },
	{ true, -114, 48, 0 },
	{ true, 85, 46, 0 },
	{ true, 52, 48, 0 },
	{ true, 19, 20, 0 },
	{ false, 703, 50, 19 },
	{ false, 743, 32, 21 },
	{ true, 50, 4, 0 },
	{ false, 783, 20, 19 },
	{ false, 823, 20, 19 },
	{ false, 863, 52, 19 },
	{ false, 895, 42, 79 },
	{ true, 83, 42, 0 },
	{ true, 75, 42, 0 },
	{ true, 76, 42, 0 },
	{ true, 77, 42, 0 },
	{ true, 78, 42, 0 },
	{ true, 79, 42, 0 },
	{ true, 80, 42, 0 },
	{ true, 81, 42, 0 },
	{ true, 21, 20, 0 },
	{ true, 22, 20, 0 },
	{ false, 894, 54, 0 },
	{ false, 886, 56, 0 },
	{ false, 589, 40, 91 },
	{ false, 589, 40, 93 },
	{ true, 43, 54, 0 },
	{ true, 44, 54, 0 },
	{ true, -134, 58, 0 },
	{ false, 925, 36, 19 },
	{ true, 6, 2, 0 },
	{ true, -136, 48, 0 },
	{ true, 8, 2, 0 },
	{ true, -137, 48, 0 },
	{ true, -55, 24, 88 },
	{ true, 10, 2, 0 },
	{ true, 72, 24, 0 },
	{ true, 53, 2, 0 },
	{ true, 54, 2, 0 },
	{ true, 55, 2, 0 },
	{ true, 56, 2, 0 },
	{ true, 58, 2, 0 },
	{ true, -139, 12, 0 },
	{ true, -140, 12, 0 },
	{ true, -141, 12, 0 },
	{ true, -142, 12, 0 },
	{ true, 63, 2, 0 },
	{ true, -67, 24, 83 },
	{ true, 86, 24, 0 },
	{ true, -144, 60, 0 },
	{ false, 963, 32, 21 },
	{ true, 48, 4, 0 },
	{ true, 49, 4, 0 },
	{ true, 3, 2, 0 },
	{ false, 430, 34, 87 },
	{ true, 11, 2, 0 },
	{ true, 82, 34, 0 },
	{ false, 589, 40, 98 },
	{ false, 589, 40, 100 },
	{ true, 25, 20, 0 },
	{ false, 147, 30, 102 },
	{ false, 147, 30, 103 },
	{ false, 147, 30, 104 },
	{ false, 147, 30, 105 },
	{ false, 147, 30, 106 },
	{ false, 147, 30, 107 },
	{ true, -155, 24, 0 },
	{ true, 41, 54, 0 },
	{ false, 992, 54, 0 },
	{ false, 147, 30, 108 },
	{ true, 27, 20, 0 },
	{ true, -158, 60, 0 },
	{ true, -159, 60, 0 },
	{ true, 74, 42, 0 },
	{ true, 59, 2, 0 },
	{ true, 60, 2, 0 },
	{ true, 61, 2, 0 },
	{ true, 62, 2, 0 },
	{ true, 88, 46, 0 },
	{ false, 299, 26, 105 },
	{ true, 47, 4, 0 },
	{ true, 84, 42, 0 },
	{ false, 997, 54, 0 },
	{ true, 40, 54, 0 },
	{ true, 32, 54, 0 },
	{ true, 33, 54, 0 },
	{ true, 34, 54, 0 },
	{ true, 35, 54, 0 },
	{ true, 36, 54, 0 },
	{ true, 37, 54, 0 },
	{ true, 38, 54, 0 },
	{ true, 42, 54, 0 },
	{ true, -161, 62, 0 },
	{ false, 299, 26, 106 },
	{ false, 299, 26, 107 },
	{ true, 5, 2, 0 },
	{ true, 26, 20, 0 },
	{ true, 7, 2, 0 },
	{ true, 9, 2, 0 }
};

const Whale::Parser::RuleData Whale::Parser::rules[Whale::Parser::number_of_rules]={
	{ 0, 1 },	{ 1, 1 },	{ 2, 4 },	{ 3, 3 },
	{ 3, 6 },	{ 3, 3 },	{ 3, 6 },	{ 3, 3 },
	{ 3, 6 },	{ 4, 3 },	{ 5, 4 },	{ 6, 2 },
	{ 7, 2 },	{ 7, 3 },	{ 7, 3 },	{ 7, 2 },
	{ 7, 2 },	{ 7, 1 },	{ 7, 3 },	{ 7, 2 },
	{ 7, 3 },	{ 7, 3 },	{ 7, 1 },	{ 7, 1 },
	{ 7, 4 },	{ 7, 6 },	{ 7, 4 },	{ 8, 1 },
	{ 8, 1 },	{ 8, 1 },	{ 8, 1 },	{ 9, 3 },
	{ 9, 3 },	{ 9, 3 },	{ 9, 3 },	{ 9, 3 },
	{ 9, 3 },	{ 9, 3 },	{ 9, 3 },	{ 9, 3 },
	{ 9, 2 },	{ 9, 3 },	{ 9, 1 },	{ 9, 1 },
	{ 10, 1 },	{ 10, 3 },	{ 10, 5 },	{ 10, 4 },
	{ 10, 4 },	{ 10, 3 },	{ 11, 1 },	{ 11, 1 },
	{ 12, 2 },	{ 12, 2 },	{ 12, 2 },	{ 12, 2 },
	{ 12, 1 },	{ 12, 2 },	{ 12, 3 },	{ 12, 3 },
	{ 12, 3 },	{ 12, 3 },	{ 12, 2 },	{ 13, 1 },
	{ 13, 1 },	{ 13, 1 },	{ 13, 1 },	{ 13, 1 },
	{ 14, 1 },	{ 14, 2 },	{ 15, 1 },	{ 16, 1 },
	{ 17, 1 },	{ 17, 3 },	{ 18, 1 },	{ 18, 1 },
	{ 18, 1 },	{ 18, 1 },	{ 18, 1 },	{ 18, 1 },
	{ 18, 1 },	{ 19, 1 },	{ 20, 1 },	{ 20, 3 },
	{ 21, 1 },	{ 22, 1 },	{ 23, 1 },	{ 23, 3 }
};


const int Whale::Parser::compressed_action_table[Whale::Parser::compressed_action_table_size]={
	-13, -14, -15, -16, -17,   0,   0,   0,   0,   0,   0,   0,
	  0,   0, -18, -19,   0, -20,   0,   0,   0, -21,   0,   0,
	-22,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-23, -24, -25,   0, -26, -27,   0,   0, -28,   2, -13, -14,
	-15, -16, -17,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-18, -19,   0, -20,   0,   0,   0, -21,   0,   0, -22,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0, -23, -24,
	-25,   0, -26, -27,   0,   0, -28, -30,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-31,  18,  18,  18,  18,   0,   0,  18,  18,   0,   0,  18,
	 18,  18,  18,  18,  18,  18,  18,  18,  18,  18,   0, -32,
	 18,  18,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	 18,  18,  18,   0,  18, -34, -15, -16, -17,   0,   0,   0,
	 45,   0,   0, -35, -36, -37, -18, -19,   0, -20,   0, -38,
	-39, -21,   0,   0, -22,  45,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0, -23, -24, -25,  28,  28,  28,  28,   0,
	-41,  28,  28, -42,  28,  28,  28,  28,  28,  28,  28,  28,
	 28,  28,  28,  28,   0,  28,  28,  28,  28,  28,  28,  28,
	 28,   0,   0,   0,   0,   0,  28,  28,  28,  28,  28, -34,
	-15, -16, -17,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-18, -19,   0, -20,   0,   0,   0, -21,   0,   0, -22,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0, -23, -24,
	-25, -49,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0, -50, -51,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-52, -57, -58, -59, -60, -61,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0, -62, -63, -67,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0, -68,  13,  13,  13,  13,   0,   0,  13,  13,
	  0,   0,  13,  13,  13,  13,  13,  13,  13,  13, -38, -39,
	 13,   0,   0,  13,  13,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,  13,  13,  13,   0,  13, -34, -15, -16, -17,
	  0,   0,   0,   0,   0,   0,   0,   0,   0, -71, -19,   0,
	-20,   0,   0,   0, -21,   0,   0, -22,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0, -23, -24, -25,   0, -72,
	-78, -79, -80, -81, -82,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0, -83, -84,  20,  20,  20,  20,   0,
	  0,  20,  20,   0,   0,  20,  20,  20,  20,  20,  20,  20,
	 20, -38, -39,  20,   0,   0,  20,  20,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,  20,  20,  20,   0,  20, -34,
	-15, -16, -17,   0,   0,   0,   0,   0,   0,   0, -36, -37,
	-18, -19, -85, -20,   0, -38, -39, -21,   0,   0, -22,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0, -23, -24,
	-25, -34, -15, -16, -17,   0,   0,   0,   0,   0,   0,   0,
	-36, -37, -18, -19,   0, -20, -86, -38, -39, -21,   0,   0,
	-22,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-23, -24, -25, -34, -15, -16, -17,   0,   0,   0,   0,   0,
	  0,   0,   0,   0, -89, -90,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0, -91, -92, -100,   0,
	  0, -101,  57,  57,  57,  57,  57,  57,   0,   0, -106,   0,
	  0,   0,   0,   0,   0,  57,  57,   0,  57,   0,   0,   0,
	 57,   0,   0,  57,   0,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,  57,  57,  57,   0,  57,  57,   0,   0,  57,
	-107, -108, -109, -110, -113,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0,  51, -34, -15, -16,
	-17,   0,   0,   0,  46,   0,   0,   0, -36, -37, -115, -19,
	  0, -20,   0, -38, -39, -21,   0,   0, -22,  46,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0, -23, -24, -25,   0,
	-116, -34, -15, -16, -17,   0,   0,   0,   0,   0,   0,   0,
	  0,   0, -18, -19,   0, -20,   0,   0,   0, -21,   0,   0,
	-22,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-23, -24, -25,   0, -117, -34, -15, -16, -17,   0,   0,  14,
	 14,   0,   0,  14,  14, -37, -18, -19,  14, -20,  14, -38,
	-39, -21,   0,   0, -22,  14,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0, -23, -24, -25,   0,  14, -34, -15, -16,
	-17,   0,   0,  15,  15,   0,   0,  15,  15,  15, -18, -19,
	 15, -20,  15, -38, -39, -21,   0,   0, -22,  15,   0,   0,
	  0,   0,   0,   0,   0,   0,   0,   0, -23, -24, -25,   0,
	 15, -34, -15, -16, -17,   0,   0, -118,   0,   0,   0,   0,
	-36, -37, -18, -19,   0, -20,   0, -38, -39, -21,   0,   0,
	-22,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	-23, -24, -25, -120,   0,   0, -121, -122, -123,   0,   0, -124,
	-125, -126, -127, -128, -129, -130,   0,   0,   0,   0,   0,   0,
	  0,   0, -131, -34, -15, -16, -17,   0,   0,   0,   0,   0,
	  0,   0, -36, -37, -18, -19, -135, -20,   0, -38, -39, -21,
	  0,   0, -22,   0,   0,   0,   0,   0,   0,   0,   0,   0,
	  0,   0, -23, -24, -25, -34, -15, -16, -17,   0,   0,   0,
	  0,   0,   0,   0,   0,   0, -18, -19,   0, -20,   0,   0,
	  0, -21,   0,   0, -22,   0,   0,   0,   0,   0,   0,   0,
	  0,   0,   0,   0, -23, -24, -25,   0, -145, -122, -123,   0,
	  0, -156,  39, -123,   0,   0,  39
};

const unsigned int Whale::Parser::compressed_action_error_map[Whale::Parser::compressed_action_error_map_size]={
	0x0245803e, 0x000026e0, 0x0245803f, 0x000026e0, 0x04000200, 0x00000000,
	0x077ff33c, 0x000002e0, 0x0675f23c, 0x000000e0, 0x00000001, 0x00000000,
	0x00000100, 0x00000000, 0xff7fffbc, 0x000003e0, 0xff7ffb3c, 0x000003e0,
	0x0245803c, 0x000000e0, 0x067ff33c, 0x000002e0, 0x00010000, 0x00000000,
	0x00000004, 0x00000000, 0x0000007c, 0x00000003, 0x00100004, 0x00000000,
	0x0000003c, 0x00000000, 0x0245803c, 0x000002e0, 0x0000007c, 0x00001800,
	0x0277e03c, 0x000000e0, 0x027de03c, 0x000000e0, 0x0001803c, 0x00001800,
	0x00000900, 0x00000000, 0x0245813f, 0x000026e0, 0x08000800, 0x00000000,
	0x08000000, 0x00000000, 0x0675e23c, 0x000002e0, 0x0275e13c, 0x000000e0,
	0x00026000, 0x00000000, 0xfc000000, 0x00000100, 0x00000800, 0x00000000,
	0x00000200, 0x00000000, 0x00020000, 0x00000000
};

const int Whale::Parser::compressed_goto_table[Whale::Parser::compressed_goto_table_size]={
	 11,  10,   9,   8,   7,   6,   5,   4,  -1,   3,  -1,  -1,
	  2,   1,  10,   9,   8,   7,   6,   5,   4,  -1,   3,  -1,
	 -1,  28,  32,   4,  42,   4,  43,   4,  44,   4,  53,  -1,
	 52,  55,  65,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,
	 64,  -1,  63,  68,  69,   4,  72,   4,  73,   4,  74,   4,
	 76,  -1,  75,  87,  86,  92,  93,   4,  94,  95,  -1,  -1,
	 -1,  -1,  -1,  -1,  -1,  -1,  -1,  64,  -1,  63,  96,  97,
	 -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  -1,  64,  -1,  63,
	 98, 111, 118,  87, 131,  87, 132, 137, 142, 145,  87, 146,
	 87, 147, 148, 149, 150, 151, 152, 153, 156, 159, 161, 162
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -