You are on page 1of 3

Compilers and Automata Theory

Assignment 1

K.G.P Thilini
SCS3008 08001261


The form or structure of the expressions, statements, and program units. Grammars are
commonly used to describe the syntax of programming language.


<program> → <stmts>
<stmts> → <stmt> | <stmt> ; <stmts>
<stmt> → <var> = <expr>
<var> → a | b | c | d
<expr> → <term> + <term> | <term> - <term>
<term> → <var> | const

[a = b + const] can be derived from this grammer which is syntactically correct.

Static semantics:

The static semantics defines restrictions on the structure of valid texts that are hard or impossible
to express in standard syntactic formalisms. For compiled languages, static semantics essentially
include those semantic rules that can be checked at compile time


 include checking that every identifier is declared before it is used.

 include checking the labels on the arms of a case statement are distinct.
 Include checking that identifiers are used in the appropriate context (e.g. not adding a
integer to a function name), or
 Include checking that subroutine calls have the appropriate number and type of
arguments can be enforced by defining them as rules in a logic called a type system.

Dynamic semantics:

Dynamic semantics means describing the meanings of expressions, statements, and program


Three primary methods of Dynamic semantics..

1. Operational
Describes how a valid program is interpreted as sequences of computational steps.
These sequences then are the meaning of the program. In the context of functional
programs, the final step in a terminating sequence returns the value of the

Assignment 1
SCS3008 08001261

2. Axiomatic
Defines the meaning of a command in a program by describing its effect on
assertions about the program state. The assertions are logical statements -
predicates with variables, where the variables define the state of the program.

3. Denotational
is an approach to formalizing the meanings of programming languages by
constructing mathematical objects (called denotations) which describe the
meanings of expressions from the languages.

Ambiguous Grammars:

A grammar is ambiguous if and only if it generates a sentential form that has two or more
distinct parse trees

Example :

<expr> → <expr> <op> <expr> | const

<op> → / | -

The two distinct parse trees for this grammar are given below.

Assignment 1