[[select]]
 
 
 
	bool IsIdent (char * s)
	{
		return sy == IDENT && strcmp (IdentVal, s) == 0;
	}
 
	void CheckIdent (char * s)
	{
		if (IsIdent (s))
	           NextSymbol ();
		else 
		{
                   STR_TYP msg;
	     	   strcpy (msg, s);
                   stradd (msg, sizeof (msg), " expected");
                   Error (msg);
		}
	}
 
	void field ()
	{
		if (sy == IDENT)
		{
			PutStr ("field ");
			PutStr (IdentVal);
			PutEol ();
			NextSymbol ();
		}
		else Error ("Field identifier expected");
	}
 
	void table ()
	{
		if (sy == IDENT)
		{
			PutStr ("from table ");
			PutStr (IdentVal);
			PutEol ();
			NextSymbol ();
		}
		else Error ("Table identifier expected");
	}
 
	void expr ();
 
	void simple ()
	{
                Indent ();
		if (sy == IDENT)
		{
			PutStr ("identifier ");
			PutStr (IdentVal);
			PutEol ();
			NextSymbol ();
		}
		else if (sy == NUM)
		{
			PutStr ("number ");
			PutStr (NumVal);
			PutEol ();
			NextSymbol ();
		}
		else if (sy == LPAR)
		{
			NextSymbol (); // preskocit (
			   PutStr ("(");
			   PutEol ();
			   Indent ();
			expr ();
			   Unindent ();
			   PutStr (")");
			   PutEol ();
			CheckSymbol (RPAR);
		}
		else Error ("Invalid simple expression");
                Unindent ();
	}
 
	void mul ()
	{
		Indent ();
		PutStr ("begin of mul");
		PutEol ();
 
		simple ();
		while (sy == ASTERISK || sy == SLASH)
		{
			PutStr (sy == ASTERISK ? "*" : "/");
			PutEol ();
			NextSymbol ();
			simple ();
		}
 
		PutStr ("end of mul");
		PutEol ();
		Unindent ();
	}
 
	void add ()
	{
		Indent ();
		PutStr ("begin of add");
		PutEol ();
 
		mul ();
		while (sy == PLUS || sy == MINUS)
		{
			PutStr (sy == PLUS ? "+" : "-");
			PutEol ();
			NextSymbol ();
			mul ();
		}
 
		PutStr ("end of add");
		PutEol ();
		Unindent ();
	}
 
 
 
	void expr ()
	{
		add ();
	}
 
	void select ()
	{
		PutEol ();
		CheckIdent ("SELECT");
		if (sy==ASTERISK)
		{
			NextSymbol ();
			PutStr ("All fields");
			PutEol ();
		}
		else
		{
			field ();
			while (sy == COMMA)
			{
				NextSymbol ();
				field ();
			}
		}
		CheckIdent ("FROM");
		table ();
		if (IsIdent ("WHERE"))
		{
			NextSymbol ();
			expr ();
		}
		CheckSymbol (SEMICOLON);
	}
 
select.txt · Last modified: 2014/03/17 13:13 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki