SCL: Site Construction Language SCL: Site Construction Language - - PowerPoint PPT Presentation

scl site construction language scl site construction
SMART_READER_LITE
LIVE PREVIEW

SCL: Site Construction Language SCL: Site Construction Language - - PowerPoint PPT Presentation

SCL: Site Construction Language SCL: Site Construction Language Sudip Das, Clark Landis, Sudip Das, Clark Landis, Mohamed Nasser Mohamed Nasser COMS W4115 COMS W4115 Programming Languages and Translators Programming Languages and


slide-1
SLIDE 1

SCL: Site Construction Language SCL: Site Construction Language

Sudip Das, Clark Landis, Mohamed Nasser Sudip Das, Clark Landis, Mohamed Nasser COMS W4115 COMS W4115 Programming Languages and Translators Programming Languages and Translators Columbia University Columbia University May 13, 2003 May 13, 2003

slide-2
SLIDE 2

What is SCL? What is SCL?

  • A scripting language for building websites

– Efficiently and intelligently merges

  • Text
  • HTML
  • Graphics
  • Executable CGI scripts

– Automates index generation – Simple yet Powerful – Integrates well with Unix

  • A scripting language for building websites

– Efficiently and intelligently merges

  • Text
  • HTML
  • Graphics
  • Executable CGI scripts

– Automates index generation – Simple yet Powerful – Integrates well with Unix

slide-3
SLIDE 3

What SCL is not What SCL is not

  • GUI-based web design software

– Time-consuming to construct an entire website – Difficult to integrate with dynamic files

  • Server side scripting (PHP, Perl + libraries)

– These generate pages on the fly – Not as efficient as SCL’s precompiled pages

  • SCL works best when combined with the above
  • GUI-based web design software

– Time-consuming to construct an entire website – Difficult to integrate with dynamic files

  • Server side scripting (PHP, Perl + libraries)

– These generate pages on the fly – Not as efficient as SCL’s precompiled pages

  • SCL works best when combined with the above
slide-4
SLIDE 4

SCL Program Components SCL Program Components

  • Template

– an HTML skeleton file

  • Data files

– text, HTML, graphics, CGI, etc.

  • SCL file

– code written in SCL language

  • Template

– an HTML skeleton file

  • Data files

– text, HTML, graphics, CGI, etc.

  • SCL file

– code written in SCL language

slide-5
SLIDE 5

Example: Template Example: Template

<HTML><HEAD></HEAD><TITLE></TITLE> <BODY bgColor=#ff9933 > PutHeaderHere <TABLE cellspacing=0 cellpadding=0 border=0 > <TR align=center> <TD width=100 bgColor=#99ff33> PutNavHere </TD> <TD width=400 bgColor=#ff9999> PutBodyHere </TD> </TR> </TABLE> </BODY> <HTML><HEAD></HEAD><TITLE></TITLE> <BODY bgColor=#ff9933 > PutHeaderHere <TABLE cellspacing=0 cellpadding=0 border=0 > <TR align=center> <TD width=100 bgColor=#99ff33> PutNavHere </TD> <TD width=400 bgColor=#ff9999> PutBodyHere </TD> </TR> </TABLE> </BODY>

slide-6
SLIDE 6

Example: Template Example: Template

slide-7
SLIDE 7

Example: Template Example: Template

slide-8
SLIDE 8

Bindings Bindings

  • Associates a data file with each

placeholder in the template

bind mybindings { PutHeaderHere : "header.html" ; PutBodyHere : "body.jpg" ; PutNavHere : "nav.html" : SSI ; }

  • Associates a data file with each

placeholder in the template

bind mybindings { PutHeaderHere : "header.html" ; PutBodyHere : "body.jpg" ; PutNavHere : "nav.html" : SSI ; }

slide-9
SLIDE 9

Makepage Makepage

  • Takes the template and “smartly” inserts

the substitutions specified in binding

makepage(“template.html”,mybindings)

  • HTML files are copied in
  • Text / code files are translated to HTML &

copied in

  • Image files are linked with <IMG> tag
  • Takes the template and “smartly” inserts

the substitutions specified in binding

makepage(“template.html”,mybindings)

  • HTML files are copied in
  • Text / code files are translated to HTML &

copied in

  • Image files are linked with <IMG> tag
slide-10
SLIDE 10

Other built-in functions Other built-in functions

  • Link: add a link to a file
  • Read: copy contents of file to a variable
  • Write: write a string to

– a variable – a file

  • Writepage: makepage + write
  • Link: add a link to a file
  • Read: copy contents of file to a variable
  • Write: write a string to

– a variable – a file

  • Writepage: makepage + write
slide-11
SLIDE 11

Foreach Foreach

  • Iterates over each element of a list

foreach $file in "messy.jpg halloween.jpg bath.jpg intro.html todo.html" { bind mybindings { PutBodyHere : $file ; } writepage($mytemplate,mybindings,$file.".shtml"); }

  • Iterates over each element of a list

foreach $file in "messy.jpg halloween.jpg bath.jpg intro.html todo.html" { bind mybindings { PutBodyHere : $file ; } writepage($mytemplate,mybindings,$file.".shtml"); }

slide-12
SLIDE 12

Variables Variables

  • All variables are strings

– Can be treated like numbers, e.g. math

  • No declarations

– Variables have default value “null”

  • Identifier preceded by a $, e.g. $foo
  • Dynamic Scope

– defined in inner scope => not seen in outer – defined in outer, changed in inner => changed in outer

  • All variables are strings

– Can be treated like numbers, e.g. math

  • No declarations

– Variables have default value “null”

  • Identifier preceded by a $, e.g. $foo
  • Dynamic Scope

– defined in inner scope => not seen in outer – defined in outer, changed in inner => changed in outer

slide-13
SLIDE 13

User-Defined Functions User-Defined Functions

  • Function declaration

function #foot ($name){ $Return="Foot of ".$name; }

– accepts one variable as input – $Return is the string returned by the function

  • Function reference

#foot("Clark");

  • Can define functions inside functions
  • Can do recursion
  • Function declaration

function #foot ($name){ $Return="Foot of ".$name; }

– accepts one variable as input – $Return is the string returned by the function

  • Function reference

#foot("Clark");

  • Can define functions inside functions
  • Can do recursion
slide-14
SLIDE 14

Example Code Example Code

$mytemplate=read("template.html"); bind mybindings { PutHeaderHere : "header.html" ; PutNavHere : "nav.html" : SSI; } write ("","nav.html"); foreach $file in "messy.jpg halloween.jpg bath.jpg intro.html todo.html" { bind mybindings { PutBodyHere : $file ; } writepage($mytemplate,mybindings,$file.".shtml"); link ($LastPageLink,$file,"nav.html"); } writepage($mytemplate,mybindings,"index.shtml"); $mytemplate=read("template.html"); bind mybindings { PutHeaderHere : "header.html" ; PutNavHere : "nav.html" : SSI; } write ("","nav.html"); foreach $file in "messy.jpg halloween.jpg bath.jpg intro.html todo.html" { bind mybindings { PutBodyHere : $file ; } writepage($mytemplate,mybindings,$file.".shtml"); link ($LastPageLink,$file,"nav.html"); } writepage($mytemplate,mybindings,"index.shtml");

slide-15
SLIDE 15

Output of Example Code Output of Example Code

slide-16
SLIDE 16

Example Code: Scoping Example Code: Scoping

function #foot ($name){ $Return="Foot of ".$name; } function #dog ( $name ) { function #foot ( $name ) { $x="Hello from foot of dog!"; $Return = $name." is a paw. ".#toe($name."'s toe"); } $Return=$name." is a Dog. ".#foot($name."'s foot"); } echo(#dog("Neutron")); echo($x); $x="Hello from OuterScope"; echo($x); echo(#dog("Electra")); echo($x); echo(#foot("Clark")); function #foot ($name){ $Return="Foot of ".$name; } function #dog ( $name ) { function #foot ( $name ) { $x="Hello from foot of dog!"; $Return = $name." is a paw. ".#toe($name."'s toe"); } $Return=$name." is a Dog. ".#foot($name."'s foot"); } echo(#dog("Neutron")); echo($x); $x="Hello from OuterScope"; echo($x); echo(#dog("Electra")); echo($x); echo(#foot("Clark"));

slide-17
SLIDE 17

Compiler Architecture Compiler Architecture

Lexer Lexer Parser Parser AST AST Symbol Table Symbol Table Back End Back End

SCL file SCL file

Tree Walker Tree Walker

Templates Templates Data Files Data Files HTML HTML files files

slide-18
SLIDE 18

Compiler Implementation Compiler Implementation

  • ANTLR Java Parser Generator

– SCLLexer – SCLParser – SCLTreeWalker

  • Other Java Classes

– SCLBE (Back End) – SCL (executes the compiler)

  • java SCL filename.scl
  • ANTLR Java Parser Generator

– SCLLexer – SCLParser – SCLTreeWalker

  • Other Java Classes

– SCLBE (Back End) – SCL (executes the compiler)

  • java SCL filename.scl
slide-19
SLIDE 19

Compiler Output Compiler Output

  • No code is generated

– The SCL file is interpreted

  • The output is a collection of HTML files
  • No code is generated

– The SCL file is interpreted

  • The output is a collection of HTML files
slide-20
SLIDE 20

Demo Demo

slide-21
SLIDE 21

Testing Testing

  • Test suite

– set of tests that run over every line of code – using simple scripts

  • After each update of the source code...

– run the tests as they are

  • should return the same values

– add .scl files to suite, to test new features

  • should return same values + results of new test
  • Test suite

– set of tests that run over every line of code – using simple scripts

  • After each update of the source code...

– run the tests as they are

  • should return the same values

– add .scl files to suite, to test new features

  • should return same values + results of new test
slide-22
SLIDE 22

Testing Testing

  • What was tested

– basic language constructs

  • statements
  • function calls
  • simple commands

– page generation – other subcategories

  • new things added
  • complex commands
  • What was tested

– basic language constructs

  • statements
  • function calls
  • simple commands

– page generation – other subcategories

  • new things added
  • complex commands
slide-23
SLIDE 23

Lessons Learned Lessons Learned

  • Division of Labor

– worked well, even with only 3 people

  • coder
  • tester
  • documenter
  • Keep it simple
  • Read documentation carefully to avoid

frustration, e.g. with ANTLR

  • Division of Labor

– worked well, even with only 3 people

  • coder
  • tester
  • documenter
  • Keep it simple
  • Read documentation carefully to avoid

frustration, e.g. with ANTLR

slide-24
SLIDE 24

Acknowledgements Acknowledgements

  • Peter Palfrader - code2html
  • Seth Doe - txt2html
  • Terrence Parr - ANTLR
  • J.S. Mills - ANTLR Tutorial
  • Prof. Edwards
  • Peter Davis
  • Peter Palfrader - code2html
  • Seth Doe - txt2html
  • Terrence Parr - ANTLR
  • J.S. Mills - ANTLR Tutorial
  • Prof. Edwards
  • Peter Davis