Compilers and Automata Theory: Assignment 1
Compilers and Automata Theory: Assignment 1
Assignment 1
K.G.P Thilini
08001261
2008/CS/126
SCS3008 08001261
Syntax:
The form or structure of the expressions, statements, and program units. Grammars are
commonly used to describe the syntax of programming language.
Example:
<program> → <stmts>
<stmts> → <stmt> | <stmt> ; <stmts>
<stmt> → <var> = <expr>
<var> → a | b | c | d
<expr> → <term> + <term> | <term> - <term>
<term> → <var> | const
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
Examples:
Dynamic semantics:
Dynamic semantics means describing the meanings of expressions, statements, and program
units.
Examples:
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 :
The two distinct parse trees for this grammar are given below.
Assignment 1