Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 403: Programming Languages Lecture 16 Fall 2003 Department of Computer Science University of Alabama Joel Jones.

Similar presentations


Presentation on theme: "CS 403: Programming Languages Lecture 16 Fall 2003 Department of Computer Science University of Alabama Joel Jones."— Presentation transcript:

1 CS 403: Programming Languages Lecture 16 Fall 2003 Department of Computer Science University of Alabama Joel Jones

2 Lecture 162 Overview Announcements

3 M4 Macro Processor Geoffrey Haynes

4 Lecture 164 m4 is a general purpose macro processor that can be used to preprocess C and assembly language programs, among other things. Besides the straightforward replacement of one string of text by another, m4 lets you perform integer arithmetic file inclusion conditional macro expansion string and substring manipulation

5 Lecture 165 You can use built-in macros to perform these tasks or define your own macros. Built-in and user-defined macros work exactly the same way except that some of the built-in macros have side effects on the state of the process. The basic operation of m4 is to read every legal token (string of ASCII letters and digits and possibly supplementary characters) and determine if the token is the name of a macro. The name of the macro is replaced by its defining text, and the resulting string is pushed back onto the input to be rescanned. Macros may be called with arguments. The arguments are collected and substituted into the right places in the defining text before the defining text is rescanned.

6 A small review of Python Jesse Booth Named after Monty Python Released to public in 1991 Syntax: cross between C and the Modula family

7 Lecture 167 Why Use Python? Simple Syntax Easy to learn and quick to code Portable between Unixes and even other operating systems Large Standard Library Used for large complex projects with many different developers

8 Lecture 168 Why is Python different? Choice of Object-oriented programming Block structure is controlled by actual indentation not brackets Easy to combine with C for performance- critical applications Substantial speed gains

9 Lecture 169 Python Bin Qiao  Python is a scripting language designed for close integration with C. Its syntax is rather like a cross between that of C and the Modula family.  It has a type system comparable in expressive power to Perl’s.  Python is generally thought to be the least efficient and slowest of the major scripting languages.

10 Lecture 1610 Considerations of Using Python  Programmability. Python is well suited to functioning as a glue language which is commonly used to implement the lower level operations.  Prototyping. Python provides a good environment for quickly developing an initial prototype.  Simplicity and ease of understanding. Python is powerful but very simple, which lets you learn the language more quickly, and then rapidly write code.  Java integration. Jython is a re-implementation of Python in Java that complies Python codes into Java bytecodes. The resulting environment has very tight, almost seamless, integration with Java.

11 Ruby Robert Bradford What is Ruby?  Ruby is a new object oriented programming language.  Though rarely used in the United States, it has become very popular in other areas of the world. What are the advantages to using Ruby as a language?  Features similar to Perl o Process text files o Perform system management tasks  Few lines of code, but not cryptic  Syntax and semantics are simple  Ruby is open source  Platform independent… can be used on Windows, Unix or Linux created by: Yukihiro Matsumoto

12 Lecture 1612 Features  Simple syntax  Error handling  Blocks in syntax o Surrounded by either { } or do … end o Can be passed to methods  Integers can be used without counting internal representation  No variable declarations, naming conventions denote scope o 'var' = local variable o '@var' = instance variable o '$var' = global variable

13 Lecture 1613 Code Analysis  First… a definition of Fibonacci o The basic Fibonacci series is a sequence of integers, starting with two 1's, in which each subsequent term is the sum of the two preceding terms. The series is sometimes used in sorting algorithms and in analyzing natural phenomena.  Demonstrated by this example: o Parallel assignment o Local variable creation o Looping structure o Function definition o Output

14 Tool Command Language (Tcl) By: Steven Kemp

15 Lecture 1615 What is Tcl? Tcl is a small language interpreter that can be linked with compiled C libraries. It can also be used for embedded scripts, which are scripts that are called from C programs. It was first released publicly in 1990.

16 Lecture 1616 Advantages of Tcl It is extremely flexible and radically simple. It has a totally consistent syntax. The interpreter itself can be redefined from within Tcl. It’s compact design makes it more efficient for smaller projects

17 Lecture 1617 Minor Disadvantages of Tcl The only data structure is association lists Not good for use on large programs Syntax is slightly odd, even though it is consistant

18 Lecture 1618 Java Eric Jackson Developed by Sun Microsystems Created to be “write once, run anywhere” Automatically handles memory management. Can inherit from just about anything. Easy to learn. Style very similar to C and C++ MySet.java code to implement Set ADT

19 Brad Hutchinson PHP  Open source, server-side, HTML embedded scripting language used to create dynamic web pages.  Created in 1994, but during mid 1997 the development changed hands and the parser was rewritten from scratch to create PHP version 3.  Syntax is similar to that of Perl or C++.  The script is enclosed within special PHP tags, and because PHP is embedded within tags it is possible to jump between HTML and PHP.  This prevents having to actually write large amounts of HTML code using PHP.  Since it is executed on the server, the script cannot be viewed by someone accessing the web page.  Can perform any task that any CGI program can do, but its strength lies in its compatibility with many types of databases.  Can talk across networks using IMAP, SNMP, NNTP, POP3, or HTTP.

20 Little Ruby? Big Ruby? What is Ruby? Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, extensible, and portable. The Creator of Ruby Yukihiro Matsumoto, a.k.a Matz matz@netlab.jpmatz@netlab.jp R. Allen Sanford

21 Lecture 1621 Features of Ruby Ruby has simple syntax, partially inspired by Eiffel and Ada. Ruby has exception handling features, like Java or Python, to make it easy to handle errors. Ruby's operators are syntax sugar for the methods. You can redefine them easily. Ruby is a complete, full, pure object oriented language: OOL. This means all data in Ruby is an object. Ruby's OO is carefully designed to be both complete and open for improvements. Ruby features single inheritance only, *on purpose*. Ruby features blocks in its syntax (code surrounded by '{'... '}' or 'do'... 'end'). These blocks can be passed to methods, or converted into closures. Ruby features a true mark-and-sweep garbage collector. It works with all Ruby objects. You don't have to care about maintaining reference counts in extension libraries. This is better for your health. ;-) Writing C extensions in Ruby is easier than in Perl or Python, due partly to the garbage collector, and partly to the fine extension API. SWIG interface is also available. Integers in Ruby can (and should) be used without counting their internal representation. Ruby needs no variable declarations. It uses simple naming conventions to denote the scope of variables. Examples: simple 'var' = local variable, '@var' = instance variable, '$var' = global variable. So it is also not necessary to use a tiresome 'self.' prepended to every instance member. Ruby can load extension libraries dynamically if an OS allows. Ruby features OS independent threading. Thus, for all platforms on which Ruby runs, you also have multithreading, regardless of if the OS supports it or not, even on MS-DOS! ;-) Ruby is highly portable: it is developed mostly on Linux, but works on many types of UNIX, DOS, Windows 95/98/NT, Mac, BeOS, OS/2, etc. R. Allen Sanford Information obtain from http://www.ruby-lang.org/en/ http://www.ruby-lang.org/en/

22 Lecture 1622 Documentation All of the Previous information and more can be found at: http://www.ruby-lang.org/en/ Other useful links are: Great intro to ruby! http://www.math.umd.edu/~dcarrera/ruby/0.3/ Ruby, Gui’s, and Tk toolkit. http://httpd.chello.nl/k.vangelger/ruby/learntk/ Demonstration on generating html templates using ruby. http://www.hillmanimages.com/912/tutor01.html R. Allen Sanford

23 Lecture 1623 Ruby Charles B. Ward Ruby is an interpreted language, similar in a number of ways to perl, php, and python. Ruby is an purely object oriented programming language, like Smalltalk. Everything is an object, including numbers. Ruby is *not* strongly typed. Ruby features only single-inheritance, instead allowing classes to import modules of methods. Ruby has automatic memory management (garbage collector).

24 Lecture 1624 More Ruby Ruby naming conventions to denote the scope of variables. 'var' = local variable '@var' = instance variable '$var' = global variable. Ruby supports internal threading. (programs can be multithreaded independently of the operating system) Ruby is compatible with LINUX, UNIX, DOS, Windows 95/98/NT, Mac, BeOS, OS/2, etc.

25 TCL (Tool Command Language) Charles Lemont Howard developed mainly by John Ousterhout

26 Lecture 1626 Pros and Cons of TCL PROS It is a high-level scripting language ~ lot less code to write to get job done It runs on many platforms It is interpreted ~ execute code without compiling and linking It is extensible It is embeddable in your applications ~ meaning you can use TCL as an application language terrific language for database applications Tcl is free CONS TCL is interpreted ~ programs written in TCL are slow because TCL only deals with strings Syntax checking only at runtime

27 Fundamental aspects of the Ruby programming language Kunal Vyas

28 Lecture 1628 About Ruby Yukihiro Matsumoto (Matz), a professional programmer working for and open source company in Japan (netlab.co.ip) invented the Ruby programming language. Ruby is a "pure Object Oriented Language". Everything in Ruby is an object Ruby uses pass-by-reference. Ruby also supports default formal argument assignment

29 Lecture 1629 Ruby's features are as follows: Interpretive Variables have no type (dynamic typing) No declaration needed Simple syntax No user-level memory management Everything is object Class, inheritance, methods Singleton methods Mix-in by modules Iterators Closures Text processing and regular expression Bignums Dynamic loading Exception handling

30 Lecture 1630 What made ruby different from other Programming Languages Language:Ruby Added:Ruby Took Away: C *Operator overloading Object OrientationIn light of the fact that C is the defining language for Ruby and Ruby is extendable using C, all the functionality of C is supported. Smalltalk *Object Orientation *Everything is an object! 1.Multiple Inheritance. 2. Ruby isn't as strict as Smalltalk with regard to object, inheritance and class hierarchy

31 Lecture 1631 Continue Language:Ruby Added:Ruby Took Away: Perl *Scripting Power 1. Clean Object Orientation - Ruby was initially designed with OO in mind, whereas Perl was extended to support objects. 1.Scope rules in Ruby (default: local) eliminate the need for any 'my' declarations. 2. Ruby eliminates a lot of Perl's syntax sugar without losing functionality making Ruby less cryptic.

32 Lecture 1632 Continue Language:Ruby Added:Ruby Took Away: Python *Exception Handling 1. Exception handling 2. Type coercion between small and long integers 3. Mark and sweep garbage collection instead of a Ref-counter garbage collection. 4. Inheritance / subclassing 1. Ruby's instance variables are prefixed by a at eliminating the need for 'self' declarations. 2. Python treats types and classes differently, Ruby treats them the same. 3. Tuples

33 Lecture 1633 Continue Language:Ruby Added:Ruby Took Away: Eiffel *Object orientation and simple syntax Ruby is interpretedCompilation is not Required for Ruby. Lisp * Lambda expressions Object OrientationAll those Parentheses

34 Lecture 1634 For what applications would this language be suitable? Text processing CGI programming Network programming XML programming GUI applications AI and Exploratory Mathematics General programming Prototyping Programming education eXtreme programming

35 Lecture 1635 For what would it not be suitable? High traffic web applications Operating systems implementation Compiler implementation

36 Ruby André Taylor “The object oriented scripting language” André Taylor

37 Lecture 1637 Introduction  Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, extensible, and portable.  Ruby is highly portable: it is developed mostly on Linux, but works on many types of UNIX, DOS, Windows 95/98/NT, Mac, BeOS, OS/2, etc. André Taylor

38 Lecture 1638 Important features  Ruby has simple syntax, partially inspired by Eiffel and Ada.  Ruby has exception handling features, like Java or Python, to make it easy to handle errors.  Ruby features a true mark-and-sweep garbage collector. It works with all Ruby objects. You don't have to care about maintaining reference counts in extension libraries. This is better for your health. ;-) André Taylor

39 Lecture 1639 Important features cont.  Ruby needs no variable declarations.  Examples:  'var' = local variable  '@var' = instance variable  '$var' = global variable.  Ruby features blocks in its syntax (code surrounded by '{'... '}' or 'do'... 'end'). These blocks can be passed to methods, or converted into closures. André Taylor

40 Lecture 1640 Tcl/Tk David Marshall Tcl (Tool Command Language) Created in 1989 by John Ousterhout An interpreted language with the main purpose of integrating or tying together other applications Tk An extension of Tcl created for component- based GUI design

41 Lecture 1641 Features of Tcl/Tk Extensible – Easy to add your own features Designed so that added features feel as natural as the basic features of the language Embeddable – I nterpreter exists as C Library GUI building with Tk toolkit Extremely fast to design and implement a GUI out of components provided by Tk Cross Platform Runs on Windows, Mac, and Unix platforms

42 Lecture 1642 Tcl Compared Often compared to Perl Syntax is much simpler than Perl and has less of a learning curve Easier to maintain – Perl syntax is much more complex, so reading and maintaining Tcl code is an easier task Tk is available for Perl, but is less intuitive and clumsier because it was designed for Tcl More information available at http://www.tcl.tk

43 Bash, XSLT, Dot, and C Nathan Wiegand What to do with all those tools?

44 Lecture 1644 Bash The Bourne Again SHell - Created by Ritchie and Thompson from the Bourne Shell(sh). Designed in order for people to better communicate with the system they were developing at AT&T

45 Lecture 1645 XSLT eXtensible Stylesheet Language Transform Used to translate XML (eXtensible Markup Language) into another format (e.g. HTML, Word File, Dot)

46 Lecture 1646 Dot Open graph drawing software developed at AT&T Used to present datastructures and other things which can be represented as graphs (i.e. file trees)

47 Lecture 1647 File Tree Viewer Start with a Bash script which walks your file tree and creates and XML file from the files it observes. Next, use an XSL Transform to convert that XML document into a Dot Script. Use Dot to convert this script into a nice Gif image for viewing.

48 Lecture 1648 The Bash Script #!/bin/bash dir=$(pwd) function dirExp { echo " " cd "$1/$2" for i in $(ls -l -1 | grep ^- | gawk '{print $9}') do VAL=$($dir/conv $(ls -l -1 $i | gawk '{print $1}')) if [ $(($VAL/100)) = 7 ]; then color="green" else color="white" fi echo " " done for i in $(ls -l -1 | grep ^d | gawk '{print $9}') do dirExp "$1/$2" $i done echo " " } dirExp $dir. > "$dir/dir.xml" cd $dir xsltproc -o structure.dot graph.xsl dir.xml dot -Tgif -o structure.gif structure.dot mv structure.gif ~/public_html

49 Lecture 1649 The C file #include int main (int argc, char *argv[]) { int perm[3], i; if(argc!=2) fprintf(stderr,"Error\n"); for(i=1,perm[0]=perm[1]=perm[2]=0;i<strlen(argv[1]);i++) { perm[(i-1)/3]*=2; if(argv[1][i]!='-') perm[(i-1)/3]++; } fprintf(stdout,"%d%d%d\n",perm[0],perm[1],perm[2]); return 0; }

50 Lecture 1650 The Produced XML

51 XSLT <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> digraph treestruct { } " ",shape=<xsl:value-of select="@s"/>,style=filled,fillcolor= [label= ]; -> ;

52 Lecture 1652 Excerpt of the Dot file digraph treestruct { id2588904 [label=".",shape=box,style=filled,fillcolor=red]; id2588904 -> id2588686; id2588904 -> id2587734; id2588904 -> id2587745; id2588904 -> id2587755; id2588904 -> id2588236; id2588904 -> id2588246; id2588904 -> id2588257; id2588904 -> id2588267; id2588904 -> id2588406; id2588686 [label="conv",shape=ellipse,style=filled,fillcolor=green]; id2587734 [label="conv.c",shape=ellipse,style=filled,fillcolor=white]; id2587745 [label="dir.xml",shape=ellipse,style=filled,fillcolor=white];

53 Lecture 1653 The Product


Download ppt "CS 403: Programming Languages Lecture 16 Fall 2003 Department of Computer Science University of Alabama Joel Jones."

Similar presentations


Ads by Google