edited by
1,490 views
0 votes
0 votes

Question1. Count number of Distinct tokens and lexemes in following code

{

float a=20.6;

float b=19.8;

float c=19.8;

float a=20.6;

float c=15.7;

printf("Hello!How r u");

printf("I am Good");

}

Doubt:- Does float constants and string constants like(20,6/19.8/printf string) will be counted as different tokens or same token?

There is multiple declarations of some variables  in above code,but i am only concerned about lexical analysis o/p.

I dont have the answer as it is self made question

Question 2 : Nuber of lexemes will always be same as number of tokens?

Question 3. Number of distinct lexemes will always be same as number of distinct tokens?

I have read following statement from dragon

In a compiler, the lexical analyzer reads the characters of the source program,
groups them into lexically meaningful units called lexemes, and produces
as output tokens representing these lexemes.

So i guess lexems and tokens are same as token is just a representation of lexemes associated with it?So by this the answer to 2 and 3 statement will be true?

edited by

Please log in or register to answer this question.

Related questions

5 votes
5 votes
1 answer
2
rahul sharma 5 asked Oct 9, 2017
5,591 views
void main(){i/*nt*/a=10;return;}Number of tokens in above code:?
8 votes
8 votes
2 answers
4
vishwa ratna asked Jan 18, 2017
4,984 views
The number of tokens in following program?# define M 100 int main ( ) { // declare variables int n = 2020; return n % M; }Your Answer:19Correct Answer: 16 Status: inco...