void args(Scanner & s)
{

	if ((s.Peek().token_type == TOKENS::LABEL) || (s.Peek().token_type == TOKENS::NUMBER))
	{
		symbol(s);
		x_5(s);

	}
	else{
		oops("args", s, "LABEL or NUMBER");

	}
}
void x_5(Scanner & s){
	if (s.Peek().token_type == TOKENS::COMMA)
	{
		s.Match(TOKENS::COMMA);
		args(s);
	}
	else if ((s.Peek().token_type == TOKENS::RIGHTPAREN)){
		return;
	}
	else{
		oops("x_5", s, "COMMA or RIGHTPAREN");

	}

}
void symbol(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::LABEL)
	{
		s.Match(TOKENS::LABEL);
	}
	else if (s.Peek().token_type == TOKENS::NUMBER)
	{
		s.Match(TOKENS::NUMBER);
	}
	else
	{
		oops("symbol", s, "LABEL or NUMBER");
	}
}
void x_6(Scanner & s){

	if (s.Peek().token_type == TOKENS::AND)
	{
		s.Match((TOKENS::AND));
		head(s);
	}
	else if (s.End() || s.Peek().token_type == TOKENS::SEPARATOR)
	{
		return;
	}
	else
	{
		oops("x_6", s, "AND or SEPARATOR");
	}
}
void x_4(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::RIGHTPAREN)
	{
		s.Match(TOKENS::RIGHTPAREN);
		Token temp_t;
		s.SetValidIndex();
	}
	else if ((s.Peek().token_type == TOKENS::LABEL) || (s.Peek().token_type == TOKENS::NUMBER))
	{
		args(s);
		s.Match(TOKENS::RIGHTPAREN);
		s.SetValidIndex();
	}
	else
	{
		oops("x_4", s, "RIGHTPAREN, LABEL, or NUMBER");
	}
}
void name(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::LABEL)
	{
		s.Match(TOKENS::LABEL);
	}
	else
	{
		oops("name", s, "LABEL");
	}
}
void x_1(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::SEPARATOR)
	{
		s.Match(TOKENS::SEPARATOR);
		body(s);
	}
	else
	{
		oops("x_1", s, "SEPARATOR");
	}
}
void hornclause(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::LABEL)
	{
		head(s);
		x_1(s);
	}
	else
	{
		oops("hornclause", s, "LABEL");
	}
}
/*
The opps function is used to error out from the recursion ( for LL(1) parser) and prints out useful 
erro message
*/
void oops(std::string s, Scanner & scanner, std::string expect)
{
	cout << endl;
	cout << "<-----Error Message----->" << std::endl;
	cout << "From: " << s << " " << scanner.Peek().token_name << " is coming in. Delinquent token is: " << scanner.Peek().token_value << endl;
	cout << "We expected " << expect << std::endl;
	cout << "Production up until error: ";
	scanner.PrintError();
	cout << "<-----End Error Message----->" << std::endl;
	cout << endl;
	throw TOKEN_MISMATCH;
}
void predicate(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::LABEL)
	{
		name(s);
		x_3(s);
	}
	else
	{
		oops("predicate", s, "LABEL");
	}
}
void body(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::LABEL)
	{
		predicate(s);
		x_2(s);
	}
	else
	{
		oops("body", s, "LABEL");
	}
}
void head(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::LABEL)
	{
		predicate(s);
		x_6(s);
	}
	else
	{
		oops("head", s, "LABEL");
	}
}
void x_3(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::LEFTPAREN)
	{
		s.Match(TOKENS::LEFTPAREN);
		x_4(s);
	}
	else
	{
		oops("x_3", s, "LEFTPAREN");
	}

}
void x_2(Scanner & s)
{
	if (s.Peek().token_type == TOKENS::AND)
	{
		s.Match((TOKENS::AND));
		body(s);
	}
	else if (s.End() )
	{
		return;
	}
	else
	{
		oops("x_2", s, "AND");
	}
}