Jerzy Nawrocki, Introduction to informatics

Size: px
Start display at page:

Download "Jerzy Nawrocki, Introduction to informatics"

Transcription

1 Jerzy Nawrocki Faculty of Computing & Information Sci. Poznan University of Technology File conversion problem FName:John SName:Great Salary 585 Text processing and AWK FName:Ann SName:Nice Salary 7 FName SName Salary John Great 585 Ann Nice 7 Text processing & AWK (2) File conversion problem File conversion problem #include <stdio.h> #include <stdlib.h> FILE *fin; char token[2]; char gettoken(void) {int i=; char c; do {c = getc(fin); if (c == EOF) return (EOF); } while (c <! ); Solution in C: 4 lines of code Text processing & AWK (3) Solution in AWK BEGIN {FS=": ";} NR == 1 {print $1, "\t", $3, "\t", $5;} {gsub(/,/, "., $6); print $2, "\t", $4, "\t", $6;} Text processing & AWK (4) Origins of AWK Authors of AWK Bell Labs, Murray Hill (New Jersey), Foto: Bell Labs, New Jersey (USA), 1977 AWK: Aho, Weinberger, Kernighan Platforms: Unix, MS DOS/Windows Similarity to C Text processing & AWK (5) Alfred Aho Peter Weinberger Brian Kernighan Text processing & AWK (6) Text processing and AWK 1

2 Aim of the lecture Agenda To present: Another programming paradigm (rule-based programming) Basics of AWK Fundamentals of AWK Simplest programs Patterns Variables Text processing & AWK (7) Text processing & AWK (8) Fundamental question Input file What is text? Field Jerzy Nawrocki 4389 I1 Jane Kowalski 4378 I2 Line Fields: $1, $2, $3,... Text processing & AWK (9) Text processing & AWK (1) Program structure Execution principle pattern1 {instruction1} pattern2 {instruction2} Processing rule Jerzy Nawrocki Jane Kowalski Adam Malinowski pattern1 {instruction1} pattern2 {instruction2} Text processing & AWK (11) Text processing & AWK (12) Text processing and AWK 2

3 Agenda Simplest programs Fundamentals of AWK Simplest programs Patterns Variables How many fields on the output? Jerzy Nawrocki 4389 I1 Jane Kowalski 4378 I2 $4== I1 { print $2, $1; } Nawrocki Jerzy Malinowski Adam Text processing & AWK (13) Text processing & AWK (14) Simplest programs Simplest programs How many fields on the output? Jerzy Nawrocki 4389 I1 Jane Kowalski 4378 I2 What field will be first? Jerzy Nawrocki 4389 I1 Jane Kowalski 4378 I2 $4== I1 { print $2, $1; } Jerzy Nawrocki 4389 I1 Nawrocki Jerzy Kowalski Jane Malinowski Adam Text processing & AWK (15) Text processing & AWK (16) Agenda Patterns Fundamentals of AWK Simplest programs Patterns Variables Begining and end of text Relations Compound patterns Range patterns Text processing & AWK (17) Text processing & AWK (18) Text processing and AWK 3

4 Begining and end of text Begining and end of text Jerzy Nawrocki Jane Kowalski BEGIN { print ; } $4== I2 { print $2, $1; } END { print ***** ; } Kowalski Jane ***** 4389 I I2 Text processing & AWK (19) Jerzy Nawrocki Jane Kowalski END { print ***** ; } $4== I2 { print $2, $1; } BEGIN { print ; } Kowalski Jane ***** 4389 I I2 Text processing & AWK (2) Relations Compound patterns $1 > $ or $1==1 $2==1 && and $1==1 && $2==1! not! $1==1 Text processing & AWK (21) Text processing & AWK (22) Compound patterns Agenda Jerzy Adam 4389 I1 Adam Kowalski 4378 I2 $4== I1 && $1== Adam { print $2, $1; } Fundamentals of AWK Simplest programs Patterns Variables Malinowski Adam Text processing & AWK (23) Text processing & AWK (24) Text processing and AWK 4

5 Stephen Kleene , Connecticut, USA 1934: Dr, Princeton Univ., (Alonzo Church) 1935: Univ. of Wisconsin- Madison (USA) : Inst. for Advanced Study, Princeton recursion theory 199: National Medal of Sci , Madison Text processing & AWK (25) Regular expressions Arithmetic expressions Value: Text Number Value( ) = 9 Regular expressions Value: Text SetOfCharacterStrings Value(/Ala Ola/) = {"Ala", "Ola"} Text processing & AWK (26) $, $1, $2,.. $, $1, $2,.. Begining String ~ /^ reg_exp / $1 ~ /^I$/ $1 ~ /^I/ Text processing & AWK (27) Text processing & AWK (28) $, $1, $2,.. $, $1, $2,.. Begining String ~ /^ reg_exp / End String ~ / reg_exp $/ $3 ~ /e$/ Begining String ~ /^ reg_exp / End String ~ / reg_exp $/ Substring String ~ / reg_exp / $3 ~ /e/ Text processing & AWK (29) Text processing & AWK (3) Text processing and AWK 5

6 $, $1, $2,.. $, $1, $2,.. Begining String ~ /^ reg_exp / End String ~ / reg_exp $/ Substring String ~ / reg_exp / $ ~ /ne/ Text processing & AWK (31) Begining String ~ /^ reg_exp / End String ~ / reg_exp $/ Substring String ~ / reg_exp / $ ~ / wyr_reg / = / wyr_reg / /ne/ Text processing & AWK (32) Special characters Special characters. Any character [ ] Set of characters \n New line \. Dot \ Quotation \ddd Character of octal code = ddd What does it mean? /^.$/ /[ ]/ /[-9]/ Text processing & AWK (33) Text processing & AWK (34) Complement of a set of characters Disjunction (or) reg_exp reg_exp What s the difference? [^... ] /[^-9]/ /^[-9]/ /im in/ Text processing & AWK (35) Text processing & AWK (36) Text processing and AWK 6

7 Parentheses and disjunction Parentheses change precedence of operators: 3*(4 + 5) = 3* 9 = 27 Distributive law: 3*(4 + 5) = 3*4 + 3*5 = = 27 (4 + 5)*3 = 4*3 + 5*3 = = 27 Select all lines for which the first field is a number AD 1984 $1 ~ /[-9]/ Distributivity of concatenation over disjunction: /i(m n)/ = /Lond(o y)n/ = /im in/ /London Londyn/ Text processing & AWK (37) Text processing & AWK (38) Select all lines for which the first field is a number tune: AD cents Select all lines for which the first field is a 1-digit number tune: 4tune: AD cents 32 cents $1 ~ /[-9]/ $1 ~ /^ [-9] $/ tune: 2 cents Text processing & AWK (39) Text processing & AWK (4) Select all lines for which the first field is a 1- or 2-digit number tune: 4tune: AD cents 32 cents Select all lines for which the first field is a 1- or 2-digit number tune: 4tune: 4tune: AD cents 32 cents 32 cents 12 euro $1 ~ /^( [-9] [-9][-9] )$/ $1 ~ /^( [-9] [-9][-9] )$/ 1 digit 2 digits cents 32 cents Text processing & AWK (41) Text processing & AWK (42) Text processing and AWK 7

8 $1 ~ /^( [-9] [-9][-9] [-9][-9][-9] )$/ Select all lines for which the first field is a number tune: 4tune: 4tune: AD cents 32 cents 32 cents 12 euro 1 digit 2 digits 3 digits [-9] = [-9] 1 [-9][-9] = [-9] 2 [-9][-9][-9] = [-9] [-9] 1 [-9] 2 [-9] 3... = [-9]+ Text processing & AWK (43) Text processing & AWK (44) $1 ~ /^ [-9]+ $/ Select all lines for which the first field is a number tune: 4tune: 4tune: AD cents 32 cents 32 cents 12 euro cents 32 cents 32 cents 12 euro Text processing & AWK (45) A non-empty sequence Can be a of w s. sequence of w s. w+ = w ww Empty string w* = w ww x = x x = x w+ = w w* = w* w x w* = x x w+ w*x = x w+x w( w ww )= w ww www wwww.. Text processing & AWK (46) Riddle Riddle What s its meaning? What on the output? Payment 21/11 ================ Nawrocki 16 Antczak 359 $2 ~ /^[-9][-9]*$/ $2 ~ /^[-9]+$/ Text processing & AWK (47) Text processing & AWK (48) Text processing and AWK 8

9 Agenda Variables Fundamentals of AWK Simplest programs Patterns Variables Variables introduced by a programmer (type: string of characters; initial value: empty string / zero) Built-in variables (standard meaning) Field variables $1, $(i+j-1),.. Text processing & AWK (49) Text processing & AWK (5) Some built-in variables NF number of fields in a row NR row number FILENAME file name with input data NR NF total Variables If you have a hammer, everything looks like a nail {total= total + NF;} END {print "Fields: ", total; print "Rows: ", NR;} Text processing & AWK (51) Text processing & AWK (52) Input file Summary Field Jerzy Nawrocki 4389 I1 Jane Kowalski 4378 I2 Line Fields: $1, $2, $3,... Text processing & AWK (53) Text processing & AWK (54) Text processing and AWK 9

10 Program structure Execution principle pattern1 {instruction1} pattern2 {instruction2} Processing rule Jerzy Nawrocki Jane Kowalski Adam Malinowski pattern1 {instruction1} pattern2 {instruction2} Text processing & AWK (55) Text processing & AWK (56) Regular expressions Summary (1)* = {ε, 1, 11, 111, } ε x = x ε L 1 L 2 = {xy: x L 1 y L 2 } L (r) = { ε } L n+1 (r) = L(r) L n (r) L n (r) = {xx x: x L(r) } n L(r*) = U L n (r) n= L(r*) = {ε,x, xx, xxx, : x L(r)} Text processing & AWK (57) At last! gawk -f prog.awk <in.txt >out.txt Other features of AWK: Compound instructions (if, while,..) Dynamic arrays Built-in functions (gsub,..) Text processing & AWK (58) Literature A. Aho, B. Kernighan, P. Weinberger, The AWK Programming Language, Addison-Wesley, Reading, J. Nawrocki, W. Complak, Wprowadzenie do przetwarzania tekstów w języku AWK, Pro Dialog 2 (1994), J. Cybulka, B. Jankowska, J.R. Nawrocki, Automatyczne przetwarzanie tekstów. AWK, Lex i YACC, Nakom, Poznań, 22. Text processing & AWK (59) Thank you for your attention! Text processing & AWK (6) Text processing and AWK 1

AWK: The Duct Tape of Computer Science Research. Tim Sherwood UC Santa Barbara

AWK: The Duct Tape of Computer Science Research. Tim Sherwood UC Santa Barbara AWK: The Duct Tape of Computer Science Research Tim Sherwood UC Santa Barbara Duct Tape Systems Research Environment Lots of simulators, data, and analysis tools Since it is research, nothing works together

More information

awk A UNIX tool to manipulate and generate formatted data

awk A UNIX tool to manipulate and generate formatted data awk A UNIX tool to manipulate and generate formatted data Alexander Voigt Technische Universität Dresden Institut für Kern- und Teilchenphysik Version_05_21 /01234/546 78994: IKTP Computing Kaffee 10 January

More information

Lex The Idea Program Structure What Lex does Using Lex Lex Operators States in Lex

Lex The Idea Program Structure What Lex does Using Lex Lex Operators States in Lex Lex The Idea Program Structure What Lex does Using Lex Lex Operators States in Lex The Lex Idea Lex is an implementation that uses an extension of RE notation as well as states and C/C++ Extending REs

More information

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013 CMPSCI 250: Introduction to Computation Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013 Regular Expressions and Their Languages Alphabets, Strings and Languages

More information

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print In the simplest terms, grep (global regular expression print) will search input

More information

Automating tasks through scripting. HPC Certificate Program

Automating tasks through scripting. HPC Certificate Program Automating tasks through scripting HPC Certificate Program Summary of preparation lectures From "The Shell" at Software Carpentry: Lecture 4: Pipes and Filters The redirect operator saves command output

More information

Regular Languages and Finite Automata

Regular Languages and Finite Automata Regular Languages and Finite Automata 1 Introduction Hing Leung Department of Computer Science New Mexico State University Sep 16, 2010 In 1943, McCulloch and Pitts [4] published a pioneering work on a

More information

CS F-02 Formal Languages 1

CS F-02 Formal Languages 1 CS411 2015F-02 Formal Languages 1 02-0: Alphabets & Strings An alphabetσis a finite set of symbols Σ 1 = {a, b,..., z} Σ 2 = {0, 1} A string is a finite sequence of symbols from an alphabet fire, truck

More information

COS 333: Advanced Programming Techniques

COS 333: Advanced Programming Techniques COS 333: Advanced Programming Techniques How to find me bwk@cs, www.cs.princeton.edu/~bwk 311 CS Building 609-258-2089 (but email is always better) TA's: Stephen Beard, Chris Monsanto, Srinivas Narayana,

More information

Automata Theory and Languages

Automata Theory and Languages Automata Theory and Languages SITE : http://www.info.univ-tours.fr/ mirian/ Automata Theory, Languages and Computation - Mírian Halfeld-Ferrari p. 1/1 Introduction to Automata Theory Automata theory :

More information

C H A P T E R Regular Expressions regular expression

C H A P T E R Regular Expressions regular expression 7 CHAPTER Regular Expressions Most programmers and other power-users of computer systems have used tools that match text patterns. You may have used a Web search engine with a pattern like travel cancun

More information

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy Kim S. Larsen Odense University Abstract For many years, regular expressions with back referencing have been used in a variety

More information

Compiler I: Syntax Analysis Human Thought

Compiler I: Syntax Analysis Human Thought Course map Compiler I: Syntax Analysis Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy Translator Chapters 7-8 Assembly

More information

C programming. Intro to syntax & basic operations

C programming. Intro to syntax & basic operations C programming Intro to syntax & basic operations Example 1: simple calculation with I/O Program, line by line Line 1: preprocessor directive; used to incorporate code from existing library not actually

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Introduction to Lex. General Description Input file Output file How matching is done Regular expressions Local names Using Lex

Introduction to Lex. General Description Input file Output file How matching is done Regular expressions Local names Using Lex Introduction to Lex General Description Input file Output file How matching is done Regular expressions Local names Using Lex General Description Lex is a program that automatically generates code for

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

Definition: String concatenation. Definition: String. Definition: Language (cont.) Definition: Language

Definition: String concatenation. Definition: String. Definition: Language (cont.) Definition: Language CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata Introduction That s it for the basics of Ruby If you need other material for your project, come to office hours or

More information

Lecture 5. sed and awk

Lecture 5. sed and awk Lecture 5 sed and awk Last week Regular Expressions grep egrep Today Stream manipulation: sed awk Sed: Stream-oriented, Non- Interactive, Text Editor Look for patterns one line at a time, like grep Change

More information

Introduction to C Programming S Y STEMS

Introduction to C Programming S Y STEMS Introduction to C Programming CS 40: INTRODUCTION TO U NIX A ND L I NUX O P E R AT ING S Y STEMS Objectives Introduce C programming, including what it is and what it contains, which includes: Command line

More information

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing The scanner (or lexical analyzer) of a compiler processes the source program, recognizing

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

Regular Expressions. Languages. Recall. A language is a set of strings made up of symbols from a given alphabet. Computer Science Theory 2

Regular Expressions. Languages. Recall. A language is a set of strings made up of symbols from a given alphabet. Computer Science Theory 2 Regular Expressions Languages Recall. A language is a set of strings made up of symbols from a given alphabet. Computer Science Theory 2 1 String Recognition Machine Given a string and a definition of

More information

12 INPUT AND OUTPUT OF DATA

12 INPUT AND OUTPUT OF DATA 12 INPUT AND OUTPUT OF DATA 12.1 INTRODUCTION In C language input and output of data is done by a collection of library functions like getchar, putchar, scanf, printf, gets and puts. These functions permit

More information

2110711 THEORY of COMPUTATION

2110711 THEORY of COMPUTATION 2110711 THEORY of COMPUTATION ATHASIT SURARERKS ELITE Athasit Surarerks ELITE Engineering Laboratory in Theoretical Enumerable System Computer Engineering, Faculty of Engineering Chulalongkorn University

More information

Antlr ANother TutoRiaL

Antlr ANother TutoRiaL Antlr ANother TutoRiaL Karl Stroetmann March 29, 2007 Contents 1 Introduction 1 2 Implementing a Simple Scanner 1 A Parser for Arithmetic Expressions 4 Symbolic Differentiation 6 5 Conclusion 10 1 Introduction

More information

Scanner. tokens scanner parser IR. source code. errors

Scanner. tokens scanner parser IR. source code. errors Scanner source code tokens scanner parser IR errors maps characters into tokens the basic unit of syntax x = x + y; becomes = + ; character string value for a token is a lexeme

More information

C Programming Language CIS 218

C Programming Language CIS 218 C Programming Language CIS 218 Description C is a procedural languages designed to provide lowlevel access to computer system resources, provide language constructs that map efficiently to machine instructions,

More information

CISC 181 Project 3 Designing Classes for Bank Accounts

CISC 181 Project 3 Designing Classes for Bank Accounts CISC 181 Project 3 Designing Classes for Bank Accounts Code Due: On or before 12 Midnight, Monday, Dec 8; hardcopy due at beginning of lecture, Tues, Dec 9 What You Need to Know This project is based on

More information

Previously we saw that a string constant was just a sequence of characters enclosed within quotation marks. Now we take a look at string variables.

Previously we saw that a string constant was just a sequence of characters enclosed within quotation marks. Now we take a look at string variables. 1 Programming with C Terry Marris November 2010 2 Strings Previously we saw that a string constant was just a sequence of characters enclosed within quotation marks. Now we take a look at string variables.

More information

Advance Bash Shell Scripting

Advance Bash Shell Scripting Advance Bash Shell Scripting 1- Introduction to Shell What is shell Installation of shell Shell features Bash Keywords Built-in Commands Linux Commands Specialized Navigation and History Commands Shell

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Programming in C: Basics CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of variable We must declare the

More information

Command Scripts. 13.1 Running scripts: include and commands

Command Scripts. 13.1 Running scripts: include and commands 13 Command Scripts You will probably find that your most intensive use of AMPL s command environment occurs during the initial development of a model, when the results are unfamiliar and changes are frequent.

More information

Reading 13 : Finite State Automata and Regular Expressions

Reading 13 : Finite State Automata and Regular Expressions CS/Math 24: Introduction to Discrete Mathematics Fall 25 Reading 3 : Finite State Automata and Regular Expressions Instructors: Beck Hasti, Gautam Prakriya In this reading we study a mathematical model

More information

PHP Tutorial From beginner to master

PHP Tutorial From beginner to master PHP Tutorial From beginner to master PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

More information

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays A First Book of C++ Chapter 2 Data Types, Declarations, and Displays Objectives In this chapter, you will learn about: Data Types Arithmetic Operators Variables and Declarations Common Programming Errors

More information

Module 816. File Management in C. M. Campbell 1993 Deakin University

Module 816. File Management in C. M. Campbell 1993 Deakin University M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working

More information

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement

More information

The char Data Type. Character and String Processing. Another Example /* Capitalize all lowercase letters */ while ((c = getchar())!

The char Data Type. Character and String Processing. Another Example /* Capitalize all lowercase letters */ while ((c = getchar())! Character and String Processing CSE 130: Introduction to C Programming Spring 2005 The char Data Type A char value can be thought of as either a character or a small integer printf( %d, a ); /* prints

More information

Indicates the end of data when the number of data is not known in advance Must be distinct from the data but be of the same type

Indicates the end of data when the number of data is not known in advance Must be distinct from the data but be of the same type Program Control Essentials of repetition Loop control variable Counts the number of repetitions in the counter-controlled loop Controls the execution of loop Sentinel value Indicates the end of data when

More information

Lecture 2: Regular Languages [Fa 14]

Lecture 2: Regular Languages [Fa 14] Caveat lector: This is the first edition of this lecture note. Please send bug reports and suggestions to jeffe@illinois.edu. But the Lord came down to see the city and the tower the people were building.

More information

A Rudimentary Intro to C programming

A Rudimentary Intro to C programming A Rudimentary Intro to C programming Wayne Goddard School of Computing, Clemson University, 2008 Part 4: Strings and Pointers 18 Strings.................................... D1 19 String Functions..............................

More information

Going from Python to C

Going from Python to C Going from Python to C Darin Brezeale December 8, 2011 Python is a high-level, interpreted language. C has many of the same types of programming constructs as in Python: arrays, loops, conditionals, functions,

More information

Reading. C Programming Language. Basic syntax Whitespaces. Whitespaces (cont d) #include. Basic syntax Comments

Reading. C Programming Language. Basic syntax Whitespaces. Whitespaces (cont d) #include. Basic syntax Comments Reading C Programming Language Types, operators, expressions Control flow, functions Basic IO K&R Chapter 2 Types, Operators, and Expressions K&R Chapter 3 Control Flow K&R Chapter 7 Basic I/O NEWS Assignment

More information

The current topic: Scheme. Announcements. Numeric operators. Review: car, cdr, and cons

The current topic: Scheme. Announcements. Numeric operators. Review: car, cdr, and cons The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction Next up: Numeric operators, REPL, quotes, functions, conditionals Types and values

More information

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 Basics of C Remark: Skim Chapters 1 through 6 of Deitel & Deitel. You will notice the following: C is (more or less) a subset of Java. (So, you are

More information

Computer Science. General Education Students must complete the requirements shown in the General Education Requirements section of this catalog.

Computer Science. General Education Students must complete the requirements shown in the General Education Requirements section of this catalog. Computer Science Dr. Ilhyun Lee Professor Dr. Ilhyun Lee is a Professor of Computer Science. He received his Ph.D. degree from Illinois Institute of Technology, Chicago, Illinois (1996). He was selected

More information

6.087 Lecture 1 January 11, 2010

6.087 Lecture 1 January 11, 2010 6.087 Lecture 1 January 11, 2010 Introduction to C Writing C Programs Our First C Program 1 What is C? Dennis Ritchie AT&T Bell Laboratories 1972 16-bit DEC PDP-11 computer (right) Widely used today extends

More information

LAB 1 REPRESENTATION OF NUMBERS AND INTRODUCTION TO C

LAB 1 REPRESENTATION OF NUMBERS AND INTRODUCTION TO C LAB 1 REPRESENTATION OF NUMBERS AND INTRODUCTION TO C 1. LAB OBJECTIVE The objective of this lab is to review binary numbers and to review/introduce you to the C programming language and the MATLAB environment.

More information

Python Programming for Linguists

Python Programming for Linguists Python Programming for Linguists Week 8 Shu-Kai Hsieh LOPE lab at Graduate Institute of Linguistics, National Taiwan University 1 Agenda 2 Introduction to Data Structure 3 String Text Processing in Python

More information

Your first C program. Which one is best?

Your first C program. Which one is best? Your first C program #include void main(void) { printf( Hello, world!\n ); } #include void main(void) { printf( Hello, ); printf( world! ); printf( \n ); } Which one is best? #include

More information

Lecture 18 Regular Expressions

Lecture 18 Regular Expressions Lecture 18 Regular Expressions Many of today s web applications require matching patterns in a text document to look for specific information. A good example is parsing a html file to extract tags

More information

Finite Automata and Formal Languages

Finite Automata and Formal Languages Finite Automata and Formal Languages TMV026/DIT321 LP4 2011 Lecture 14 May 19th 2011 Overview of today s lecture: Turing Machines Push-down Automata Overview of the Course Undecidable and Intractable Problems

More information

Programming for MSc Part I

Programming for MSc Part I Herbert Martin Dietze University of Buckingham herbert@the-little-red-haired-girl.org July 24, 2001 Abstract The course introduces the C programming language and fundamental software development techniques.

More information

Turing Machines, Part I

Turing Machines, Part I Turing Machines, Part I Languages The $64,000 Question What is a language? What is a class of languages? Computer Science Theory 2 1 Now our picture looks like Context Free Languages Deterministic Context

More information

The C Programming Language

The C Programming Language The C Programming Language CS 1025 Computer Science Fundamentals I Stephen M. Watt University of Western Ontario The C Programming Language A high-level language for writing low-level programs Allows machine-independent

More information

Compiler Construction

Compiler Construction Compiler Construction Regular expressions Scanning Görel Hedin Reviderad 2013 01 23.a 2013 Compiler Construction 2013 F02-1 Compiler overview source code lexical analysis tokens intermediate code generation

More information

Information Systems SQL. Nikolaj Popov

Information Systems SQL. Nikolaj Popov Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria popov@risc.uni-linz.ac.at Outline SQL Table Creation Populating and Modifying

More information

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method

More information

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459) Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459) Class Time: 6:00 8:05 p.m. (T,Th) Venue: WSL 5 Web Site: www.pbvusd.net/mis260 Instructor Name: Terrell Tucker Office: BDC 127

More information

A Lex Tutorial. Victor Eijkhout. July 2004. 1 Introduction. 2 Structure of a lex file

A Lex Tutorial. Victor Eijkhout. July 2004. 1 Introduction. 2 Structure of a lex file A Lex Tutorial Victor Eijkhout July 2004 1 Introduction The unix utility lex parses a file of characters. It uses regular expression matching; typically it is used to tokenize the contents of the file.

More information

Outline Basic concepts of Python language

Outline Basic concepts of Python language Data structures: lists, tuples, sets, dictionaries Basic data types Examples: int: 12, 0, -2 float: 1.02, -2.4e2, 1.5e-3 complex: 3+4j bool: True, False string: "Test string" Conversion between types int(-2.8)

More information

Getting started 7. Storing variable values 19

Getting started 7. Storing variable values 19 Contents 1 2 3 4 Getting started 7 Introducing the C language 8 Installing a C compiler 10 Writing a C program 12 Compiling a C program 14 Understanding compilation 16 Summary 18 Storing variable values

More information

1 Installation. 2 Setup. 3 Example 0. Jumpstart Flex and Bison Bo Waggoner Updated:

1 Installation. 2 Setup. 3 Example 0. Jumpstart Flex and Bison Bo Waggoner Updated: Jumpstart Flex and Bison Bo Waggoner Updated: 2014-10-18 Abstract Flex and Bison are tools for writing a compiler (they are free/replacement versions of the famous Lex and Yacc). We try to get some minimal

More information

SCR. Scripting. Goals of this lab: Prerequisites: LXB

SCR. Scripting. Goals of this lab: Prerequisites: LXB SCR Scripting Goals of this lab: To learn the basics of writing shell scripts. To gain insight in the gains with automating administrative work. To gain practical experience of automating administrative

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

PIC 40A. Lecture 16: Introduction to PHP. Copyright 2011 Jukka Virtanen UCLA 1 11/12/14

PIC 40A. Lecture 16: Introduction to PHP. Copyright 2011 Jukka Virtanen UCLA 1 11/12/14 PIC 40A Lecture 16: Introduction to PHP 11/12/14 Copyright 2011 Jukka Virtanen UCLA 1 What is PHP? Server-side scripting language An interpreted language like JavaScript Developed by Rasmus Lerdorfin 1994

More information

Engineering Problem Solving with C++, Etter

Engineering Problem Solving with C++, Etter Engineering Problem Solving with C++, Etter Chapter 7 Strings 12-11-13 1 Strings Character Strings The string Class. 2 C style strings functions defined in cstring CHARACTER STRINGS 3 C Style Character

More information

Linux Lecture-2. Ashish Bhatia Summer 2009

Linux Lecture-2. Ashish Bhatia Summer 2009 Linux Lecture-2 Ashish Bhatia Summer 2009 Doubts (from previous lecture)? Concept of Users GNU/Linux is a multi-user OS Everything is a file or a process Each process must specify which user is the owner

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Python Programming: An Introduction to Computer Science Sequences: Strings and Lists Python Programming, 2/e 1 Objectives To understand the string data type and how strings are represented in the computer.

More information

Structural Regular Expressions

Structural Regular Expressions Structural Regular Expressions Rob Pike AT&T Bell Laboratories Murray Hill, New Jersey 07974 ABSTRACT The current UNIX text processing tools are weakened by the built-in concept of a line. There is a simple

More information

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming INDEX 1) Introduction to C Programming a. What is C? b. Getting started with C 2) Data Types, Variables, Constants a. Constants, Variables and Keywords b. Types of Variables c. C Keyword d. Types of C

More information

IV-1Working with Commands

IV-1Working with Commands Chapter IV-1 IV-1Working with Commands Overview... 2 Multiple Commands... 2 Comments... 2 Maximum Length of a Command... 2 Parameters... 2 Liberal Object Names... 2 Data Folders... 3 Types of Commands...

More information

Introduction to Programming (in C++) Data types and visibility. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC

Introduction to Programming (in C++) Data types and visibility. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC Introduction to Programming (in C++) Data types and visibility Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC Outline Data types Type conversion Visibility Introduction to

More information

Advanced Query for Query Developers

Advanced Query for Query Developers for Developers This is a training guide to step you through the advanced functions of in NUFinancials. is an ad-hoc reporting tool that allows you to retrieve data that is stored in the NUFinancials application.

More information

Reading Assignment. Main Program in C. K.N. King Chapter 2. K.N. King Chapter 3. K.N. King Chapter 4. K.N. King Chapter 7. Our first C program

Reading Assignment. Main Program in C. K.N. King Chapter 2. K.N. King Chapter 3. K.N. King Chapter 4. K.N. King Chapter 7. Our first C program Reading Assignment Main Program in C In C the main program is a function called main The body of the function is enclosed in left ( ) and right ( ) curly braces. K.N. King Chapter 2 K.N. King Chapter 3

More information

GETTING STARTED WITH C++ C++ BASICS - 1 -

GETTING STARTED WITH C++ C++ BASICS - 1 - - 1 - GETTING STARTED WITH C++ Programming is a core activity in the process of performing tasks or solving problems with the aid of a computer. An idealised picture is: PROBLEM COMPUTER SOLUTION Unfortunately

More information

BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems, BSc (Hons) Mathematics & BSc (Hons) Software Engineering

BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems, BSc (Hons) Mathematics & BSc (Hons) Software Engineering BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems, BSc (Hons) Mathematics & BSc (Hons) Software Engineering Cohort: BCNS/07/FT- BIS/07/FT- BIS/06/FT -BM/07/FT BSE/07/FT/PT-

More information

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions Theory of Formal Languages In the English language, we distinguish between three different identities: letter, word, sentence.

More information

CS 164 Programming Languages and Compilers Handout 8. Midterm I

CS 164 Programming Languages and Compilers Handout 8. Midterm I Mterm I Please read all instructions (including these) carefully. There are six questions on the exam, each worth between 15 and 30 points. You have 3 hours to work on the exam. The exam is closed book,

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

CSE 450. Translation of Programming Languages. Lecture 3: Git Setup and More Lexing

CSE 450. Translation of Programming Languages. Lecture 3: Git Setup and More Lexing CSE 450 Translation of Programming Languages Lecture 3: Git Setup and More Lexing Lecture Overview Git version control SSH keys Continuous Integration with Travis CI Walkthrough on git setup on CSE servers

More information

Primitive Data Types Summer 2010 Margaret Reid-Miller

Primitive Data Types Summer 2010 Margaret Reid-Miller Primitive Data Types 15-110 Summer 2010 Margaret Reid-Miller Data Types Data stored in memory is a string of bits (0 or 1). What does 1000010 mean? 66? 'B'? 9.2E-44? How the computer interprets the string

More information

1 Problem Description

1 Problem Description CSCE2014 Programming Foundations II Homework One By Wing Ning Li 1 Problem Description Implement the standard library function strtok using C++/C basic language constructs. In concept, this assignment

More information

Chapter 2: Problem Solving Using C++

Chapter 2: Problem Solving Using C++ Chapter 2: Problem Solving Using C++ 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common

More information

String Processing in C

String Processing in C String Processing in C C Programming and Software Tools N.C. State Department of Computer Science Standard Library: Many functions for checking whether a character is a digit, is upper case,

More information

Jeri R. Hanly and Elliot B. Koffman, Problem Solving and Program Design in C, 7th ed., 2012, Addison- Wesley. (Required)

Jeri R. Hanly and Elliot B. Koffman, Problem Solving and Program Design in C, 7th ed., 2012, Addison- Wesley. (Required) University of Macau Faculty of Science and Technology Department of Computer and Information Science CISB110 Programming Science Syllabus 1 st Semester 2014/2015 Part A Course Outline Compulsory course

More information

Standard C Input/Output. Output: printf() Table of Contents

Standard C Input/Output. Output: printf() Table of Contents Standard C Input/Output 1 Output: printf() 2 Table of Contents Output: printf( ) - syntax & sematics Output: printf( ) - examples Output: printf( ) - format control Screen / Printer Control Input: scanf(

More information

Introduction to Computers and Programming

Introduction to Computers and Programming 16.070 Introduction to Computers and Programming March 14 Recitation 6 Spring 2002 Topics: Quick review of PS4 issues Fundamental Data types ASCII / Arithmetic Conversion Number Systems / Logical Operation

More information

CS 341 Homework 9 Languages That Are and Are Not Regular

CS 341 Homework 9 Languages That Are and Are Not Regular CS 341 Homework 9 Languages That Are and Are Not Regular 1. Show that the following are not regular. (a) L = {ww R : w {a, b}*} (b) L = {ww : w {a, b}*} (c) L = {ww' : w {a, b}*}, where w' stands for w

More information

In this lecture you will learn:

In this lecture you will learn: Data Types and Variables Imed Hammouda Department of Software Systems Tampere University of Technology Objectives In this lecture you will learn: What is a data type and how types are represented in C++.

More information

Lecture 4 Notes: Arrays and Strings

Lecture 4 Notes: Arrays and Strings 6.096 Introduction to C++ January 10, 2011 Massachusetts Institute of Technology John Marrero Lecture 4 Notes: Arrays and Strings 1 Arrays So far we have used variables to store values in memory for later

More information

ECS 120 Lesson 17 Church s Thesis, The Universal Turing Machine

ECS 120 Lesson 17 Church s Thesis, The Universal Turing Machine ECS 120 Lesson 17 Church s Thesis, The Universal Turing Machine Oliver Kreylos Monday, May 7th, 2001 In the last lecture, we looked at the computation of Turing Machines, and also at some variants of Turing

More information

IMPERATIVE PROGRAMMING C LANGUAGE

IMPERATIVE PROGRAMMING C LANGUAGE J.NAWROCKI, M. ANTCZAK, H. ĆWIEK, W. FROHMBERG, A. HOFFA, M. KIERZYNKA, S. WĄSIK IMPERATIVE PROGRAMMING C LANGUAGE EX. 1. Write in C language programs described below, compile them and tentatively debug:

More information

AP Computer Science Static Methods, Strings, User Input

AP Computer Science Static Methods, Strings, User Input AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because

More information

HP-UX Essentials and Shell Programming Course Summary

HP-UX Essentials and Shell Programming Course Summary Contact Us: (616) 875-4060 HP-UX Essentials and Shell Programming Course Summary Length: 5 Days Prerequisite: Basic computer skills Recommendation Statement: Student should be able to use a computer monitor,

More information

Functions. Recursion

Functions. Recursion CandC++ 2. Functions Preprocessor Stephen Clark University of Cambridge (heavily based on last year s notes (Andrew Moore) with thanks to Alastair R. Beresford and Bjarne Stroustrup) Michaelmas Term 2011

More information

Introduction to Python

Introduction to Python WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

More information

Chapter 2. Finite Automata. 2.1 The Basic Model

Chapter 2. Finite Automata. 2.1 The Basic Model Chapter 2 Finite Automata 2.1 The Basic Model Finite automata model very simple computational devices or processes. These devices have a constant amount of memory and process their input in an online manner.

More information

The Fundamentals of C++

The Fundamentals of C++ The Fundamentals of C++ Basic programming elements and concepts JPC and JWD 2002 McGraw-Hill, Inc. Program Organization Program statement Definition Declaration Action Executable unit Named set of program

More information