CptS 355 Programming Language Design - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

CptS 355 Programming Language Design

Description:

host - /usr/local/apache/htdocs/index.html (or .htm) ... Apache process. Web and Perl Fit Together. Why is a text-based model so useful for web? ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 37
Provided by: roge2
Category:

less

Transcript and Presenter's Notes

Title: CptS 355 Programming Language Design


1
CptS 355Programming Language Design
Scripting Languages
  • Roger Ray
  • WSU Vancouver, Spring 2001

scripting.ppt
2
This Week
  • OOP wrap-up
  • Scripting Languages
  • reading "Instant Perl" packet
  • lab a small website
  • Presentation

3
Key Things to Learn This Week
4
Tool Builder Attitude
  • Language design is a human activity
  • Chose the right language for the task
  • You can learn to learn a language quickly

5
Tool Builder Skills
  • Basic website structure using dynamic pages
  • Basic Perl
  • Using text and files as data types

6
Language Context
7
Languages Types
most programming languages
imperative
declarative
process-oriented (von Neumann)
data-oriented (object-oriented)
functional
logic
other
matches standard HW efficiency
modelsexternal world maintenance
matchesmathematics experimentation
sophisticatedsearching simplicity
specializedto problem convenience
C
Java
C
Lisp Scheme
Yacc
Prolog
Smalltalk
Fortran Cobol Algol/Pascal
Excel
ML
APL
Perl
compiled
interp
8
Language Levels
algorithm
highabstraction
  • Very High only essential aspects of algorithm
    need to be expressed
  • High many housekeeping and consistency checking
    tasks do not need to be expressed
  • Low all details of computation must be expressed

Scheme
Perl
Java
C
HIGHEFFICIENCY
machine
9
Scripting Languages
  • Purpose
  • combine separate programs into a complete
    solution
  • Examples
  • Unix shells
  • Perl
  • Tk
  • Python
  • Technical details
  • text and file oriented
  • interpreted
  • very high level

10
Hint Getting Up To Speed Quickly
  • Understand purpose
  • Compare to known languages
  • Focus on your goal
  • Run modify examples

Technical
  • Data Structures
  • Control Structures
  • Abstraction Structures

issues to master
Usage
  • Syntax
  • Semantics
  • Pragmatics

11
Perl Review
study the packet handout
12
Web Sites
13
HTML Overview
  • Content of web page is in "Hyper-Text Markup
    Language" format
  • text to be formatted
  • interspersed directives ("tags") for
    presentation ("layout") and relationships
    ("link")
  • various oddities and browser dependent features

14
Many Capabilities
ltfont face"Bradley Hand ITC"gtMany
fontslt/fontgt lttable border"1" cellspacing"3"gt
lttrgt lttd bgcolor"FFFF00"gtltstronggtTableslt/st
ronggtlt/tdgt lttd bgcolor"FFFF00"gtstronggtplayer
lt/stronggtlt/tdgt lttd bgcolor"FFFF00"gtltstronggts
corelt/stronggtlt/tdgt lt/trgt lttrgt lttdgtlt/tdgt
lttd align"center" width"62"gtJacklt/tdgt lttd
align"right" width"53"gt24lt/tdgt lt/trgt lttrgt
lttdgtlt/tdgt lttd align"center"gtPeterlt/tdgt
lttd align"right"gt30lt/tdgt lt/trgt lttrgt lttd
align"right"gtaveragelt/tdgt lttd
align"center"gtnbsplt/tdgt lttd
align"right"gt27lt/tdgt lt/trgt lt/tablegt ltolgt
ltligtLists of manylt/ligt ltligtsortslt/ligt lt/olgt For
ms for data entry ltform method"POST"
action"something.cgi"gt ltinput type"text"
name"T1" size"20"gt ltinput type"submit"
value"Submit" name"B1"gt lt/formgt Applets ltapple
t code"Mandala" width"150" height"150"
align"right"gt ltparam name"n"
value"9"gt lt/appletgt
15
How Web Pages Work
client
server
index.html
16
Common Server Directory Structure
net cloud
http//cs.vancouver.wsu.edu
199.237.83.46
port 80
Apache process
cs13 in ELSB 104
fork as "nobody"
/usr/local/apache/htdocs
note chmod arx !
...
index.html
  • Examples (where host "http//cs.vancouver.wsu.ed
    u"
  • host -gt /usr/local/apache/htdocs/index.html (or
    .htm)
  • host/x.html -gt /usr/local/apache/htdocs/x.html
  • host/ray -gt ray/public_html/index.html
  • host/ray/a/b.html -gt ray/public_html/a/b.html

17
How Dynamic Web Pages Work
client
server
1. Connect to server and ask for page
www.puddle.com/search.cgi?wordsrobot
the CGI protocol
2. Accept and execute the program search.cgiwith
stdin wordsrobot
3. Look in database and write text of new web
page to stdout
lthtmlgt ltheadgt lttitlegtTitles Foundlt/titlegt lt/headgt
ltbodygt lth1gtTitles Foundlt/h1gt These titles
were found lttable cellspacing"5"gt lttrgt
lttdgtltstronggtRobot Monsterlt/stronggtlt/tdgt
lttdgtlta href"http//www.puddle.com/detail.cgi?uid
10043"gtdetailslt/agtlt/tdgt lt/trgt ... etc. ...
4. Interpret the HTML tags and display the page
18
Web and Perl Fit Together
net cloud
Apache process
fork as "nobody"
Text!
exec Perl script
  • Why is a text-based model so useful for web?
  • What are good Perl attributes for this purpose?

Text files!
19
Using Perl and the Web Together
20
Common Approach
ray/public_html
  • GIF JPG
  • Misc
  • The home page
  • Other pages
  • Scripts

cgi
page
index.html
image
lib
index.htm
page/x.htm
lthtmlgt ltbodygt ltbgtThis is ray/public_html/index.h
tmlt/bgt ltulgt ltligtlta hrefpage/x.htmgtGoto x
pagelt/agt ltligtlta hrefpage/y.htmgtGoto y
pagelt/agt ltligtlta hrefcgi-bin/z.cgigtRun z
scriptlt/agt lt/ulgt lt/bodygt lt/htmlgt
lthtmlgt ltbodygt ltbgtThis is ray/public_html/page/x.
htmlt/bgt ltulgt ltligtlta hrefx.htmgtGoto x
pagelt/agt ltligtlta hrefy.htmgtGoto y pagelt/agt ltligtlta
href../cgi-bin/z.cgigtRun z scriptlt/agt lt/ulgt lt/bo
dygt lt/htmlgt
cgi-bin/z.cgi
! /usr/bin/perl print "Content-type
text/html\n\n" print ltltEOF lthtmlgt ltbodygt ltbgtThis
is ray/public_html/cgi-bin/z.cgilt/bgt ltulgt ltligtlta
href../index.htmgtGo back to index.htmlt/agt lt/ulgt
lt/bodygt lt/htmlgt EOF
  • Note carefully
  • pathnames
  • first 2 lines of the script

21
Your Most Common Problems ...
  • Check spelling in URL
  • Check pathname on server
  • Make all directories and files arx
  • Verify pathname references
  • Verify first two lines of your script
  • Run your script by hand examine output
  • Refresh the page

22
A Time Page
Report current time at server
http//cs.vancouver.wsu.edu/ray/cgi-bin/now.cgi
  • Open
  • write to file open (XYZ, "gtname")
  • append to file open (XYZ, "gtgtname")
  • read from file open (XYZ, "ltname")
  • write to pipe open (XYZ, "command")
  • read from pipe open (XYZ, "command")
  • Read a file in one gulp
  • var ltXYZgt
  • Test by hand

! /usr/bin/perl print "Content-type
text/html\n\n" open (DATE, "/bin/date") resul
tltDATEgt print ltltEOF lthtmlgt ltbodygt ltbgtThe time
is now resultlt/bgt lt/bodygt lt/htmlgt EOF
cd ray/public_html cgi-bin/now.cgi Content-ty
pe text/html lthtmlgt ltbodygt ltbgtThe time is now
Fri Apr 20 140755 PDT 2001 lt/bgt lt/bodygt lt/htmlgt
cgi-bin/now.cgi
23
A Plural Page
Compute plural of a noun
http//cs.vancouver.wsu.edu/ray/page/plural.htm
type
submit
clear
link
cd ray/public_html/lib plural dog dogs
the program I will use
24
A Plural Page
http//cs.vancouver.wsu.edu/ray/page/plural.htm
page/plural.htm
lthtmlgt ltbodygt ltbgtPlurallt/bgt ltpgt ltform
method"POST" action"../cgi-bin/plural.cgi"gt ltin
put typetext name"word" size16gt ltpgt ltinput
typesubmit value"Submit"gt ltinput typereset
value"Clear"gt lt/formgt lt/bodygt lt/htmlgt
! /usr/bin/perl require "weblib.pl" parameter
s wordFORM"word" print "Content-type
text/html\n\n" open (PIPE, "../lib/plural
word") resultltPIPEgt chop result print
ltltEOF lthtmlgt ltbodygt The plural of 'ltfont
colorbluegtwordlt/fontgt' is 'ltfont
colorbluegtresultlt/fontgt'. ltpgt lta
href../page/plural.htmgtGo backlt/agt lt/bodygt lt/html
gt EOF
parameters is reusable sub
../cgi-bin/plural.cgi?worddog
Apache process
cgi-bin/plural.cgi
export REQUEST_METHODPOST export
CONTENT_LENGTH8 echo "worddog"
../cgi-bin/plural.cgi
25
Form Element Summary
lthtmlgt ltbodygt ltbgtSome Form Elementslt/bgt ltform
action"../cgi-bin/form.cgi" methodpostgt lttable
valigntopgt lttrgtlttdgtText lttdgtltinput
typetext nametext1 valuedefault
size20gt lttrgtlttd colspan2gtlthrgt lttrgtlttdgtCheckbox
lttdgtltinput typecheckbox namecheck1
valueongt engraved ltbrgtltinput
typecheckbox namecheck2 valueon checkedgt
framed lttrgtlttd colspan2gtlthrgt lttrgtlttdgtRadio
lttdgtltinput typeradio nameradio1 valueredgt
red ltbrgtltinput typeradio
nameradio1 valuebluegt
blue ltbrgtltinput typeradio nameradio1
valuegreen checkedgt green lttrgtlttd
colspan2gtlthrgt lttrgtlttdgtSelect lttdgtltselect
nameselect1 size3gt ltoption value1gt
big ltoption value2gt
medium ltoption value3 selectedgt
small lt/selectgt lttrgtlttd colspan2gtlthrgt lttrgtltt
dgtButtons lttdgtltinput typesubmit namesubmit1
valueContinuegt ltinput typesubmit
namesubmit1 valueQuitgt ltinput typereset
valueResetgt lttrgtlttd
colspan2gtlthrgt lttrgtlttdgtHidden lttdgtltinput
typehidden namehidden1 valueSecretgt lt/tablegt lt/
formgt lt/bodygt lt/htmlgt
../cgi-bin/form.cgi?text1defaultcheck2onradio1
greenselect13submit1Continuehidden1Secret
26
Scripting Wrap-up
27
Scripting Language Challenges
  • Issues
  • pseudo-code and virtual machine implementation
  • static vs. dynamic scoping
  • unbounded strings/arrays and garbage collection
  • I/O operations
  • program invocation and communication primitives
  • error handling
  • portability
  • Non-issues
  • efficiency
  • numeric computation
  • rich data structures

28
Key Points
  • Scripting languages objective
  • combine separate programs into a whole solution
  • Key insight
  • organize software as subsystems exchanging text
  • Key technique
  • text manipulation without pre-compilation
  • Things to remember
  • basic Perl techniques
  • basic website structure
  • tool builder attitude
  • Things to learn in future
  • lots more web technologies
  • website experts got that way by building things!

29
Appendix
30
The "parameters" Subroutine
parameters Read form values into
FORM'variable_name' sub parameters
Get the input via GET or POST interface if
(ENV'REQUEST_METHOD' eq "GET") buffer
ENV'QUERY_STRING' else sysread (STDIN,
buffer, ENV'CONTENT_LENGTH') Split
the name-value pairs and process each _at_pairs
split(//, buffer) foreach pair (_at_pairs)
(name, value) split(//, pair)
un-Webify plus signs and -encoding value
tr// / value s/(a-fA-F0-9a-fA-F
0-9)/pack("C", hex(1))/eg save in FORM
array FORMname value 1
make require happy
31
Some Perl Techniques
set n to random number between 1 and 6 n
int (rand (6)) 1
loop thru 0 .. 4 for (i 0 i lt 5 i)
print "i i\n"
evaluate a string as Perl expression exp
"1(23)" v eval (exp) v set to 5
replace XYZ by value of new everywhere in
string t t s/XYZ/new/g
print to the file xyz.txt, if it can be
opened if (open (FILE, "gtxyz.txt")) print FILE
"line 0\n" print FILE "line 1\n"
write message to stderr and exit die ("I can't
continue like this")
print every element in an array x _at_x ("one",
"two", "three") foreach x (_at_x) print
"x\n"
read line n gt 0 of a file assume every
line 8 bytes long n 3 open (FILE,
"ltdata.txt") seek (FILE, n8, 0) read (FILE,
line, 7) no \n print "line n line\n"
split into fields and array data
"pete\tsome stuff\tzero\tone\ttwo\tthree" (id,
stuff, _at_f) split ("\t", data) print "id
id, stuff stuff, f0 f0\n"
id pete, stuff some stuff, f0 zero
... and much more!
32
URL's Identify Resources
  • Anatomy of a web page uniform resource locator
    (simplified)

http
//
www.puddle.com
/title.htm
?wordsrobot
protocol
stdin
server
pathname
(case insensitive)
(case sensitive)
(dependent on form method)
(top directory is server dependent)
  • Some other protocols (greatly simplified)

ftp
//
neon.vancouver.wsu.edu
/class/cs360/lib/database
typea
mailto
//
roger_at_anastasia.com
?subjectLunch today
news
//
comp.infosys.www.announce
telnet
//
neon.vancouver.wsu.edu
33
CGI Alternatives
Server Side
Client Side
  • SSI (Server Side Includes)
  • PHP (PHP Hypertext Preprocessor)
  • ASP (Active Server Pages)
  • JavaScript
  • Java

lthtmlgt ltbodygt lt!--exec cmd"/bin/date"
--gt lt/bodygt lt/htmlgt
ltscriptgt function Validate (form) if
(form.email.value.length 0) alert ("missing
email address") return false else return
true lt/scriptgt ltform method"POST"
action"../cgi-bin/fb.pl" onsubmit"return
Validate(this)"gt lttextarea name"email" rows3
cols52 wraphardgtlt/textareagt ltinput typesubmit
valueSubmitgt lt/formgt
lthtmlgt ltbodygt lt?php echo "ltbgtHello Worldlt/bgt" ?gt
lt/bodygt lt/htmlgt
lt?php if(strstr(HTTP_USER_AGENT,"MSIE")) 
?gt ltcentergtltbgtYou are using Internet Explorerlt/bgt
lt/centergtlt?  else  ?gt ltcentergtltbgtYou are not u
sing Internet Explorerlt/bgtlt/centergtlt? ?gt
ltapplet code"Hairy.class" codebase"./" width"12
8" height"128"gt ltparam name"n"
value"19"gt ltparam name"nmax"
value"999"gt lt/appletgt
lt DIM X X 100 gt The value of x is lt X gt.
34
What Technologies Do Webmasters Use?
  • Server administration
  • server OS Sun Solaris, Linux, Microsoft NT
  • protocols tools http, ftp, mail, etc.
  • Web static page construction
  • specialized editors Microsoft Frontpage,
    Macromedia Dreamweaver, ...
  • text editors various
  • Web graphics construction
  • still images Adobe Photoshop
  • animations Macromedia Flash, Macromedia Director,
    ...
  • Web dynamic page construction (server side)
  • databases SQL, Oracle, Microsoft Internet
    Information Server
  • page construction Perl, PHP, Microsoft Active
    Server Pages, ...
  • Web page embedded logic (client side)
  • page element manipulation Javascript
  • embedded applications Java, Microsoft ActiveX,
    various "plugins"
  • And many other specialized tools!

35
Useful Books
36
Dynamic Web Page Irritants and Problems
Server Side
Client Side
  • Stateless model
  • CR/LF vs. NL
  • I/O buffer caching
  • OS differences
  • Security issues
  • E-mail (love it/hate it)
  • Database interfaces
  • Changing "standards"
  • TCP/IP delivery guarantees
  • ...
  • Stateless model
  • CR/LF vs. NL
  • Page caching
  • Browser differences
  • Monitor differences
  • Language cultural differences
Write a Comment
User Comments (0)
About PowerShow.com