Part 3 - Syntax, Semantics and Pragmatics
Part 3 - Syntax, Semantics and Pragmatics
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 beginend to group statements;
C uses { and }
Pascal uses the keyword integer; C uses int
if (x < y)
temp = x;
x = y;
y = temp;
Ada:
if x < y then
temp := x;
x := y;
y := temp
end if;
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 is typographical
Syntax describes the way we write programs as
a sequence of characters
Syntax can be precisely and formally defined
by BNF (Backus-Naur Form)
A language in the usual sense is a sequence of
characters (or sounds) and requires syntax
BUT you can do many language-like things
with a GUI and no real syntax
Semantics is fundamental
Semantics affects the very way we think about
programming
Someone once said, You can write a FORTRAN
program in any language.
This is a poor way to program
You can use a language, or you can fight with it
If you are fighting with a language, you are either
using the wrong language, or
using the language wrong
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