Representation, Syntax, Paradigms, Types

Slides:



Advertisements
Similar presentations
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Advertisements

Programming Languages and Paradigms The C Programming Language.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
CSE S. Tanimoto Syntax and Types 1 Representation, Syntax, Paradigms, Types Representation Formal Syntax Paradigms Data Types Type Inference.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
CSE 341, S. Tanimoto Concepts 1- 1 Programming Language Concepts Formal Syntax Paradigms Data Types Polymorphism.
CIS Computer Programming Logic
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Input, Output, and Processing
ISBN Chapter 3 Describing Syntax and Semantics.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
CSE S. Tanimoto Paradigms 1 Paradigms Imperative Functional Object-Oriented Rule-Based Logic Visual* Scripting* * whether visual and scripting methodologies.
CPS 506 Comparative Programming Languages Syntax Specification.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
C H A P T E R T H R E E Type Systems and Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Bill Tucker Austin Community College COSC 1315
Functional Programming
C++ LANGUAGE MULTIPLE CHOICE QUESTION
CSE3302 Programming Languages (notes continued)
Information and Computer Sciences University of Hawaii, Manoa
Chapter 3 – Describing Syntax
Programming Languages and Compilers (CS 421)
The Machine Model Memory
Types CSCE 314 Spring 2016.
Chapter 1 Introduction.
Describing Syntax and Semantics
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Java Primer 1: Types, Classes and Operators
Chapter 3 – Describing Syntax
CS 326 Programming Languages, Concepts and Implementation
Revision Lecture
C++, OBJECT ORIENTED PROGRAMMING
Chapter 1 Introduction.
Data types and variables
Type Systems Terms to learn about types: Related concepts: Type
Java Programming: From Problem Analysis to Program Design, 4e
Engineering Innovation Center
Arrays, For loop While loop Do while loop
Chapter 10 Programming Fundamentals with JavaScript
Chapter 4: Control Structures I (Selection)
Programming Language Syntax 2
Chapter 2: Basic Elements of Java
FP Foundations, Scheme In Text: Chapter 14.
R.Rajkumar Asst.Professor CSE
Representation, Syntax, Paradigms, Types
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
Representation, Syntax, Paradigms, Types
CSE S. Tanimoto Paradigms
Python Primer 1: Types and Operators
Representation, Syntax, Paradigms, Types
Syntax vs Semantics Backus-Naur Form Extended BNF Derivations
Chapter 3 Describing Syntax and Semantics.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Basic Programming Concepts
C++ Programming Basics
Programming Languages and Paradigms
An Overview of C.
Introduction to C Programming
Presentation transcript:

Representation, Syntax, Paradigms, Types Formal Syntax Paradigms Data Types Type Inference CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types General Issues Representation (of data, of computation) Form (Syntax) Meaning (Semantics) Paradigm (General way of thinking) Naming (names, name spaces, bindings, locality) Functionality (numeric, data manip, I/O, communication, synchronization, security) Correctness (types, exception handling, error checking, bug avoidance) CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types Syntax: The grammatical form of programs. vs Semantics: The meaning of the program Syntax (of textual languages) is typically specified by production rules for a context-free grammar using Backus-Naur Form (BNF) or Extended BNF (EBNF) In visual languages, syntax is described by a set of restrictions on how diagrams may be constructed. (e.g., connection constraints) CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types Syntactic Components Identifiers and reserved words Numeric constants Parentheses, braces and brackets Expressions Statements CSE 341 -- S. Tanimoto Syntax and Types

BNF (Backus-Naur Form) (2.0 * PI) / n <expression> ::= <expression> + <term> | <expression> - <term> | <term> <term> ::= <term> * <factor> | <term> / <factor> | <factor> <factor> ::= number | name | ( <expression> ) CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types Extended BNF Optional constructs written as [ x ] Zero or more of x written as { x } Choice (“or”) written using | Grouping with parentheses ( x | y ) as in { (x | y ) z } <expression> ::= <term> { (+ | -) <term> } <term> ::= <factor> { (* | /) <factor> } <factor> ::= ’(’ <expression> ’)’ | name | number CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types Derivation E ::= E + T | E - T | T T ::= T * F | T / F | F F ::= number | name | ( E ) E E + T T + T T / F + T F / F + T F / F + F 25 / F + F 25 / 100 + F 25 / 100 + total CSE 341 -- S. Tanimoto Syntax and Types

Representation of Data Constants, Variables Types, classes Compounds: arrays, structures. Non-numeric objects: strings, images, audio. Values vs references Machine dependencies: word size, addressing resolution. In C, characters and booleans are actually integers. CSE 341 -- S. Tanimoto Syntax and Types

Representation of Process Arithmetic and logical expressions Conditional expressions Loops Recursive and nonrecursive functions Multiple threads of control, forking, joining, synchronizing Single-threaded Parallel processing (in Single-instruction stream/multiple data stream processors) Throwing and catching of exceptions Declaration of constraints and rules CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types Paradigm General style of thinking that underlies a programming language Webster’s New World Dictionary: “a pattern, example, or model”. Imperative Rule-based Functional Logic Object-oriented Visual data-flow CSE 341 -- S. Tanimoto Syntax and Types

The Imperative Paradigm An imperative program is a sequence of commands Read a value from a file. Evaluate an arithmetic expression. Assign a value to a variable. Test a condition and branch if it is true. Iterate a loop body until a condition is false. Print a value onto the screen. CSE 341 -- S. Tanimoto Syntax and Types

The Functional Paradigm An functional program is a collection of function definitions and function applications. Define SQR(x): { Apply the * function to x and x} Apply SQR to 7; CSE 341 -- S. Tanimoto Syntax and Types

The Object-Oriented Paradigm An object-oriented program is a collection of object class definitions, in which both data members and methods are specified. Class Student extends Person { int student_number; int get_student_number() { return student_number; } int set_student_number (int num) { student_number = num; } CSE 341 -- S. Tanimoto Syntax and Types

The Rule-Based Paradigm A rule-based program is a collection of if-then rules. if name = "" then input name; if name starts with "A" then print "Early in the alphabet"; CSE 341 -- S. Tanimoto Syntax and Types

The Logic-Programming Paradigm A logic program is a collection of logical propositions and questions. If x is a bird or an airplane, then x has wings. Tweety is a bird. Does Tweety have wings? CSE 341 -- S. Tanimoto Syntax and Types

The Visual Data-Flow Paradigm A visual data-flow program is a diagram in which boxes represent operations and arrows indicate the flow of data from outputs of operations to inputs of other operations. 3x2 + 5x + 8 3 * * input x + * + 5 8 CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types Category or class for a value (or object) that permits its bits to be interpreted. Central Processing Unit instruction sets recognize certain types, such as integers and floats of different sizes. A programming language is not limited to the types that are directly supported by the CPU. CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types Strong vs Weak Typing Strong typing: (static and usually monomorphic) Every variable must have a type. A variable may receive only values of its type. Type-related bugs can be reduced. Type identification tags are not needed a run time. Weak typing: (dynamic and usually polymorphic) Variables need not be declared with particular types. The type of value held by a variable can change dynamically. Values must be tagged during execution with their types. CSE 341 -- S. Tanimoto Syntax and Types

Coercion and Contagion Coercion: Any automatic type conversion. A value of type A is being assigned to a variable of type B. The value is coerced into one of type B. double x = 3 * 5; Contagion: Values of lower precision “catch” the precision of their higher precision co-arguments. int y = 10 * (3.1415 / 10); /* result is 3, not 0. */ In Common Lisp, when a rational meets a float, the rule of floating-point contagion rules. CSE 341 -- S. Tanimoto Syntax and Types

CSE 341 -- S. Tanimoto Syntax and Types Type Inference With weak typing, type inference is needed. (But ML, which is strongly typed, also uses a kind of type inference.) The resulting type can be determined from the types of the arguments, and the nature of the operations. Contagion provides one method for type inference: With strong typing, means for determining type equivalence are needed. int x[10]; int y[10]; Here x and y have structurally equivalent types. C and C++ recognize structurally equivalent types as equivalent. In Modula, most structurally equivalent types are not automatically considered equivalent, but they can be declared equivalent. CSE 341 -- S. Tanimoto Syntax and Types