You are on page 1of 3

lab 1

1. Write a C program that will behave as a deterministic finite automata which


accepts strings of odd number 0s and even number of 1s.
2. Write a C program that will convert a non-deterministic finite automata to its
deterministic finite automata using appropriate data structures.

lab2
1. Consider the following set of tokens
{begin,end,if,then,else,identifier,constant,<,<=,=,<>,>,>=} and write C programs
for the following
(a) Two-dimension array represention of a DFA accepting each of the tokens.
(b) Compressed representation of the same DFA using four arrays defined as
follows
base array - determines base location of entries for state s (base[s])
next array - entry for next state of s (r) on input a next[base[s] + a]= r
check array - stores check[base[s] + a] = s for a valid transition from s to
r on input a
default array - alternative base location if check[base[s] + a] = s
State transition alogrithm
nextState(s,a)
if check[base[s] + a] = s then
return next[base[s] + a]
else
return nextState(default[s],a)
end if
Note: (i) Consider ASCII character set as alphabet set
(ii) Refer the lecture slides for the DFA
2. Compare them with respect to token recognition time and memory space saved.
3. Design a DFA using LEX/FLEX that will recoginize a valid identifier. A valid
identifier is a string whose starting symbol belongs to [A-Z],[a-z]
,_ while rest of the symbols belong to [A-Z],[a-z],_,[0-9].
4. An input alphabet consists of the following twenty eight symbols - ONE, TWO,
THREE, FOUR, FIVE, SIX, SEVEN , EIGHT, NINE, TEN,
ELEVEN, TWELVE, THIRTEEN, FORTEEN , FIFTEEN, SIXTEEN ,SEVENTEEN, EIGHTEEN,
NINETEEN, TWENTY, THIRTY, FOURTY, FIFTY,
SIXTY, SEVENTY, EIGHTY, NINETY, HUNDRED. Design a DFA using LEX/FLEX that accepts
as input the English language representation
(e.g. ONE HUNDRED THIRTY FIVE) of any symbol from 1 to 999 and outputs the
equivalent decimal number (135 in this case).

lab3
1. Write a program to obtain Chomsky's Normal Form of a given context free grammar.
2. Write a program to check whether a context free grammar is left recursive.
3. Write a program to eliminate left recursion from a left recursive context free
grammar.

lab4
1. Design a parser using Bison that will derive the strings belonging to the
language a^nb^n.
2. Design a parser using Bison that will verify the correctness of the strings
belonging to the language of grammar G having rules S->iCtSeS|iCtS|a, C->b.
3. Design a parser using Bison that will verify the correctness of the parenthesis
for string belonging to the language of grammar G having rules S->(S)|id
4. Design a parser using Bison that generates any number between 0 and 999 in
words.
Input: 249 Output: Two Hundred and Forty Nine

Note: The parsers should print the errors if the input string is not derived.
lab5
Problem 1:
Consider the following grammar rules
E -> E + E
E -> E * E
E -> id
Design a calculator using Flex and Bison. The calculator solve expressions
containing positive integers.
The application will parse the expression and then evaluate it if the expression is
syntactically correct.
Consider multiplication operator '*' has higher precedence than the addition
operator '+'. Specify the errors
encountered if found.

Problem 2:
Design an LR(0) parser by hand that will check the validity of proposition logic
expressions and
generate its truth table and report whether the expression is a
tautology/fallacy/satisfactory.

Valid Tokens
1. A-Z (excluding T and F), a-z (excluding t and f) are tokens of length 1
represent Boolean variables
whole values are either T/t for true or F/f for false.
2. T/t and F/f are constants representing true and false respectively.
3. Operator /\ stands for 'AND'.
4. Operator \/ stands for 'OR'.
5. Operator ~ stands for 'NOT'.
6. Operator -> stands for 'implication'.
7. Operator <-> stands for 'if and only if'.
8. Operator ( stands for 'opening parenthesis'.
9. Operator ) stands for 'closing parenthesis'.

Operator Precedence Associativity

maximum () Left
~ Right
<-> Left
-> Left
/\ Left
minimum \/ Left

Errors Handled by this system

1. Lexical Error occurs when invalid tokens are found. The error and its position
in the imput string should
be displayed.
2. Syntax or Parse Error:
(i) Incomplete expression.
(ii) Operator missing when two operands are consecutive.
(iii) Expression missing when open parenthesis and close parenthesis are
consecutive elements in the input
string and vice versa.
(iv) Operand missing for a binary operator.
(v) Operand missing for an unary operator.
(vi) Consecutive Binary Operators -> operand missing.
(vii) Missing of ( for a ).

Problem 3:
Solve problem 2 using Flex and Bison.

lab 6
Design a Flex-Bison application that will convert a document in bibtex to xml. A
supporting
document is provided as an attachment.

lab 7
1. Write a bison program to recognize string with grammar { a^nb^nc^n | n>=1}.
2. Write a bison program to that takes a signed binary number string as input,
evaluates the corresponding decimal value and outputs it.
Ex: -1101 will be evaluated as -13.

lab8
Consider a grammar G
S-> id := E
E-> E1 + E2 | E1 * E2 | -E1 | (E1) | id
Design a translation scheme to generate three-address intermediate code for the
strings belonging to L(G).
The attached material contains
1. The translation rules and actions
2. A trace for the input A:=-B*(C+D) as a sample output

You might also like