programming languages and translators fall 2007 eli hamburger ([email protected]) michele merler...

10
Programming Languages and Translators Fall 2007 Eli Hamburger ([email protected]) Michele Merler ([email protected]) Jimmy Wei ([email protected]) Lin Yang ([email protected]) TMIL Text ManIpulation Language

Post on 21-Dec-2015

226 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

Programming Languages and Translators

Fall 2007

Eli Hamburger ([email protected])Michele Merler ([email protected])

Jimmy Wei ([email protected])Lin Yang ([email protected])

TMIL

Text ManIpulation Language

Page 2: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

• Generate CAPTCHAs(image based RTT)

• Manipulate text on multiple images to create animations

• Create easily adaptable templates (for web site designers)

• Simple, easy to use, c++ like programming language that allows iterative operations text and images

Motivation

Page 3: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

TMIL Features• Manipulate color, size, rotation, font

of a text

• Write text on an image

• Draw lines on an image

• Open and save images

• Build text or lines animations on sequences of images

Page 4: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

Lexical Conventions• Basic types (C/C++ like): bool, char, float, int, string

• Built-in types: – color (r,g,b)

– coordinate (x,y)

– image (h,w)

– text (name, font, colour, position, size, rotation)

• Built-in functions: – open(image, name)

– create(image,h,w,bgcolor)

– save(image,name)

– drawline(image, pos1, pos2, color, width)

– int2string, float2string, string2float, string2int, char_at

• Operators: () [] + - * / % ++ -- == != > < >= <= && || ! . ,

• Special operator: <~ image <~ text : stamps text on image

Page 5: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

TMIL Program Sampleint main(){

image im;

open(im,"Dock.jpg"); // loads image from file

text t;

t.name = "dog"; t.font = "Arial.ttf"; t.size = 60;

coordinate coor[3]; /* array definition */

color c; c.r = c.g = c.b = 50;

t.colour = c;

for (int i=0; i<=2; i++) {•

coor[i].x = i*150; coor[i].y = 200;

t.rotation = i*40;

t.position = coor[i];

if(i==1) t.font = "Times.ttf";

im <~ t; }

drawline(im, coor[0], coor[2], c, 5);

save(im, "test5.png"); // save image into a file

return 0;

}

Page 6: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

//

int main() {

image im;

open(im,"Dock.jpg"); loads image from file

text t;

t.name = "dog";

t.font = "Arial.ttf";

t.size = 60;

coordinate coor[3]; array definition

color c;

c.r = c.r = c.b = 50;

t.colour = c;

for (int i=0; i<=2; i++) {•

coor[i].x = i*150; coor[i].y = 200;

t.rotation = i*40;

t.position = coor[i];

if (i==1) t.font = "Times.ttf";

im <~ t; }

drawline(im, coor[0], coor[2], c, 5);

save(im, "test5.png"); // save image into a file

return 0;}

TMIL Program Sample

C/C++ comments style

multiple assignments

control flow statements

Stamp operator

Built-in functions

Built-in type property access

main() function required

/* */

Array access

Page 7: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

Another TMIL Samplevoid circular_draw(image im, text w) {

text w1 = w; string name; for(int j = 0; j<15; j++) {

name = "./turtle/turtle" + int2string(j+1) + ".jpg"; w1.colour.b -= 30;

w1.colour.g -= 10;w1.rotation = - j*(360/15);

im <~ w1;

save(im,name); }}

int main() {

image im; open(im, "turtle.jpg");

text w1; w1.name = "turtle"; w1.font = "GOTHIC.ttf"; w1.rotation = 0; w1.size = 80; w1.position.x = im.w/2; w1.position.y = im.h/2; w1.colour.r = w1.colour.g = w1.colour.b = 255;

circular_draw(im,w1);

return 0;}

User defined function

Page 8: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

TMIL Compiler ArchitectureInput: TMIL code

Tree WalkerSyntax Analysis

Semantic Analysis

LEXER/PARSER

Output: executable

G++

GDFreeTypeAST

C++ Code

tmil.h

Code Generation

Page 9: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

Testing

• Lexer Tests

• Parser Tests

• Walker/Semantic Analysis Tests

• Final Programs (more complex and actually do something)

Page 10: Programming Languages and Translators Fall 2007 Eli Hamburger (eh2315@columbia.edu) Michele Merler (mm3233@columbia.edu) Jimmy Wei (jw2553@columbia.edu)

Lessons Learned & Conclusions

• Start early

• Good communication

• Pros of teamwork

• Modifying grammar

• There will always be more corner cases to test

• Writing your own compiler is fun