190 likes | 334 Views
MDraw Graphics Manipulation Language. Huimin Sun(hs2740) Dongxiang Yan(dy2224) Jingyu Shi (js4151 ) COMS 4115 Columbia University August 16, 2013. Introduction. 1. A C-like language designed specially for drawing graphics 2. Built-in types: Point, Line, Ellipse, Curve and others
E N D
MDrawGraphics Manipulation Language Huimin Sun(hs2740) Dongxiang Yan(dy2224) Jingyu Shi (js4151) COMS 4115 Columbia University August 16, 2013
Introduction • 1. A C-like language designed specially for drawing graphics • 2. Built-in types: Point, Line, Ellipse, Curve and others • 3. Mdraw is easy to learn and to use • Functionality: • 1. Basic calculation, basic control flow • 2. Drawing graphics using point, line, ellipse, and curve
Tutorial Examples • How to manipulate these built-in types and functions: • Point p1; • p1 = Mpoint( x, y ); /* 2 parameter as the coordinate of the point*/ • Line l1; • l1 = Mline(x1, y1, x2, y2); /* the coordinates of the 2 end point*/ • Curve c1; • c1 = Mcurve(x, y, w, h, angst, angExt); • /*parameters as location, size, angular extents*/ • Ellipse e1; e1 = Mellipse( x, y, w, h ); e1.draw(); p1.draw(); c1.draw();
Tutorial Examples This is a .mdraw file. In basic() , it covers the basic Functionalities. paint() is a drawing function. This file draws a pottery. void basic(){ if(1<2){ print “This is the start!”; } } void paint(){ Ellipse e1; inti; for(i=0; i<20;i=i+1){ e1 = MEllipse(100-5*i, 100+10*i, 100+10*i, 30+5*i); e1.draw(); } Ellipse e2; for (i=0;i<20;i=i+1){ e2 = MEllipse(5+5*i, 290+i*10, 290-10*i,125-5*i); e2.draw(); } }
Implementation • Project Management • Architecture
Project Management • Scrum methodology • 6 weeks • Milestones • 3 questions
Architecture • Scanner • The scanner is used to tokenize the input source code by using lexical analysis. • Comments, whitespace and other unnecessary tokens will be waived. • If any, Illegal characters will fail the program. • Ocamllex
Architecture • Parser • From the stream of tokens output from the scanner, the parser generates the AST (abstract syntax tree). • Ocamlyacc • Translate • The translate is designed to do semantic checking • The semantic check evaluates the type of a statement. • Exceptions will be thrown.
Architecture • Java Generator • Compile.ml • Translate a program in AST form into a java program. Throw an exception if something is wrong, e.g., a reference to an unknown variable or function
Test • Scanner • Ast
Test • void basic(){ • print (2+3); • }
Scanner VOID ID: basic LEFT_PAREN RIGHT_PAREN LEFT_BRACE PRINT LEFT_PAREN INTLITERAL: 2 PLUS INTLITERAL: 3 RIGHT_PAREN SEMICOLON RIGHT_BRACE
AST PROGRAM:[LIST:[CONSTRUCT_FUNCDEF:[FUNCDECL:[FUNTYPE[TYPE_VOID],FUNNAME[basic],LIST:[],LIST:[STMT_BLOCK:[LIST:[STMT_PRINT:[EXPR_BINOP:[EXPR_LITERAL:[LITERAL_INT:[2]],ADD,EXPR_LITERAL:[LITERAL_INT:[3]]]]]]]]]]]
Test • Print • If • For • While • Arithmetic • Gcd • Fib • Point • Line • Curve • Ellipse
While Test • void basic(){ • inti; • i=10; • while(i>0){print i; i=i-1;} • } Result: 10 9 8 7 6 5 4 3 2 1
Gcd Test • intgcd(int a, int b) { • while (a != b) { • if (a > b) a = a - b; • else b = b - a; • } • return a; • } • void basic() • { • print(gcd(2,14)); • print(gcd(3,15)); • print(gcd(99,121)); • } Result: 2 3 11