Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
50% found this document useful (4 votes)
2K views

Syntax and Semantics

Syntax refers to the rules that govern the structure of a computer program or language. Some key aspects of syntax include grammar rules for valid statements, symbols that can be used, and structure of sentences. Semantics refers to the meaning and correctness of statements, including the compatibility and intended usage. Some examples of syntax errors include missing closing brackets or multiple decimals, while semantic errors involve issues like using an undeclared variable or ambiguous variable types. An algorithm is a precise set of ordered steps to solve a general class of problems in a finite time through unambiguous and deterministic instructions.

Uploaded by

api-3739054
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
50% found this document useful (4 votes)
2K views

Syntax and Semantics

Syntax refers to the rules that govern the structure of a computer program or language. Some key aspects of syntax include grammar rules for valid statements, symbols that can be used, and structure of sentences. Semantics refers to the meaning and correctness of statements, including the compatibility and intended usage. Some examples of syntax errors include missing closing brackets or multiple decimals, while semantic errors involve issues like using an undeclared variable or ambiguous variable types. An algorithm is a precise set of ordered steps to solve a general class of problems in a finite time through unambiguous and deterministic instructions.

Uploaded by

api-3739054
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

Syntax

And
Semantic
SYNTAX:
A set of strict grammar rules,
symbols, and special words
used to construct a computer
program.
There are syntax rules
(grammar: how valid instructions
are written, what combinations of
symbols can be used)
Cont..
Syntax is the grammar of the
language, that is the rules for
constructing valid statements
in that language.

If you break the rules the


compiler will complain.
Cont….
Study of the rules that govern
the structure of sentences,
and which determine their
relative grammaticality.
The term syntax can also be
used to refer to these rules
themselves, as in “the syntax
of a language”.
SYNTAX ERROR:
If a syntax error is
encountered during
compilation( mapping high
level language to low level
language) it must be corrected
if the source code is to be
successfully compiled.
Cont..
Syntax errors may also occur
when an invalid equation is
entered into a calculator. This
can be caused by opening
brackets without closing them,
or less commonly, using
several decimal points in one
number.
Cont..
GOOD compiler should help
in identifying and locating
errors.
Any token which doesn’t
match grammar rule is part of
syntax error i.e arithematic
expression with unbalance
paranthesis.
Recovery:
If we have a good idea of
common error that might be
encountered at hand.
End with delimiter
Never go in infinite loop
Replace comma (,) by
semicolon(;)
Semantic:
Semantic is
MEANING OF STATEMENT
COMPATIBILITY OF
STATEMENT
CORRECT USAGE OF
STATEMENT
Cont..
Computers can't read your
mind, so they don't help much
if the meaning of your
program is not what you
wanted.
Cont..
In this regard, semantics
permits programs to be
separated into their syntactical
part (grammatical structure)
and their semantic part
(meaning).
FOR EXAMPLE
IF INTEAD OF
X = 1; STMT
IT WERE GIVEN AS
Y = 1;
WHERE X was declared in
program
BUT Y was not
Cont..
Scope of variable is the range
of program instruction over
which the variable is known.
If the program uses undeclare
name such as
-Y = 1
Cont..
Introduces (ambiguous name)
For example
int X
char X
C++ Syntax and Semantics

3. Mark the following expressions as


either legal or illegal,
Indicate whether the value is an integer
or a floating point value.
Valid Invalid integer floating point
10 + 3
-9.4 - 6.2
10.0 / 3.0
10 / 3
4/8
Cont…

x * y = c; invalid
y = con; valid
const int x : 10; invalid
int x: a = b % c; invalid
ALGORITHM

Step-by-step procedures for solving a


problem in a finite amount of time.
Algorithms encompass far more than
computer programs.
We are learning to write algorithms
and the computer is simply a fast and
flexible tool for implementing
algorithms.
An algorithm is an ordered set of
instructions such that:
(1) There are a finite number of
steps.
(2) It takes a finite amount of time
to execute the steps.
(3) Each step is precise in
meaning.
(4) It is deterministic.
during the execution of an algorithm, the
information must be sufficient to
determine uniquely and completely the
actions required by each step.
(5) It solves a general class of
problems
ensures that the algorithm is general
enough that it solves a general set of
problems, and not one specific/particular
problem
INCLUSION:

the execution of each step in an


algorithm does not require creative
skills, it requires rather only the ability
to follow directions. In specifying
behavior, an algorithm must be
precise, unambiguous, complete, and
correct.

You might also like