Download presentation
Presentation is loading. Please wait.
Published byAsher Lawson Modified over 8 years ago
1
Programming Languages Meeting 12 November 18/19, 2014
2
Short Exam Results Computer programming requires precise notation: Missing ; Wrong case Mismatched parentheses There were many sloppy answers to questions. The reprise on the next slides gives you the opportunity to be precise.
3
Short Exam Reprise Submit by Friday, November 20, 2014, no later than 5:00 p.m. a text file attached to an email message containing the implementation in Lisp using our development rules of the functions: reverse concat IG
4
Short Exam Answers
5
GetFloat Project Code checked – Comments – getc implemented – getfloat implemented – input file specification Output checked – File of correct floats – File of floats with line numbers – File of floats mingled with character strings – File with no floats, but some look temptingly good
6
Matrix Project Helpfulness of LispWorks – Bug when functions are redefined – Solution: Define myfirst, mylast Primitives and functionals submitted? Questions?
7
Preparations for Tonight Unix cluster access?
8
Scripting Languages Originally, tools for – Quick, dirty programs – Rapid prototyping for text-based computation – Glue between other programs – File format conversion Evolved to mainstream programming tools – Check current estimates on the number of lines of Javascript code doing productive work
9
Characteristics Strings as the basic, maybe only, data type Associative arrays (hashes?) as the basic structured data type Regular expressions as a principle programming structure Minimal use of types and declarations Usually interpreted rather than compiled
10
Examples Unix shell AWK Perl Python Tcl Javascript VBScript, Jscript PHP
11
Our Approach Look at AWK and Perl first Determine the syntactical structure of each language, starting with AWK Use experimentation to discover the semantics Work several exercises on each language during class time
12
AWK Age: 38 years Developed at Bell Labs by Al Aho, Brian Kernighan, Peter Weinberger – Aside: Where are each of these computing pioneers now? Intended for simple manipulation of, and data extraction, from text files – 38 years ago data existed in text files almost exclusively
13
AWK Examples Print all lines longer than 80 characters. length > 80 Replace the second field in each line by its logarithm. { $2 = log($2); print } Add up the numbers in the first field and report the sum and average. { sum += $1 } END { print sum, sum/NR }
14
AWK Syntax ::= [ ] [ ] ::= { } ::= | { } | { } ::= BEGIN { } ::= END { }
15
Heart of AWK – A regular expression – A numeric expression – A combination of the previous two – Executable code, similar in structure to C
16
Inferred Control Structure Previous languages: sequence – Execute S1, then S2, then S3, … AWK: a triply nested for-loop surrounding an if-then. Specifically for each file for each input line for each pattern if pattern matches input line then action
17
Program Development Use your favorite text editor to create an AWK program file. Run the program awk –f myprog [file1 file2 … ] OR for really short programs (one line) awk ‘program’ [file1 file2 …]
18
Some Interesting Data From the course website, under Resources, download the four data files – Flight Aware data – Moby Dick extract – Web form data – Classic AWK data on countries (these data come from the 1985 AWK manual)
19
Some AWK Programs Try each of these programs using flightaware.txt as the input file { print NR, $0 } { $1 = NR; print } Note that is surrounded by { } and may consist of several statements separated by ;
20
More Programs {print $NF} /Cancelled/ END {print NR}
21
AWK Built-Ins NF – number of fields on a line NR – number of lines (records) in a file, actually the number of the current line read in the file $k – name of the k th field, count starts at 1 $0 – name of the current line FILENAME – name of current input file
22
More Built-Ins FS – field separator, typically reset in the BEGIN action if something other than space is needed OFS – output field separator RS – record separator ORS – output record separator OFMT – output format
23
Your Turn Write AWK programs to: 1.Determine how many flights were cancelled 2.Find the latest arriving flight from those in the list 3.List the different aircraft used for this flight number.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.