The Gateway to Computer Science Excellence
+1 vote
512 views
Find no of tokens in below program.

#include<stdio.h>

main()

{

   int I;

   int *pi = &I; //parent pointer

   scanf("%d",pi);

   printf("%d\n", I+5);

}
in Compiler Design by (69 points) | 512 views
+4
L1:main()
L2:{
L3: int I;
L4: int *pi = &I; //parent pointer

L5 : scanf("%d",pi);
L6 : printf("%d\n", I+5);
L7: }

L1 : 3 ; L2 : 1 ; L3 : 3 ; L4 : 7; L5 : 7 ; L6 : 9 ; L7 : 1

So total number of tokens : 31
0
I am getting 31

What is answer ?
0
what about header file?
0
Lexical analysis of header file is not done
0

@Sayan Bose

Lexical analysis of header file is not done

WHY? is there any standard reference?

0
0

@srestha mam

then how the printf and scanf or some other can resolve? ( i mean at what phase of compiler )

0
@Shaik

it is done before lexical analysis

In preprocessing phase (macro also done there)
0
i am getting total num of tokens as 32

1 Answer

+1 vote
statement # of tokens
#include<stdio.h> 0(zero)
main() 3
{ 1
   int I; 3
   int *pi = &I; //parent pointer 7
 scanf("%d",pi); 7
   printf("%d\n", I+5); 9
} 1
Total 31
by (289 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,645 questions
56,615 answers
195,894 comments
102,332 users