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

sigl a drawing language
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

SIGL A Drawing Language

Phong Pham Abelardo Gutierrez Alketa Aliaj May 7, 2007

COMS W4115 Programming Languages and Translators - Spring 2007

slide-2
SLIDE 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

slide-3
SLIDE 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

slide-4
SLIDE 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

slide-5
SLIDE 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

slide-6
SLIDE 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

slide-7
SLIDE 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

slide-8
SLIDE 8

Class Hierarchy

Stmt Value IntValue RealValue ArrayValue BoolValue FunctionValue ThunkValue Expr BinaryOperation UnaryOperation ArithmeticOperation LogicalOperation BoolConstant IntConstant RealConstant RelationalOperation If For While Block Break Continue Return Function

COMS W4115 Programming Languages and Translators - Spring 2007 7

slide-9
SLIDE 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

slide-10
SLIDE 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

slide-11
SLIDE 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 name stub value value Clone Extend name stub value value stub Extend destructively

COMS W4115 Programming Languages and Translators - Spring 2007 10

slide-12
SLIDE 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

slide-13
SLIDE 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

slide-14
SLIDE 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

slide-15
SLIDE 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

slide-16
SLIDE 16

Testing

  • Some unit testing using JUnit
  • Peer-review
  • Big-bang testing

COMS W4115 Programming Languages and Translators - Spring 2007 15

slide-17
SLIDE 17

Thank you

Questions?

COMS W4115 Programming Languages and Translators - Spring 2007 16