CD Outputs
CD Outputs
Experiment 1 output
Enter the c program
int main()
{
int a=10,20;
charch;
float f;
}^Z
The numbers in the program are: 10 20
The keywords and identifiersare:
int is a keyword
main is an identifier
int is a keyword
a is an identifier
char is a keyword
ch is an identifier
float is a keyword
f is an identifier
Special characters are ( ) { = , ; ; ; }
Experiment 2 output:
Input:
#include<stdio.h>
main()
{
int a,b;
}
Output:
#include<stdio.h> is a PREPROCESSOR DIRECTIVE
FUNCTION
main (
)
BLOCK BEGINS
int is a KEYWORD
a IDENTIFIER
b IDENTIFIER
BLOCK ENDS
$ cc y.tab.c -ll
./a.out
4 + t Accepted
( 5 * d + 5 ) Accepted
a + * 5 Rejected
Valid
0(0+b)
Invalid
answer=8
answer=0
syntax error
Experiment 3(d) output:
$lex int.l
$yacc –d int.y
$./a.out test.c
Pos Operator Arg1 Arg2 Result
0 < a b t0
1 == t0 FALSE 5
2 + a b t1
3 == t1 5
4 GOTO
5 < a b t2
6 == t2 FALSE 10
7 + a b t3
8 = t3 a
9 GOTO 5
10 <= a b t4
11 == t4 FALSE 15
12 - a b t5
13 = t5 c
14 GOTO 17
15 + a b t6
16 = t6 c
Experiment 4 output:
Enter the no of states: 3
Epsilon closure of q0 = { q0 q1 q2 }
Epsilon closure of q1 = { q1 q2 }
Epsilon closure of q2 = { q2 }
q0 0 q0
q0 1 q1
q0 e q1
q1 1 q2
q1 e q2
Experiment 5 output:
Experiment 6 output:
Enter the number of states
5
Move[0][0]-
Move[0][1]e
Move[0][2]-
Move[0][3]e
Move[0][4]-
Move[1][0]-
Move[1][1]-
Move[1][2]a
Move[1][3]-
Move[1][4]-
Move[2][0]-
Move[2][1]e
Move[2][2]-
Move[2][3]e
Move[2][4]-
Move[3][0]-
Move[3][1]-
Move[3][2]-
Move[3][3]-
Move[3][4]b
Move[4][0]-
Move[4][1]-
Move[4][2]-
Move[4][3]-
Move[4][4]-
ab
013 213 4
4
213 213 4
Experiment 7 OUTPUT:
a ,b
move(0,a);-1
move(0,b);-1
move(0,e);1
move(0,e);7
move(0,e);-1
move(1,a);-1
move(1,b);-1
move( 1,e);2
move(1,e);4
move(1,e);-1
move(2,a);3
move(2,a);3
move(2,a);-1
move(2,b);-1
move(2,e);-1
move(3,a);-1
move(3,b);-1
move(3,e);6
move(3,e);-1
move(4,a);-1
move(4,b);-1
move(4,e);-1
move(5,a);-1
move(5,b);-1
move(5,e);6
move(5,e);1
move(5,e);-1
move(6,a);-1
move(6,b);-1
move(6,e);-1
move(7,a);-1
move(7,b);-1
move(7,e);-1
EXPERIMENT 8 OUTPUT:
EXPERIMENT 9 OUTPUT:
Enter 8 productions:
E = TD
D=+TD
D=$
T=FS
S=*FS
S=$
F=(E)
F=a
EXPERIMENT 10 OUTPUT:
a+(a*a) a+a*a , (a), a , a+a+a*a+a.... etc are accepted
++a, a***a, +a, a*, ((a . . . etc are rejected.
EXPERIMENT 11 OUTPUT:
E
->
E+E
E
->
E*E
EXPERIMENT 12 OUTPUT:
Hello
Hello
Hello
Hello
Hello
EXPERIMENT 13 OUTPUT:
INPUT:
OUTPUT:
Optimized code is :
+ 3 b t1
+ 3 c t2
+ t1 t2 t3
EXPERIMENT 14 OUTPUT:
input.txt
+ a b t1
* c d t2
- t1 t2 t
=t?x
output.txt
MOV R0,a
ADD R0,b
MOV t1,R0
MOV R0,c
MUL R0,d
MOV t2,R0
MOV R0,t1
SUB R0,t2
MOV t,R0
MOV R0,t
MOV x,R0