UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

Similar documents
Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

(Refer Slide Time 01:41 min)

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

G Programming Languages - Fall 2012

MIDTERM EXAMINATION - CS130 - Spring 2003

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

CS558 Programming Languages

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Informatica 3 Syntax and Semantics

Compilers. Prerequisites

CSE 307: Principles of Programming Languages

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

So what does studying PL buy me?

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #13. Loops: Do - While

CS558 Programming Languages

Compiler Theory. (Semantic Analysis and Run-Time Environments)

CS558 Programming Languages

UNIT-4 (COMPILER DESIGN)

Chapter 3:: Names, Scopes, and Bindings (cont.)

Chapter 3:: Names, Scopes, and Bindings (cont.)

Introduction. C provides two styles of flow control:

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

C: How to Program. Week /Mar/05

CS450: Structure of Higher Level Languages Spring 2018 Assignment 7 Due: Wednesday, April 18, 2018

VARIABLES AND TYPES CITS1001

Game keystrokes or Calculates how fast and moves a cartoon Joystick movements how far to move a cartoon figure on screen figure on screen

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

CS 230 Programming Languages

Computer Components. Software{ User Programs. Operating System. Hardware

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

UNIT II Structuring the Data, Computations and Program. Kainjan Sanghavi

Programmiersprachen (Programming Languages)

EI326 ENGINEERING PRACTICE & TECHNICAL INNOVATION (III-G) Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Chapter 2 - Introduction to C Programming

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

A function is a named piece of code that performs a specific task. Sometimes functions are called methods, procedures, or subroutines (like in LC-3).

QUIZ. What is wrong with this code that uses default arguments?

CGS 3066: Spring 2015 JavaScript Reference

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

names names identifiers variables subroutines constants

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

Programming Languages: Lecture 12

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)

Java Bytecode (binary file)

Full file at C How to Program, 6/e Multiple Choice Test Bank

Scope of this lecture. Repetition For loops While loops

CSE P 501 Exam 8/5/04

Programming Languages Third Edition. Chapter 7 Basic Semantics

IS12 - Introduction to Programming. Lecture 7: Introduction to C

class objects instances Fields Constructors Methods static

Programming Paradigms

10. Abstract Data Types

COSC121: Computer Systems: Runtime Stack

Programs are: CMPSCI 105/119/120: Programming, Flowchar<ng, and Running Program Flowcharts

Typescript on LLVM Language Reference Manual

LECTURE 1. Overview and History

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Chapter 5 Names, Binding, Type Checking and Scopes

Flow Control. CSC215 Lecture

Introduction to Syntax Analysis. Compiler Design Syntax Analysis s.l. dr. ing. Ciprian-Bogdan Chirila

1 Lexical Considerations

Principles of Programming Languages. Lecture Outline

Implementing Subprograms

Chapter 10. Implementing Subprograms ISBN

G Programming Languages - Fall 2012

Using Source Lines of Code As A Size Input For Estimating Software Effort & Schedule

Run-time Environments


Run-time Environments

Chapter 10. Implementing Subprograms

int j = 0, sum = 0; for (j = 3; j <= 79; j++) { sum = sum + j; System.out.println(sum); //Show the progress as we iterate thru the loop.

5 The Control Structure Diagram (CSD)

Lecture 5 Tao Wang 1

G Programming Languages - Fall 2012

CPE 101. Overview. Programming vs. Cooking. Key Definitions/Concepts B-1

Chapter 2 - Programming Language Syntax. September 20, 2017

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

The New C Standard (Excerpted material)

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

CS 3360 Design and Implementation of Programming Languages. Exam 1

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

assembler Machine Code Object Files linker Executable File

COMP 202 Java in one week

CS16 Exam #1 7/17/ Minutes 100 Points total

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Why are there so many programming languages?

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

C++ Support Classes (Data and Variables)

Chapter 2: Functions and Control Structures

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

Software II: Principles of Programming Languages. Why Expressions?

Lecture 10: Introduction to Correctness

Transcription:

UNIT I Programming Language Syntax and semantics B y Kainjan Sanghavi

Contents Bird s eye view of programming language concepts Syntax Semantics Pragmatics

Programming Language Concepts A programming language is a set of rules that provides a way of telling a computer what operations to perform

Bird s eye view of PL Concepts Programming Language Concepts A Simple Program Structure Syntax Semantics Pragmatics Program Organization Data and Algorithms External Environment

Simple Program Structure consists of the following Organization/Structure (Files are arranged) Environment (Defining and Declaring Variables) Computation(Algorithms or functions)

Simple Program Structure consists of the following..example

Syntax Syntax is the required grammar and punctuation of the language Compile-time errors are syntax errors In computer science the syntax of programming language is a set of rules that define the combination of symbols that are considered to be correctly structured programs in that language. Any programming language specifies a set of rules to form valid programs in that language.

Syntax examples FORTRAN statements are one per line; modern languages are free-format Pascal uses semicolons between statements; C uses semicolons after statements Pascal uses begin end to group statements; C uses { and } Pascal uses the keyword integer; C uses int

Another syntax example C: if (x > y) x = x-1; else y--; Pascal: if x > y then x := x-1 else y := y-1; Differences: parentheses around x > y, the word then, = or :=, semicolon before else, - - These are syntactic differences; the meanings are identical

The importance of syntax Correct syntax is obviously important; if you don t get it right, your program won t run In a sense, syntax is trivial; you learn it, you fix it until it s right, end of story But the syntax of a language greatly affects: how easy it is to write programs how easy it is to read and understand programs how easy it is to make hard-to-see syntax errors

Examples of poor syntax In FORTRAN, variables don t have to be declared Therefore, every misspelling is a new variable In Pascal, semicolons go between statements Therefore, adding a statement to a block involves adding a semicolon to the previous line

An example of good syntax In Ada, control statements have the form if end if, while end while, case end case, etc. This helps avoid the confusion (in C) resulting from large groups of anonymous closing braces Syntax is usually more important for reading and understanding programs than for writing them

Why syntax matters C: if (x < y) temp = x; x = y; y = temp; Ada: if x < y then temp := x; x := y; y := temp end if; The C version has a bug that almost never occurs in Ada

Semantics Semantics has to do with the meaning of constructs in a language, and the meanings of programs written in that language Semantics is fundamental to everything you do in a language Syntax is just the code you use to describe the semantics

High-level semantics Semantics can affect things at a very high level: C is a procedural language; you describe a set of procedures to follow Java is an object-oriented language; you describe objects and their behaviors Prolog is a logic language; you describe facts and the logical relationships among them

Low level semantics Semantics can affect things at a very low level: C: do { x = 2*x; } while (x < 100); Pascal: repeat x := 2*x until x >= 100; Notice that the sense of the test is different: C exits the loop when the condition becomes false, Pascal when it becomes true

Syntax supports semantics A language cannot have semantics without syntax to support those semantics C couldn t have a for loop without syntax Java couldn t have objects without syntax for creating and using them This doesn t mean that for loops and objects are syntactic constructs!

Semantic Elements Variables Scope, Name, Type, Lifetime Values and References Expressions

VARIABLE In Computer programming a variable is a storage location and associated symbolic name which contains some known or unknown quantity or info, or a value. Whenever a computer needs to store a temporary value in the computer memory for processing and accessing it later then it is store in variable. A Variable is simply a way to store some sort of information for later use.

SEMANTIC properties of variable SCOPE- Which part of program will access to the variable? TYPE- Which type of value /data the variable is holding and what operation should be done? LIFETIME- When Is the variable created and when it is destoryed?

Pragmatics Pragmatics has to do with how well the language connects to the real world Semantics supports pragmatics: some kinds of languages are better for some kinds of problems The choice of a language should depend on pragmatic considerations

Examples of pragmatics C is fast because it does so little error checking Java programs are less buggy because they spend so much time on error checks Perl is good for CGI scripts because it has powerful tools for string processing Java is a better choice for me than C++ because I know Java better

THANKYOU