Sequence
Sequence
It is of 2 types:
Example: 3 * (var1 + 5)
operation - multiplication, operator: *, arity -
2
operand 1: constant (3)
operand 2: operation addition
operand1: data object (var1)
operand 2: constant (5)
More examples and questions
Example 2: 3* var1 +5
Question: is the example equivalent to the
above one?
Example 3: 3 + var1 +5
Question: is this equivalent to (3 + var1) + 5,
or to 3 + (var1 + 5) ?
Precedence and associativity
For each operation node, in expression tree first evaluate
each of its operands, then apply operation to evaluated
operands.
Divide by zero error.
(1)Pattern matching:
It is a fundamental char string operation in many PL.
It is provided by library function rather than operation in
language.
Consider a grammar that recognize odd-length
palindrome over ∑{a, b}
S--->aSa|bSb|0|1
Non-arithmetic expression
(2)Unification:
(a)Fact:
It is a relationship that are stated during a consult
operation which adds new facts and rules to database.
father(A,B)
(b)Rules:
If antecedent of a statement is true, then consequent of
statement must also be true.
ancestor(Mary,Bill)--->mother(Mary,Bill)
sequence control within the
statement
Familiar to programmer
Disadvantages:
goto X
if Y goto X
– transfer control to the statement
labeled X if Y is true.
break
Structured programming
Structured programming design
• Compound statements
• Conditionals
• Iterations
Compound statements
Typical syntax:
begin
statement1;
statement2;
...
end;
Execute each statement in sequence.
Sometimes (e.g., C) { ... } used instead
of begin ... end
Conditional statements