Esempio n. 1
0
void parser::Arg0()
{
	if (curlex->type==Bracket&&curlex->lexnum=='(')
	{
		newlex();
		if (curlex->type==Bracket&&curlex->lexnum==')')
			newlex();
		else throw parserr("expected `)'",curlex);
	}
	else throw parserr("expected `('",curlex);
}
Esempio n. 2
0
void parser::ArgList()
{
	if (curlex->type==Bracket&&curlex->lexnum=='(')
	{
		newlex();
		ArgPrint();
		while (curlex->type==Divider&&curlex->lexnum==',')
		{
			newlex();
			ArgPrint();
		}
		if (curlex->type==Bracket&&curlex->lexnum==')')
			newlex();
		else throw parserr("expected `)'",curlex);
	}
	else throw parserr("expected `('",curlex);
}
Esempio n. 3
0
void parser::Arg2()
{
	if (curlex->type==Bracket&&curlex->lexnum=='(')
	{
		newlex();
		Exp1();
		if (curlex->type==Divider&&curlex->lexnum==',')
		{
			newlex();
			Exp1();
			if (curlex->type==Bracket&&curlex->lexnum==')')
				newlex();
			else throw parserr("expected `)'",curlex);
		}
		else throw parserr("expected `,'",curlex);
	}
	else throw parserr("expected `('",curlex);
}
Esempio n. 4
0
/* Reparse errbuf to errors if errbuf is a scratch buffer and it has changed
 * since the last parse.
 */
static void reparserr(void) {
	if (errbuf == NULL || !errbuf->scratch || !errbuf->changed ||
	    errbuf->name[0] != '*') {
		return;
	}
	if (errptr != &errors) {  /* Keep the original error position. */
		unsigned char *name = vsncpy(NULL, 0, sv(errptr->file));
		long line = errptr->line;
		ERROR *p;
		parserr(errbuf);
		if (NULL != (p = srcherr(name, line))) {
			errptr = p;
			setline(errbuf, errptr->src);
		}
		vsrm(name);
	} else {
		parserr(errbuf);
	}
}
Esempio n. 5
0
void parser::Lab()
{
	if (curlex->type==Label)
	{
		table.decllab(curlex->lexstr,curpolizelem);
		newlex();
		if (curlex->type==Divider&&curlex->lexnum==':')
			newlex();
		else throw parserr("expected `:'\n",curlex);
	}
}
Esempio n. 6
0
void parser::State()
{
	if ((curlex->type==KeyWord)&&(curlex->lexnum==LexIf))
	{
		newlex();
		if (curlex->type==Bracket&&curlex->lexnum=='(')
		{
			newlex();
			Exp();
			if (curlex->type==Bracket&&curlex->lexnum==')')
			{
				PolizLabel *temp=new PolizLabel((char*)0);
				addpolizelem(temp);
				PolizElem *temp1=new PolizOpGoFalse;
				addpolizelem(temp1);
				newlex();
				LabState();
				temp->SetVal(curpolizelem);
			}
			else throw parserr("expected `)'",curlex);
		}
		else throw parserr("expected `('",curlex);
	}
	else if (curlex->type==Bracket&&curlex->lexnum=='{')
	{
		newlex();
		do
		{
			LabState();
		} while (curlex->type!=Bracket||curlex->lexnum!='}');
		newlex();
	}
	else
	{
		SimpleSt();
		if (curlex->type==Divider&&curlex->lexnum==';')
			newlex();
		else throw parserr("expected `;'",curlex);
	}
}
Esempio n. 7
0
bool parser::Array(bool set)
{
	if (curlex->type==Bracket&&curlex->lexnum=='[')
	{
		newlex();
		Exp1();
		if (curlex->type==Bracket&&curlex->lexnum==']')
			newlex();
		else throw parserr("expected `]'",curlex);
		PolizElem *temp=new PolizIdx(set);
		addpolizelem(temp);
		return true;
	}
	return false;
}
Esempio n. 8
0
int uparserr(BW *bw)
{
	show_messages_found_count(bw, parserr(bw->b));
	return 0;
}
Esempio n. 9
0
void parserrb(B *b)
{
	BW *bw;
	bw = find_a_good_bw(b);
	show_messages_found_count(bw, parserr(bw->b));
}
Esempio n. 10
0
void parser::SimpleSt()
{
	if (curlex->type==KeyWord&&curlex->lexnum==LexInt)
	{
		do
		{
			newlex();
			if (curlex->type==Variable)
			{
				PolizItem *tmpcur=curpolizelem;
				table.declvar(curlex->lexstr);
				PolizElem *temp=new PolizVarAddr(curlex->lexstr,0);
				addpolizelem(temp);
				newlex();
				if (!Array(true))
					if (!VarArg())
					{
						delete temp;
						curpolizelem=tmpcur;
						if (tmpcur)
							tmpcur->next=0;
						else
							poliz=0;
					}
			}
			else
				throw parserr("declaration of variable or array expected",curlex);
		} while (curlex->type==Divider&&curlex->lexnum==',');
	}
	else if (curlex->type==Variable)
	{
		PolizElem *temp=new PolizVarAddr(curlex->lexstr,0);
		addpolizelem(temp);
		newlex();
		Array(false);
		if (curlex->type==Operation&&curlex->lexnum=='=')
		{
			newlex();
			Exp1();
			temp=new PolizFunAssig;
			addpolizelem(temp);
		}
		else parserr("expected `='",curlex);
	}
	else if (curlex->type==KeyWord&&curlex->lexnum==LexGoto)
	{
		newlex();
		if (curlex->type==Label)
		{
			PolizElem *temp=new PolizLabel(curlex->lexstr);
			addpolizelem(temp);
			temp=new PolizOpGo;
			addpolizelem(temp);
			newlex();
		}
		else parserr("name of label expected",curlex);
	}
	else if (curlex->type==KeyWord&&curlex->lexnum==LexPrint)
	{
		PolizElem *temp=new PolizPrintEnd;
		addpolizelem(temp);
		newlex();
		ArgList();
		temp=new PolizPrint;
		addpolizelem(temp);
	}
	else if (curlex->type==KeyWord&&curlex->lexnum==LexSell)
	{
		newlex();
		Arg2();
		PolizElem *temp=new PolizSell;
		addpolizelem(temp);
	}
	else if (curlex->type==KeyWord&&curlex->lexnum==LexBuy)
	{
		newlex();
		Arg2();
		PolizElem *temp=new PolizBuy;
		addpolizelem(temp);
	}
	else if (curlex->type==KeyWord&&curlex->lexnum==LexProd)
	{
		newlex();
		Arg1();
		PolizElem *temp=new PolizProd;
		addpolizelem(temp);
	}
	else if (curlex->type==KeyWord&&curlex->lexnum==LexJoin)
	{
		newlex();
		Arg1();
		PolizElem *temp=new PolizJoin;
		addpolizelem(temp);
	}
	else if (curlex->type==KeyWord&&curlex->lexnum==LexBuild)
	{
		newlex();
		Arg0();
		PolizElem *temp=new PolizBuild;
		addpolizelem(temp);
	}
	else if (curlex->type==KeyWord&&curlex->lexnum==LexTurn)
	{
		newlex();
		Arg0();
		PolizElem *temp=new PolizTurn;
		addpolizelem(temp);
	}
	else throw parserr("expected operator",curlex);
}
Esempio n. 11
0
void parser::Exp3()
{
	if (curlex->type==Variable)
	{
		PolizElem *temp=new PolizVarAddr(curlex->lexstr,0);
		addpolizelem(temp);
		newlex();
		Array(false);
		temp=new PolizVar;
		addpolizelem(temp);
	}
	else if (curlex->type==Number)
	{
		PolizElem *temp=new PolizInt(curlex->lexnum);
		addpolizelem(temp);
		newlex();
	}
	else if (curlex->type==Function)
	{
		FuncClass temp;
		char *str=curlex->lexstr;

		if (temp.getargnum(str))
		{
			newlex();
			Arg1();
			PolizElem *temp=new PolizFunction1(str);
			addpolizelem(temp);
		}
		else
		{
			newlex();
			Arg0();
			PolizElem *temp=new PolizFunction0(str);
			addpolizelem(temp);
		}
	}
	else if (curlex->type==Operation&&curlex->lexnum=='-')
	{
		PolizElem *temp=new PolizInt(0);
		addpolizelem(temp);
		newlex();
		Exp3();
		temp=new PolizFunMinus;
		addpolizelem(temp);
	}
	else if (curlex->type==Operation&&curlex->lexnum=='!')
	{
		newlex();
		Exp3();
		PolizElem *temp=new PolizFunNeg;
		addpolizelem(temp);
	}
	else if (curlex->type==Bracket&&curlex->lexnum=='(')
	{
		newlex();
		Exp();
		if (curlex->type==Bracket&&curlex->lexnum==')')
			newlex();
		else throw parserr("expected `)'",curlex);
	}
	else throw parserr("expected expression",curlex);
}