0% found this document useful (0 votes)
76 views

Compilers and Automata Theory: Assignment 1

This document discusses the key concepts of compilers and automata theory including syntax, static semantics, dynamic semantics, and ambiguous grammars. It provides examples to illustrate each concept. Syntax is defined as the form or structure of a programming language and can be described using grammars. Static semantics include rules that can be checked at compile time, like type checking. Dynamic semantics describe the meaning of expressions and statements through operational, axiomatic, and denotational approaches. An ambiguous grammar is one that can generate a sentential form with two or more distinct parse trees.

Uploaded by

thilini87
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Compilers and Automata Theory: Assignment 1

This document discusses the key concepts of compilers and automata theory including syntax, static semantics, dynamic semantics, and ambiguous grammars. It provides examples to illustrate each concept. Syntax is defined as the form or structure of a programming language and can be described using grammars. Static semantics include rules that can be checked at compile time, like type checking. Dynamic semantics describe the meaning of expressions and statements through operational, axiomatic, and denotational approaches. An ambiguous grammar is one that can generate a sentential form with two or more distinct parse trees.

Uploaded by

thilini87
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Compilers and Automata Theory

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

[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

Examples:

 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
units.

Examples:

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
program.

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

You might also like