search
Log In
1 vote
938 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 938 views
6
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

@srestha mam

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

1
@Shaik

it is done before lexical analysis

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

References to printf and scanf are actually resolved by the linker by providing the object code for printf and scanf and other library functions.

In the preprocessing phase only function prototype are included in source code .

So the actual resolving done by linker .

That linking again of two types--

   Static linking 

   Dynamic linking

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

Related questions

9 votes
2 answers
1
1.1k views
I am writing down some errors and its type with a reason.If there something wrong please correct it with a valid reason. 1.fi(a==10) this is not a lexical error, because lexical analyzer cannot tell whether fi is a misspelling of the keyword if or an undeclared function ... is not a valid token. but this says it is streams of valid tokens 6.int d=10.10.10 lexical error as invalid num token.
asked Aug 14, 2017 in Compiler Design reena_kandari 1.1k views
2 votes
1 answer
2
393 views
The above diagram is Transition Diagrams for identifiers. As we can see that the identifier is said to be accepted if it starts with a letter and ends with a valid delimiter, which includes blank symbol, arithmetic, logical operator, left parenthesis, right parenthesis, +, ... ends with a delimiter and + is a valid delimiter and the error in declaration will not be detected at this stage...
asked Jun 9, 2019 in Compiler Design Hirak 393 views
1 vote
2 answers
3
772 views
which one of the following string can definitely said to be a token without looking at the next input: +(++,+=) return(return a) *(*=) =(==) ++ , ( ) ‘ ; option e is: plusplus, comma, bracket open, bracket close, single quote ;
asked Jun 5, 2019 in Compiler Design Rhythm 772 views
1 vote
3 answers
4
372 views
How will the compiler detect whether "if" is a keyword or an identifier? Please tell me the concept behind this.
asked Nov 7, 2018 in Compiler Design Lovejeet Singh 372 views
...