semantic.cpp in func_draw.rar


compiler theory test, do yourself...Original Link
    Sponsored links

			
			#include "semantics.h"

extern double 
	Parameter,
	Origin_x,Origin_y,
	Scale_x,Scale_y,
	Rot_angle;

double GetExprValue(struct ExprNode *root);
void DrawPixel(unsigned long x,unsigned long y);
void DrawLoop(double Start,double End,double Step,struct ExprNode *HorPtr,struct ExprNode *VerPtr);
void DelExprTree(struct ExprNode *root);
static void Errmsg(char *string);
static void CalcCoord(struct ExprNode *Hor_Exp,struct ExprNode *Ver_Exp, 
					  double &Hor_x, double &Ver_y);
void Errmsg(char *string)
{
	exit(1);
}
static void CalcCoord(struct ExprNode *Hor_Exp,struct ExprNode *Ver_Exp,double &Hor_x, double &Ver_y)
{
	double HorCord,VerCord,Hor_tmp;
	HorCord=GetExprValue(Hor_Exp);
	VerCord=GetExprValue(Ver_Exp);
	HorCord *=Scale_x;
	VerCord *=Scale_y;
	Hor_tmp=HorCord *cos(Rot_angle)+VerCord *sin(Rot_angle);
	VerCord=VerCord *cos(Rot_angle)-HorCord*sin(Rot_angle);
	HorCord=Hor_tmp;
	HorCord+=Origin_x;
	VerCord+=Origin_y;
	Hor_x=HorCord;
	Ver_y=VerCord;
}
void DrawLoop(double Start,
			  double End,
			  double Step,
			  struct ExprNode *HorPtr,
			  struct ExprNode *VerPtr)
{
	extern double Parameter;
	double x,y;
	for(Parameter=Start;Parameter<=End;Parameter+=Step)
	{CalcCoord(HorPtr,VerPtr,x,y);
	DrawPixel((unsigned long) x,(unsigned long)y);
	}
}
double GetExprValue(struct ExprNode *root)
{
	if(root==NULL)return 0.0;
	switch(root->OpCode)
	{
	case PLUS:
		return GetExprValue(root->Content.CaseOperator.Left)+GetExprValue(root->Content.CaseOperator.Right);
	case MINUS:
		return GetExprValue(root->Content.CaseOperator.Left)-GetExprValue(root->Content.CaseOperator.Right);
	case MUL:
return GetExprValue(root->Content.CaseOperator.Left)*GetExprValue(root->Content.CaseOperator.Right);
	case DIV:
return GetExprValue(root->Content.CaseOperator.Left)/GetExprValue(root->Content.CaseOperator.Right);
	case POWER:
return pow(GetExprValue(root->Content.CaseOperator.Left),GetExprValue(root->Content.CaseOperator.Right));
	case FUNC:
		return(*root->Content.CaseFunc.MathFuncPtr)(GetExprValue(root->Content.CaseFunc.Child));
	case CONST_ID:
		return root->Content.CaseConst;
	case T:
		return *(root->Content.CaseParmPtr);
	default:
		return 0.0;
	}
}
void DelExprTree(struct ExprNode *root)
{
	if(root==NULL)return;
	switch(root->OpCode)
	{
	case PLUS:
	case MINUS:
	case MUL:
	case DIV:
	case POWER:
		DelExprTree(root->Content.CaseOperator.Left);

		DelExprTree(root->Content.CaseOperator.Right);
		break;
	case FUNC:
		DelExprTree(root->Content.CaseFunc.Child);
		break;
	default:
		break;
	}
	delete(root);
}
#ifdef _BC_COMPILER
int InGraphMode=0;
int InitGraph(void)
{
	int gd=DETECT,gm;
if(InGraphMode)return 0;
registerbgidriver(EGAVGA_driver);
initgraph(&gd,&gm,"");
setcolor(-1);
InGraphMode=1;
return 1;
}
void CloseGraph(void)
{
	if(!InGraphMode)return;
	getch();
	closegraph();
	InGraphMode=0;
}
#endif
void DrawPixel(unsigned long x,unsigned long y)
{
#ifdef _VC_COMPILER
	SetPixel(hDC,x,y,black);
#endif;
#ifdef _BC_COMPILER
	putpixel(x,y,white);
#endif
}
			click here to download the whole source code package.

			
			


Project Files

    Sponsored links
NameSizeDate
 <func_draw>0.00 B07-09-04 13:26
 func_draw.dsp4.75 kB21-05-04 10:31
 func_draw.dsw541.00 B20-05-04 16:11
 func_draw.ncb89.00 kB21-05-04 10:31
 func_draw.opt49.50 kB21-05-04 10:31
 func_draw.plg1.36 kB21-05-04 10:21
 main.cpp2.22 kB20-05-04 16:17
 parser.cpp8.16 kB21-05-04 10:21
 parser.h381.00 B21-05-04 10:16
 parsermani.cpp200.00 B21-05-04 09:56
 scanner.cpp3.02 kB21-05-04 10:16
 scanner.h1.09 kB21-05-04 09:54
 scannermain.cpp627.00 B21-05-04 10:10
 semantic.cpp3.04 kB20-05-04 16:17
 semantics.h702.00 B20-05-04 16:18
 <Debug>0.00 B07-09-04 13:26
...

Related Items

    Sponsored links