scl site construction language scl site construction
play

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


  1. 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 Translators Columbia University Columbia University May 13, 2003 May 13, 2003

  2. What is SCL? What is SCL? • A scripting language for building websites • A scripting language for building websites – Efficiently and intelligently merges – Efficiently and intelligently merges • Text • Text • HTML • HTML • Graphics • Graphics • Executable CGI scripts • Executable CGI scripts – Automates index generation – Automates index generation – Simple yet Powerful – Simple yet Powerful – Integrates well with Unix – Integrates well with Unix

  3. What SCL is not What SCL is not • GUI-based web design software • GUI-based web design software – Time-consuming to construct an entire website – Time-consuming to construct an entire website – Difficult to integrate with dynamic files – Difficult to integrate with dynamic files • Server side scripting (PHP, Perl + libraries) • Server side scripting (PHP, Perl + libraries) – These generate pages on the fly – These generate pages on the fly – Not as efficient as SCL’s precompiled pages – Not as efficient as SCL’s precompiled pages • SCL works best when combined with the above • SCL works best when combined with the above

  4. SCL Program Components SCL Program Components • Template • Template – an HTML skeleton file – an HTML skeleton file • Data files • Data files – text, HTML, graphics, CGI, etc. – text, HTML, graphics, CGI, etc. • SCL file • SCL file – code written in SCL language – code written in SCL language

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

  6. Example: Template Example: Template

  7. Example: Template Example: Template

  8. Bindings Bindings • Associates a data file with each • Associates a data file with each placeholder in the template placeholder in the template bind mybindings { bind mybindings { PutHeaderHere : "header.html" ; PutHeaderHere : "header.html" ; PutBodyHere : "body.jpg" ; PutBodyHere : "body.jpg" ; PutNavHere : "nav.html" : SSI ; PutNavHere : "nav.html" : SSI ; } }

  9. Makepage Makepage • Takes the template and “smartly” inserts • Takes the template and “smartly” inserts the substitutions specified in binding the substitutions specified in binding makepage(“template.html”,mybindings) makepage(“template.html”,mybindings) • HTML files are copied in • HTML files are copied in • Text / code files are translated to HTML & • Text / code files are translated to HTML & copied in copied in • Image files are linked with <IMG> tag • Image files are linked with <IMG> tag

  10. Other built-in functions Other built-in functions • Link: add a link to a file • Link: add a link to a file • Read: copy contents of file to a variable • Read: copy contents of file to a variable • Write: write a string to • Write: write a string to – a variable – a variable – a file – a file • Writepage: makepage + write • Writepage: makepage + write

  11. Foreach Foreach • Iterates over each element of a list • Iterates over each element of a list foreach $file in "messy.jpg halloween.jpg bath.jpg foreach $file in "messy.jpg halloween.jpg bath.jpg intro.html todo.html" intro.html todo.html" { { bind mybindings { PutBodyHere : $file ; } bind mybindings { PutBodyHere : $file ; } writepage($mytemplate,mybindings,$file.".shtml"); writepage($mytemplate,mybindings,$file.".shtml"); } }

  12. Variables Variables • All variables are strings • All variables are strings – Can be treated like numbers, e.g. math – Can be treated like numbers, e.g. math • No declarations • No declarations – Variables have default value “null” – Variables have default value “null” • Identifier preceded by a $, e.g. $foo • Identifier preceded by a $, e.g. $foo • Dynamic Scope • Dynamic Scope – defined in inner scope => not seen in outer – defined in inner scope => not seen in outer – defined in outer, changed in inner => – defined in outer, changed in inner => changed in outer changed in outer

  13. User-Defined Functions User-Defined Functions • Function declaration • Function declaration function #foot ($name){ function #foot ($name){ $Return="Foot of ".$name; $Return="Foot of ".$name; } } – accepts one variable as input – accepts one variable as input – $Return is the string returned by the function – $Return is the string returned by the function • Function reference • Function reference #foot("Clark"); #foot("Clark"); • Can define functions inside functions • Can define functions inside functions • Can do recursion • Can do recursion

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

  15. Output of Example Code Output of Example Code

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

  17. Compiler Architecture Compiler Architecture SCL file SCL file Lexer Parser AST Lexer Parser AST HTML HTML Back End Tree Walker Back End Tree Walker files files Templates Templates Symbol Table Symbol Table Data Files Data Files

  18. Compiler Implementation Compiler Implementation • ANTLR Java Parser Generator • ANTLR Java Parser Generator – SCLLexer – SCLLexer – SCLParser – SCLParser – SCLTreeWalker – SCLTreeWalker • Other Java Classes • Other Java Classes – SCLBE (Back End) – SCLBE (Back End) – SCL (executes the compiler) – SCL (executes the compiler) • java SCL filename.scl • java SCL filename.scl

  19. Compiler Output Compiler Output • No code is generated • No code is generated – The SCL file is interpreted – The SCL file is interpreted • The output is a collection of HTML files • The output is a collection of HTML files

  20. Demo Demo

  21. Testing Testing • Test suite • Test suite – set of tests that run over every line of code – set of tests that run over every line of code – using simple scripts – using simple scripts • After each update of the source code... • After each update of the source code... – run the tests as they are – run the tests as they are • should return the same values • should return the same values – add .scl files to suite, to test new features – add .scl files to suite, to test new features • should return same values + results of new test • should return same values + results of new test

Recommend


More recommend