Download presentation
Presentation is loading. Please wait.
Published byCameron Sydney Harper Modified over 9 years ago
1
CS 403: Programming Languages Lecture 17 Fall 2003 Department of Computer Science University of Alabama Joel Jones
2
Lecture 172 Overview Announcements Story Hour, Houser 108, 3PM Friday: Software Security and Exploits
3
Lecture 173 PHP Eric Mitchell What is PHP? Originally named: Personal Home Page Tools Now stands for: PHP: Hypertext Preprocessor Open-source, server-side, HTML-embedded Web scripting Serves as a “glue” language, making connecting your Web pages to server-side database
4
Lecture 174 Why learn PHP Free, open-source, full-featured, stable, fast, cross- platform, easy to learn, plays well with others Official module of Apache HTTP Server, runs about 55% of WWW Isn’t tag-based like ColdFusion, it’s a real programming language Popular and Growing
5
Say no to LSD, and say yes to PHP Joshua Chappelle
6
Lecture 176 Mainstream uses of PHP Server side scripting Client side GUIs Command line scripting for simple text processing
7
Lecture 177 Is PHP Portable? Linux and many Unix variants Microsoft Windows Mac OS X RISC OS Apache, Microsoft IIS, Personal Web Server, Netscape and IPlanet Servers, Oreilly Website Pro Server, Caudium, Xitami, OmniHTTPd and other web servers
8
Lecture 178 Does it have DB support? IBM DB2 Oracle (OCI7 and OCI8) ODBC Informix MySQL Sybase Unix dbm and many others
9
Python Seth Copeland An object-oriented scripting language Python is interpreted, not compiled It is portable across many platforms (UNIX, Windows, OS/2, Amiga, etc.) Its interpreter can be used interactively Seth Copeland
10
Lecture 1710 Python Designed for close integration with C Supports embedding in C and data import/export to dynamically loaded C libraries. Block structure is controlled by indentation Seth Copeland
11
Lecture 1711 Python Slowest and least efficient of the major scripting languages Cannot compete in raw execution speed Exhibits runtime type polymorphism Python is best used with medium sized, speed independent projects. It encourages (and even forces) you to produce clean, readable code and its environment can run interactively. It can be integrated with C code and is cross-platform over many environments. Seth Copeland
12
Lecture 1712 PHP: Hypertext Preprocessor Daniel Pritchett Server-side Web scripting language used by many sites to serve dynamic content Tightly integrated with MySQL, supports other databases as well Most popular module on most popular web server (Apache – check www.netcraft.com for statistics)www.netcraft.com Loosely typed C-style syntax can allow for rapid learning and implementation for a C/Java coder Linux, Apache, PHP, and MySQL combine to form a popular free web service suite Detractors say that loose types and weak object model can limit scalability.
13
Login form for “Popper” web-based POP3 Mail client - http://www.ractive.ch/gpl/download/popper.tar.gz http://www.ractive.ch/gpl/download/popper.tar.gz Popper Login "> : "> : <input type="checkbox" name="set_cookie" <?php if ($poppercookie["user"]) { echo(" checked"); } ?> > "); if ($status_msg == $strings["l_PwdWrong"]) { echo(" $strings[l_LostPwd] "); } ?> ">
14
Welcome to the World of Python Ishmael Rudolph CS 403-001 October 24, 2003
15
Lecture 1715 What is Python? Python is a free, open-source scripting language. It is mainly used in Web applications, primarily to handle CGI scripting tasks. It is also powerful enough to interact with C++ and Java software components, able to combine large applications.
16
Lecture 1716 Native Data Types Numbers (includes integer, float, etc.) String (typical implementation) List (mutable list of objects) Tuple (immutable list of objects) Dictionary (index-referenced object list)
17
The Glade Minilanguage A GTK+ User Interface Builder By Robert Reach
18
Lecture 1718 Glade Development Glade is an interface builder for the open-source GTK toolkit library for X. Glade allows you to develop a GUI interface by interactively picking, placing, and modifying widgets on an interface panel. The GUI editor produces an XML file describing the interface; this, in turn, can be fed to one of several code generators that will actually grind out C, C++, Python or Perl code for the interface. The generated code then calls functions you write to supply behavior to the interface. Glade possesses the transparency and simplicity indicative of a good minilanguage.
19
Lecture 1719 Pros and Cons Pros o The advantage of Glade is that it specializes in code generation. o This makes it possible to program without so much worry about bugs that you could possibly have from hand coding. o It also saves a lot of time. Cons o Because Glade uses XML, it is extremely verbose and consequently it is difficult to have a "small" program that does something useful. o Links: ScreenshotExample Program (a port scanner)ScreenshotExample Program (a port scanner)
20
Lecture 1720 Objectives What is logic, specifically, first order logic How logic programming is related to first order logic How Prolog embodies logic programming Introduction to using Prolog
21
Lecture 1721 Prolog PROgramming in LOGic Algorithm = Logic + Control Logic = relation R(I,O) between input I and output O Control = method of searching for O that satisfies R(I,O), given input I E.g. Find X and Y such that 3*X+2*Y=1 X-Y=4 E.g. find array B such that elements in B are the same as those in A elements of B are in non-descending order
22
Lecture 1722 What is Prolog Prolog is a ‘typeless’ language with a very simple syntax. Prolog is declarative: you describe the relationship between input and output, not how to construct the output from the input (“specify what you want, not how to compute it”) Prolog uses a subset of first-order logic
23
Lecture 1723 Classical First-Order Logic simplest form of logical statements is an atomic formula. e.g. man(tom) woman(mary) married(tom,mary) More complex formulas can be built up using logical connectives: , , , , X, X Pair Up: Define each of these symbols
24
Lecture 1724 Examples of First Order Logic smart(tom) dumb(tom) smart(tom) tall(tom) dumb(tom) X married(tom,X) X loves(tom,X) X [married(tom,X) female(X) human(X)] rich(tom) smart(tom) X mother(john,X) X Y [mother(john,X) mother(john,Y) Y=X] Note: A B B A
25
Lecture 1725 Logic programming is based on formulas called Horn rules. These have the form Examples: X,Y[A(X) B(X,Y) C(Y)] X[A(X) B(X)] X[A(X,d) B(X,e)] A(c,d) B(d,e) X A(X) X A(X,d) A(c,d) Horn Rules
26
Lecture 1726 Horn Rules (cont.) Note that atomic formulas are also Horn rules, often called facts. A set of Horn rules is called a Logic Program.
27
Lecture 1727 Logical Inference with Horn Rules Logic programming is based on a simple idea: From rules and facts, derive more facts. Example 1. Given the facts and rules: 1. A 2. B 3. C 4. E A B 5. F C E 6. G E F From 1, derive E; from 2, derive F; from 3, derive G.
28
Lecture 1728 Logical Inference Example 2: Given these facts: man(plato) man(socrates) and this rule: X [mortal(X) man(X)] derive: mortal(plato), mortal(socrates).
29
Lecture 1729 Recursive Inference Example, given (1) X[mortal(son_of(X)) mortal(X)] (2) mortal(plato) derive: mortal(son_of(plato)) (using X=plato) mortal(son_of(son_of(plato))) (using X=son_of(plato)) mortal(son_of(son_of(son_of(plato)))) (using X=son_of(son_of(plato)))
30
Lecture 1730 Prolog Notation A rule: X [p(X) (q(X) r(X))] is written as p(X) q(X), r(X). Prolog conventions: variables begin with upper case (A, B, X, Y, Big, Small, ACE) constants begin with lower case (a, b, x, y, plato, aristotle) Query = list of facts with variables, e.g. mortal(X) sorted([5,3,4,9,2], X) sonOf(martha,S), sonOf(george,S) Prolog program = facts+rules+query
31
Lecture 1731 Prolog Syntax . :-. . | | | ( ) |,
32
Lecture 1732 Constructors like student and “.” are called functors in Prolog Syntax Integers Atoms: user defined, supplied name starts with lower case: john, student2 Variables begin with upper case: Who, X ‘_’ can be used in place of variable name Structures student(ali, freshman, 194). Lists [x, y, Z ] [ Head | Tail ] syntactic sugar for. ( Head, Tail ) [ ]
33
Lecture 1733 Prolog Introduction /* list of facts in prolog, stored in an ascii file, ‘family.pl’*/ mother(mary, ann). mother(mary, joe). mother(sue, mary). father(mike, ann). father(mike, joe). grandparent(sue, ann).
34
Lecture 1734 Prolog Introduction (cont.) /* reading the facts from a file */ ?- consult ( family). %family compiled, 0.00 sec, 828 bytes Comments are either bound by “/*”,”*/” or any characters following the “%”. Structures are just relationships. There are no inputs or outputs for the variables of the structures. The swipl documentation of the built-in predicates does indicate how the variables should be used. pred(+var1, -var2, +var3). + indicates input variable - indicates output variable
35
/* Prolog the order of the facts and rules is the order it is searched in */ /* Variation from pure logic model */ 2 ?- father( X, Y ). X = mike /* italics represents computer output */ Y = ann ; /* I type ‘;’ to continue searching the data base */ X = mike Y = joe ; no 3 ?- father( X, joe). X = mike ; no
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.