sigl a drawing language
play

SIGL A Drawing Language Phong Pham Abelardo Gutierrez Alketa - PowerPoint PPT Presentation

SIGL A Drawing Language Phong Pham Abelardo Gutierrez Alketa Aliaj May 7, 2007 COMS W4115 Programming Languages and Translators - Spring 2007 Outline Introduction What is SIGL? Feature highlighting SIGL anatomy Scanning


  1. SIGL A Drawing Language Phong Pham Abelardo Gutierrez Alketa Aliaj May 7, 2007 COMS W4115 Programming Languages and Translators - Spring 2007

  2. Outline • Introduction – What is SIGL? – Feature highlighting • SIGL anatomy – Scanning and parsing – Overall design – Evaluation • Testing COMS W4115 Programming Languages and Translators - Spring 2007 1

  3. What is SIGL? • Simple Image Generation Language: simple language for drawing 2D images • Motivation – VRML language: standard 3D model specification – Lack of controlling flow – Repetition required – Only suitable for machine generation • Introduce more control in form of C-like syntax COMS W4115 Programming Languages and Translators - Spring 2007 2

  4. Drawing in SIGL • Draw 3 vertically aligned boxes for (i = 0;i < 3;++i) { :translate(0, i * 2): { rectangle(0, 0, 1, 1); } } COMS W4115 Programming Languages and Translators - Spring 2007 3

  5. Features • Drawing features – OpenGL-like drawing mechanism – Support commonly used primitives: lines, circle, ellipse, polygons – Transformations: translation, rotation, scale • Language features – C-like language – Support nearly all C constructions (except for switch) – Data types: int, double, boolean, associative array – Dynamic type system, no type decoration – Static scoping – Applicative evaluation order COMS W4115 Programming Languages and Translators - Spring 2007 4

  6. Grammar • C-like operators / comments / ID – Three types of operational tokens: Integer, real number, logical • C-like arithmetic precedent etc. – Mult, Div, and Mod precedence over addition and subtraction • C-like function declaration and flow control statements – for, if, while, break, continue, return, empty statement (;) COMS W4115 Programming Languages and Translators - Spring 2007 5

  7. Parser - Walker • Build AST tree in 2 steps – Build default ANTLR tree (Parser) while_stmt : "while"^ LPAREN! expr RPAREN! stmt ; – Transform default AST tree into object tree (Walker) #("while" e1=expr s1=stmt { s = new While(e1, s1); } ) • Store location of the expressions for debugging purposes. #(LOR a=expr b=expr { e = new LogicalOperation("||", a, b); e.setLine(#LOR.getLine()); e.setColumn(#LOR.getColumn()); } ) • The object tree makes Walker simpler, allows language flexibility COMS W4115 Programming Languages and Translators - Spring 2007 6

  8. Class Hierarchy If BoolConstant For IntConstant While Stmt Expr RealConstant RelationalOperation Block BinaryOperation ArithmeticOperation Break UnaryOperation LogicalOperation Continue Return Function Value IntValue RealValue ArrayValue BoolValue FunctionValue ThunkValue COMS W4115 Programming Languages and Translators - Spring 2007 7

  9. Type checking • Expressions are evaluated into Values • Type-checking is done using Values • Example: “%” operator – Evaluate left hand side to val1 – Evaluate right hand side to val2 – Check that both val1 and val2 are both of type IntValue COMS W4115 Programming Languages and Translators - Spring 2007 8

  10. Environment • Stored current states of the program • Components: – Symbol table – Drawing canvas (this includes colors, etc.) – Current transformation – Break, continue, return flag COMS W4115 Programming Languages and Translators - Spring 2007 9

  11. Symbol table • Desired behavior x = 1; // x is bound to 1 { x = 5; // x is bound to 5 y = 6; // x is bound to 5, y is bound to 6 } // x is bound to 5, y is unbound name stub value name stub value name stub value name value stub value Clone Extend Extend destructively COMS W4115 Programming Languages and Translators - Spring 2007 10

  12. Functions • Functions are first-order entities in SIGL – Can be passed as arguments to other functions • Function declarations are evaluated into FunctionValues • FunctionValue: tuple of 2 values fv = (f,env) – The function f itself – A cloned environment env of the environment at which the function is declared • Handle recursive function: bind destructively f to fv in env COMS W4115 Programming Languages and Translators - Spring 2007 11

  13. Function call evaluation • Retrieve FunctionValue associated with the given name • Execute the function (stored in FunctionValue) – Static scoping: using the environment stored in FunctionValue – Dynamic scoping: using the current environment • Evaluation order – Applicative order: evaluate each argument expressions and pass to the function – Normal order: create a ThunkValue ∗ ThunkValue: tuple (expr,env) COMS W4115 Programming Languages and Translators - Spring 2007 12

  14. Modified access in symbol table • ThunkValue should only be evaluated once • Access is called: – Get the value – If the value is ThunkValue ∗ Evaluate expr in ThunkValue using env in ThunkValue ∗ Replace ThunkValue in symbol table with new value – return value COMS W4115 Programming Languages and Translators - Spring 2007 13

  15. Built-in functions • Don’t need to change lexer/parser • Implement as FunctionValue • Automatically loaded COMS W4115 Programming Languages and Translators - Spring 2007 14

  16. Testing • Some unit testing using JUnit • Peer-review • Big-bang testing COMS W4115 Programming Languages and Translators - Spring 2007 15

  17. Thank you Questions? COMS W4115 Programming Languages and Translators - Spring 2007 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend