in Compiler Design edited by
5,025 views
3 votes
3 votes

The number of tokens in the following C code segment is

switch(inputvalue)
{
    case 1 : b =c*d; break;
    default : b =b++; break;
}
  1. $27$
  2. $29$
  3. $26$
  4. $24$
in Compiler Design edited by
by
5.0k views

3 Answers

6 votes
6 votes

$\underline{\textbf{Answer:}\Rightarrow}\;\mathbf{c.}$

The number of tokens are:

  1. switch
  2. (
  3. inputvalue
  4. )
  5. {
  6. case
  7. 1
  8. :
  9. b
  10. =
  11. c
  12. *
  13. d
  14. ;
  15. break
  16. ;
  17. default
  18. :
  19. b
  20. =
  21. b
  22. ++
  23. ;
  24. break
  25. ;
  26. }
edited by
by
2 votes
2 votes
switch

(

inputvalue

)

{

case

1

:

b

=

c

*

d

;

break

;

default

:

b

=

b

++

;

break

;

}

i got 26 token
1 vote
1 vote

The tokens in the code segment are as follows:

  1. switch - Keyword
  2. ( - Punctuation
  3. inputvalue - Identifier
  4. ) - Punctuation
  5. { - Punctuation
  6. case - Keyword
  7. 1 - Integer Literal
  8. : - Punctuation
  9. b - Identifier
  10. = - Operator
  11. c - Identifier
  12.  Operator
  13. d - Identifier
  14. ; - Punctuation
  15. break - Keyword
  16. ; - Punctuation
  17. default - Keyword
  18. : - Punctuation
  19. b - Identifier
  20. = - Operator
  21. b - Identifier
  22. ++ - Operator
  23. ; - Punctuation
  24. break - Keyword
  25. ; - Punctuation
  26. } - Punctuation

Therefore, the number of tokens in the given C code segment is 26.

 

 

Answer:

Related questions