Presentation is loading. Please wait.

Presentation is loading. Please wait.

EZGraphs A graphs and charts generating language COMS W4115: Programming Languages and Translators Spring 2007 Vincent Edlira.

Similar presentations


Presentation on theme: "EZGraphs A graphs and charts generating language COMS W4115: Programming Languages and Translators Spring 2007 Vincent Edlira."— Presentation transcript:

1 EZGraphs A graphs and charts generating language COMS W4115: Programming Languages and Translators Spring 2007 Vincent Dobrevvd2006@columbia.edu Edlira Kumbarceek2248@columbia.edu

2 Introduction Why graphs? Why graphs? Graphs are used widely. They communicate information more easily and efficiently than words or tables. Objective Objective Provide a language that can be used to create charts and graphs, targeting those with a little prior programming experience.

3 Features User-Friendly Syntax User-Friendly Syntax Very similar to C and Java. Intuitive keywords and internal function names. More organized than Ploticus. Easy Debugging Easy Debugging Non-cryptic and informative error messages make it easy to use and debug. User given exact location of error with file name and line and column numbers.

4 Features (cont’d) Portability Portability Based on Java, so it only depends on the presence of the Java Runtime Environment. Data Types & Operators Data Types & Operators Supports boolean, integer, floating-point, and string data types, as well as multi-dimensional arrays.

5 Features (cont’d) File Inclusion File Inclusion Allows code reuse and modularity. More organized programs. Control Flow Statements Control Flow Statements Supports conditionals (if-then-else) and iterative statements (loops), which in turn enable user to create recursive functions.

6 Features (cont’d) Pre-Defined Functions Pre-Defined Functions  Drawing: point(), line(), polygon(), etc.  Transfromation: translate(), scale(), shear() etc.  Data Acquiring: data()  Math: exp(), log(), pow(), sqrt(), etc.  Auxiliary: strToInt(), strToFloat(), substring(), size(), etc.  Output: print(), println(), save(), show()

7 Example 1 - Recursion /* * Sierpinski Triangle. */ void main() { canvas(600, 600); scale(1, -1); translate(0, -600); triangles(50, 50, 550, 50, 300, 550, 1); show(); } void triangles(int x1, int y1, int x2, int y2, int x3, int y3, int level) { line(x1, y1, x2, y2); line(x2, y2, x3, y3); line(x3, y3, x1, y1); int xp1 = (x2+x1) / 2; int yp1 = (y2+y1) / 2; int xp2 = (x3+x2) / 2; int yp2 = (y3+y2) / 2; int xp3 = (x1+x3) / 2; int yp3 = (y1+y3) / 2; if (level < 8) { triangles(x1, y1, xp1, yp1, xp3, yp3, level+1); triangles(xp1, yp1, x2, y2, xp2, yp2, level+1); triangles(xp3, yp3, xp2, yp2, x3, y3, level+1); }

8 Example 2 - A Pie Chart /* * A pie chart illustrating distribution of income. */ void main() { int fields = 7; /* Colors. */ int[][] c = new int[fields][3]; c[0][0] = 255; c[0][1] = 50; c[0][2] = 0; c[1][0] = 0; c[1][1] = 255; c[1][2] = 0;... c[6][0] = 255; c[6][1] = 255; c[6][2] = 0; /* Labels. */ string[] l = new string[fields]; l[0] = "Savings"; l[1] = "Insurance";... l[6] = "Housing"; /* Percentages. */ int[] p = new int[fields]; p[0] = 9; p[1] = 11;... p[6] = 21;...

9 canvas(400,400); background(244,244,244); string title = "Income Distribution"; font("Arial", 0, 20); int width = width(title); text(title, 200 - width/2, 40); stroke(2); line(50,50,350,50); translate(100,100); int start = 0, end = 0; for (int i = 0; i < fields; i++) { color(c[i][0],c[i][1],c[i][2]); start += end; end = p[i] * 360 / 100; fillArc(0,0,200,200,start,end); } show(); } Example 2 - A Pie Chart (cont’d) Output :

10 Language Implementation The source code is parsed and executed right away with no intermediate code. The source code is parsed and executed right away with no intermediate code. Programs reside in.ezg files, with one file containing a main() function and any number of other.ezg files containing other functions. Programs reside in.ezg files, with one file containing a main() function and any number of other.ezg files containing other functions.

11 Language Implementation (cont’d) Three types of output: Three types of output: 1.Text in the console 2.An image in a window on-screen 3.An image in a file Exception handling mechanism catches, formats, Exception handling mechanism catches, formats, and prints out error messages for the user. Examples: 1.Error: draw.ezg:48:10: expecting ID, found '=‘ 2.Error: draw.ezg:59:6: unexpected data type being assigned to array 3.Error: recursion.ezg:5:5: function fact(int) expected to return int 4.Error: recursion.ezg:7:16: variable g not declared

12 Architecture

13 Interpreter Structure

14 Type System

15 Type Conversions & Operators

16 Type Conversions & Operators (cont’d)


Download ppt "EZGraphs A graphs and charts generating language COMS W4115: Programming Languages and Translators Spring 2007 Vincent Edlira."

Similar presentations


Ads by Google