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

CD Outputs

Okay thanks you for submitting

Uploaded by

Surya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CD Outputs

Okay thanks you for submitting

Uploaded by

Surya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

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 ( ) { = , ; ; ; }

Total no. of lines are:5

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

Experiment 3(a) output:


$ yacc -d prog.y

$ cc y.tab.c -ll

./a.out

4 + t Accepted
( 5 * d + 5 ) Accepted

a + * 5 Rejected

Experiment 3(b) output:


a(a+0)

Valid

0(0+b)

Invalid

Experiment 3(c) output:


[CSE@localhost ~]$ lex cal.l

[CSE@localhost ~]$ yacc -d cal.y

[CSE@localhost ~]$ cc lex.yy.c y.tab.c -ll

[CSE@localhost ~]$ ./a.out

Enter the expression5+3

answer=8

[cse@NFSSERVER ~]$ ./a.out

Enter the expression5+-5

answer=0

[cse@NFSSERVER ~]$ ./a.out

Enter the expression+5/

syntax error
Experiment 3(d) output:
$lex int.l

$yacc –d int.y

$gcc lex.yy.c y.tab.c –ll –lm

$./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

Enter the states


q0
q1
q2

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:

Enter the no of input symbols:2

Enter the input symbols:

a ,b

Enter the transitions:(-1 to stop)

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:

How many productions? 8

Enter 8 productions:

E = TD
D=+TD
D=$
T=FS
S=*FS
S=$
F=(E)
F=a

FIRST (E) = FIRST (T) =FIRST (F) = { ( , a}


FIRST (D) = { + , ε }
FIRST (S)= { * , ε }

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:

Enter the number of productions:


3
Enter the productions on LEFT and RIGHT sides:
E
->
a

E
->
E+E
E
->
E*E

Enter the input string:


a*a+a
E*E+E
E*E
E

EXPERIMENT 12 OUTPUT:
Hello
Hello
Hello
Hello
Hello

EXPERIMENT 13 OUTPUT:

INPUT:

Enter the maximum number of expressions : 4

Enter the input :


=3-a
+ a b t1
+ a c t2
+ t1 t2 t3

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

You might also like