Syntax and Semantics
Syntax and Semantics
S.Venkatesan
• Example
while(boolean_expr) statement
– Syntax is as above.
– Semantic is when the boolean_expr is true, the embedded
statement get executed otherwise control goes after the while
statement.
Syntax
• Strings of a language are called as sentences or statements.
• Example
<assign> -> <var> = <expression>
• Eg.
A = B * (A + C)
Problems
• Ambiguity
– operator precedence - order
– Associativity – An expression that have the same
precedence – a rule is required to specify the
precedence – recursion
– if then else - with matched and unmatched if
– Non-Deterministic – if then else
Example
if done == true
then if denom == 0
then quotient = 0
else quotient = num/denom
• Grammar
I -> i E t s | i E t S e S
• Deterministic
I -> i E t s S’
S’ -> e S | epsilon
Ambiguity
Extended BNF
• It increases its readability and writability.
• Non-Deterministic
I -> i E t s | i E t S e S
• Deterministic
I -> i E t s S’
S’ -> e S | epsilon
----- Simplification-----
• EBNF
I -> i E t s [e S]
• EBNF
<term> -> <term> (* | / | %) <factor>