Concepts of Programming Languages

Slides:



Advertisements
Similar presentations
CSci 1130 Intro to Programming in Java
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
ICE1341 Programming Languages Spring 2005 Lecture #9 Lecture #9 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
ISBN Chapter 6 Data Types Character Strings Pattern Matching.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
String Escape Sequences
CS 355 – Programming Languages
Objectives You should be able to describe: Data Types
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
ISBN 0-321— Chapter 6 sections 1-4, 9 Primitive Data Types Numbers Strings Ordinal Types Pointers.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Introduction to Java Java Translation Program Structure
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Copyright Curt Hill Variables What are they? Why do we need them?
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved. 6-2 Chapter 6 Topics Introduction Primitive Data Types.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Structure of Programming Language Data Types. 2 A data type defines a collection of data objects and a set of predefined operations on those objects An.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
5.2 Names - We discuss all user-defined names here
5.2 Names - We discuss all user-defined names here
Chapter 6 – Data Types CSCE 343.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Type Checking, and Scopes
Strings, Characters and Regular Expressions
Why Python? Introduction Mohamed Yehia Dahab
Concepts of Programming Languages
Chapter 6: Data Types Lectures # 10.
Documentation Need to have documentation in all programs
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Structure of Programming Language
Instructor : Ahmed Alalawi Slides from Chung –Ta King
Multiple variables can be created in one declaration
Variables and Primative Types
Selenium WebDriver Web Test Tool Training
Scope, Objects, Strings, Numbers
Names, Bindings, and Scopes
Advanced Programming Behnam Hatami Fall 2017.
Escape Sequences What if we wanted to print the quote character?
Names, Bindings, Type Checking, and Scopes
Escape Sequences Some Java escape sequences: See Roses.java (page 68)
CMSC 202 Java Primer 2.
Chapter 2: Java Fundamentals
Python Primer 1: Types and Operators
Names and Binding In Text: Chapter 5.
Chapter 6 Data Types.
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
Names, Bindings, and Scopes
Chap 2. Identifiers, Keywords, and Types
EECE.2160 ECE Application Programming
Presentation transcript:

Concepts of Programming Languages Dr. Mohamed Yehia Dahab

Dynamic Scope Based on calling sequences of program units, not their textual layout (temporal versus spatial) References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point

MAIN calls SUB1 SUB1 calls SUB2 SUB2 uses x MAIN - declaration of x ... call SUB2 SUB2 - reference to x - call SUB1 … MAIN calls SUB1 SUB1 calls SUB2 SUB2 uses x

Scope Example Static scoping Dynamic scoping Reference to x is to MAIN's x Dynamic scoping Reference to x is to SUB1's x Evaluation of Dynamic Scoping: Advantage: convenience Disadvantage: poor readability

Referencing Environments The referencing environment of a statement is the collection of all names that are visible in the statement In a static-scoped language, it is the local variables plus all of the visible variables in all of the enclosing scopes In a dynamic-scoped language, the referencing environment is the local variables plus all visible variables in all active subprograms A subprogram is active if its execution has begun but has not yet terminated

Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types

Introduction A data type defines a collection of data objects and a set of predefined operations on those objects A descriptor is the collection of the attributes of a variable An object represents an instance of a user- defined (abstract data) type One design issue for all data types: What operations are defined and how are they specified?

Primitive Data Types Almost all programming languages provide a set of primitive data types Primitive data types: Those not defined in terms of other data types Some primitive data types are merely reflections of the hardware Others require little non-hardware support

Primitive Data Types: Integer Almost always an exact reflection of the hardware so the mapping is trivial There may be as many as eight different integer types in a language Java’s signed integer sizes: byte, short, int, long

Primitive Data Types: Floating Point Model real numbers, but only as approximations Languages for scientific use support at least two floating-point types (e.g., float and double; sometimes more Usually exactly like the hardware, but not always IEEE Floating-Point Standard 754

Primitive Data Types: Decimal For business applications (money) Essential to COBOL C# offers a decimal data type Store a fixed number of decimal digits Advantage: accuracy Disadvantages: limited range, wastes memory

Primitive Data Types: Boolean Simplest of all Range of values: two elements, one for “true” and one for “false” Primitive boolean data type in: PASCAL flag: Boolean; JAVA boolean flag; PYTHON flag = True Not primitive in C Language int flag; //Zero for false and none zero for true Could be implemented as bits, but often as bytes Advantage: readability

Primitive Data Types: Character Stored as numeric codings Most commonly used coding: ASCII An alternative, 16-bit coding: Unicode Includes characters from most natural languages Originally used in Java C# and JavaScript also support Unicode

Character String Types Values are sequences of characters Design issues: Is it a primitive type or just a special kind of array? Should the length of strings be static or dynamic?

Character String Types Operations Typical operations: Assignment and copying Comparison (=, >, etc.) Catenation Substring reference Pattern matching

Character String Type in Certain Languages C and C++ Not primitive Use char arrays and a library of functions that provide operations char str1[12] = "Hello"; char *str2="abcd"; SNOBOL4(a string manipulation language) SNOBOL is a StriNg Oriented and symBOlic Language Primitive Many operations, including elaborate pattern matching Java Primitive via the String class

Pattern Matching (Regular Expressions) A regular expression (regex for short) is a special text string for describing a search pattern You can think of regular expressionsas wildcards such as “*.txt” to find all text files in a file manager

Regular Expressions (Cont’) Metacharacter Description Examples character Any literal letter, number, or punctuation character (other than those that follow) matches itself. apple matches apple. (pattern) Patterns can be grouped together using parentheses so that they can be treated as a unit. see following . Match a single character (except linefeed). s.t matches sat, sit, sQt, s3t, s&t, s t,... ? Match zero or one of the previous character/expression. (When immediately following ?, +, *, or {min,max} it prevents the expression from using "greedy" evaluation.) colou?r matches color, colour + Match one or more of the previous character/expression. a+rgh! matches argh!, aargh!, aaargh!,... * Match zero or more of the previous character/expression. b(an)*a matches ba, bana, banana, bananana,... {number} Match exactly number copies of the previous character/expression. .o{2}n matches noon, moon, loon,...

Regular Expressions (Cont’) Metacharacter Description Examples {min,max} Match between min and max copies (inclusive) of the previous character/expression. kabo{2,4}m matches kaboom, kabooom, kaboooom. [set] Match a single character in set (list and/or range). Most characters that have special meanings in regular expressions do not have to be backslash-escaped in character sets. J[aio]b matches Jab, Jib, Job [A-Z][0-9]{3} matches Canadian postal codes. [^set] Match a single character not in set (list and/or range). Most characters that have special meanings in regular expressions do not have to be backslash-escaped in character sets. q[^u] matches very few English words (Iraqi? qoph? qintar?). | Match either expression that it separates. (Mi|U)nix matches Minix and Unix ^ Match the start of a line. ^# matches lines that begin with #. $ Match the end of a line. ^$ matches an empty line.

Regular Expressions (Cont’) Metacharacter Description Examples \ Interpret the next metacharacter character literally, or introduce a special escaped combination (see following). \* matches a literal asterisk. \n Match a single newline (carriage return in Python) character. Hello\nWorld matches Hello World. \t Match a single tab character. Hello\tWorld matches Hello     World. \s Match a single whitespace character. Hello\s+World matches Hello World, Hello  World, Hello   World,... \S Match a single non-whitespace character. \S\S\S matches AAA, The, 5-9,... \d Match a single digit character. \d\d\d matches 123, 409, 982,... \D Match a single non-digit character. \D\D matches It, as, &!,...