You are on page 1of 19

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
A Simple Program
Structure Syntax
Semantics
Pragmatic
Programmin sProgram
g Language Organization Data
Concepts
and Algorithms
External
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.
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 Ada
: if (x < y) : if x < y then
temp = x; temp :=
x = y; x; x := y;
y = temp; 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
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
Semantic Elements

Variables • Scope, Name,


Type,
Lifetime

Values
and
Reference
s

E
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

You might also like