Click here to Skip to main content
15,885,990 members
Articles / Programming Languages / C#

Building a General Purpose Interpreter, Math Engine and Parser in C#

Rate me:
Please Sign up or sign in to vote.
4.97/5 (70 votes)
13 Feb 2015GPL313 min read 84.9K   7.9K   224  
An easy to understand and use language interpreter, run time parser and calculation engine from scratch in C#.
{
    removeall:
	/*
		This example demonstrates the use of new plotting routines
		Created by K.I. (kashif@mathiversity.com)
	*/
	t = vectorin(-16, 0.005, 16);:	
	a = sin(8*t/5) * cos(t);:
	b = sin(8*t/5) * sin(t);:
	
	theta= vectorin(0, 0.005, 2*pi);:
	c = 4 * cos(theta) ^ 3;:
	d = 4 * sin(theta) ^ 3;:
	
	x= vectorin(-2*pi, 0.005, 2*pi);:
	y= sin(x);:
	
	p = createplot();:	
	
	addplot(p, a, b, 0, 1, red);:
	addplot(p, c, d, 0, 1, green);:
	addplot(p, x, y, 0, 1, orange);:
	
	"Let's show the plot by scaling 30 times";:
	showplot(p, 30, 30);:
	
	"Now further zoom in";:
	showplot(p, 100, 100);:	
	
	"Copy plot for changes.";:
	p2 = copyplot(p);:
	"Add a rotated version of second plot and draw it thick";:
	addplot(p2, c, d, 45, 2, red);:		
	"Draw new plot at 60 times original size";:
	showplot(p2, 60, 60);:
	
	"Remove the red curve";:
	removeplot(p2, 0);:	
	"Now add a 45 degrees rotated version of the removed curve to second plot and show it thick with a violet pen.";:
	addplot(p2, a*4, b*4, 45, 2, violet);:
	showplot(p2, 40, 40);:
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Technical Lead https://mathiversity.com
Unknown
I am a full-stack developer. My skills include JavaScript, C#/.Net, MS Azure cloud etc. I love to work on complex programming tasks requiring deep analysis, planning and use of efficient algorithms and data structures.

Comments and Discussions