Sunteți pe pagina 1din 6

THE OPEN UNIVERSITY OF SRI LANKA

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING


BACHELOR OF SOFTWARE ENGINEERING - AY 2010/ 11
ECX5265 – SOFTWARE CONSTRUCTION - TMA 01

Important:
 Submission deadline August 12, 2010
 No late submissions will be accepted.

1. (a) In the following, a number-string is a non-empty sequence of decimal digits,


[0-9]+. The value of a number-string is an integer number. Note that leading
zeroes are allowed. For each of the following languages, create a regular
expression to describe that language.
i) All number-strings having the value 5265.
ii) All number-strings not having the value 5265.
iii) All number-strings having a value greater than 5265.
(b) Consider the following productions
A −A
A A − id
A id
i) Show that the grammar is ambiguous.
ii) Now make two different unambiguous grammars for the same language:
(I) Where prefix minus binds stronger than infix minus.
(II) Where infix minus binds stronger than prefix minus.
iii) Show the syntax trees using the new grammars for the string you used to prove
the original grammar is ambiguous.

2.

3.
(a) Draw NFA for the regular expression (1*01*0)*1* over the alphabet Σ = {0, 1}
(b) Check the sentence w = “1010” belongs to the language generated by above 3(a).
(c) Starting from the NFA you constructed in 3(a), derive the DFA.
(d) Verify that the DFA yields the same output as the original NFA for the same input
string w.

1
THE OPEN UNIVERSITY OF SRI LANKA
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
ACADEMIC YEAR – 2010/ 11
BACHELOR OF SOFTWARE ENGINEERING
ECX5265 – SOFTWARE CONSTRUCTION - TMA 02

Important:
 Submission deadline October 12, 2010
 No late submissions will be accepted.

Part A [40 marks]

1. (a) Define Chomsky Normal Form for CFGs.


(b) Convert the following grammar to CNF. (Start symbol is S)
S aSA | A
A AB | a | aDb | D
B DB | Bb
C aD | a | b
(c) Examine the ambiguity of the grammar having the following productions by using
the string ‘babab’.

2. (a) Briefly describe the PDA model and name two ways by which a language can be
accepted.
(b) Describe the types of moves made by PDA.
(c) Find the PDA that accepts the language generated by a grammar with the
productions; (Start symbol is S)
S bA
A aAb | ab
B a
(d) Show that the PDA found in 2(c) is equivalent to the given grammar.

Part B

Refer Part #1 of the Mini project on page 5.

2
THE OPEN UNIVERSITY OF SRI LANKA
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
ACADEMIC YEAR – 2010/ 11
BACHELOR OF SOFTWARE ENGINEERING
ECX5265 – SOFTWARE CONSTRUCTION - TMA 03

Important:
 Submission deadline December 29, 2010
 No late submissions will be accepted.

Part A [40 marks]

1. (a) Briefly describe the Turing Machine (TM) model.


(b) A Turing machine operating over the alphabet Σ = {0, 1} accepts only the strings
of the form 0n1n (n ≥ 0) ant the blank symbol B. For this TM,
i) Draw the transition graph. ii) Draw the transition table.
(c) List the moves made for the input string ’0011’ using instantaneous descriptions.

2. Consider the following grammar


S mAn | x | y
A ApS | S

(a) Find the leftmost and rightmost derivations for


i) mxpmxpxnn ii) mmxnpypmxnn
(b) Find the handle of each rightmost derivation.
(c) Find the viable prefixes of each string in part 2(a).
(d) What is an LR(k) grammar?

Part B

Refer Part #2 of the Mini project on page 6.

3
THE OPEN UNIVERSITY OF SRI LANKA
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
ACADEMIC YEAR – 2010/ 11
BACHELOR OF SOFTWARE ENGINEERING
ECX5265 – SOFTWARE CONSTRUCTION - MINI PROJECT

Consider the following Context Free Grammars for a compiler, called C --.

C -- Grammar

Program VarDeclList FunDeclList


VarDeclList epsilon
VarDecl VarDeclList
VarDecl Type id ;
Type id [ num] ;
FunDeclList FunDecl
FunDecl FunDeclList
FunDecl Type id ( ParamDecList ) Block
ParamDeclList epsilon
ParamDeclListTail
ParamDeclListTail ParamDecl
ParamDecl, ParamDeclListTail
ParamDecl Type id
Type id[]
Block { VarDeclList StmtList }
Type int
char
StmtList Stmt
Stmt StmtList
Stmt ;
Expr ;
return Expr ;
read id ;
write Expr ;
writeln ;
break ;
if ( Expr ) Stmt else Stmt
while ( Expr ) Stmt
Block

4
Expr Primary
UnaryOp Expr
Expr BinOp Expr
id = Expr
id [ Expr ] = Expr
Primary id
num
( Expr )
id ( ExprList )
id [ Expr ]
ExprList epsilon
ExprListTail
ExprListTail Expr
Expr , ExprListTail
UnaryOp -|!
BinOp + | - | * | / | == | != | < | <= | > | >= | && | ||

The given CFG is connected to Part B of TMA 02, 03 as well as your Mini project.
Mini project consists of altogether three parts (#1, #2 & Final).

MP - Part #1 [60 marks]

Design and implement a lexical analyzer for C -- as follows:


(You are expected to follow the steps listed below)

1. List the set of token types to be returned by your lexical analyzer.


2. Define regular expressions for this set of token types.
3. Derive a single DFA from your regular expressions.
4. Implement the DFA using any software you like (recommend C language). You
should implement the lexical analyzer as an implementation of the DFA where
each state in your DFA is a separate function.
--
5. Design a Recursive Decent parser by converting the C grammar to LL(1)
grammar.

5
MP - Part #2 [60 marks]

Implement a Recursive Decent parser for C -- as follows:


(You are expected to follow the steps listed below)

1. Implement a recursive decent parser that recognizes the LL(1) grammar. Use your
Part #1 solution as a starting point.
2. Test it and includes results in a descriptive form for the above steps.
3. Write down your code generator(s) in pseudo code.
4. Implement the code generator and complete C -- compiler.
Your compiler should take the name of a C -- program input file and produce a
stack machine code output file. It should be able to handle most (or all) of the
C -- program specifications described in Part #1, including function calls,
parameter transmission of both arrays and non-arrays, and global and local
variables etc.
5. Test it and includes results in a descriptive form for the above steps.

MP – Final (Due date: January 20, 2011)


1. Prepare complete documentation of your project including [50marks]
- An overview of the design of your compiler
- Main phases of your project (along with the interface designing of your compiler)
- Further improvements and drawbacks of your compiler.
PROJECT REPORT SHOULD BE SUBMITTED ON OR BEFORE THE DUE DATE.

2. VIVA/ Presentation (January 27, 2011) [50marks]


- Bring your implemented software with the source code.
- Include a copy of your LL(1) grammar.
- A sample of your parser's output including all essential features (and short) of your
C -- program.

- END.

S-ar putea să vă placă și