search
Log In
5 votes
323 views

Consider the following code

$x =  (y + 5) + (^*z)  * 10 - x /3 $

Which of the following correctly identified by lexical analysis after scanning the above code?

  1. 5 Identifiers
  2. 3 literals
  3. 4 Identifiers
  4. 6 literals
in Compiler Design 323 views
0
4 identifier, 3 literals
0
Ashwini are u considering x as two literals?
0

Ashwani Kumar 2 why considering x as 2 identifiers?

0
Why will be only 3 literals?
0
$5,10,3$
0
So, The answer should be 3 identifiers and 3 literals.
0
Constant literals: 5, 10, 3

Identifiers: x, y, z

x should be counted once...
0
answer given is 4 Identifiers
0
I think it should be 3,3
0
What is the number of tokens here ???
0
18 (if we don't count *z as one, I am unsure about that)
0

manisha11 *z is not one token $18$ is correct

1
Okay
and what if it is x +=  y?
we will count that as 3/4?
0
$3,$ += counted as single assignment operator
0
Thanks a lot!
0
what will be answer for this acc to me it is 3 identifier 3 literals  18 tokens please verify

1 Answer

1 vote
x=(y+5)+(∗z)∗10−x/3

Here, Identifiers are X, Y, Z.

Literals are constant numbers 5, 10, 3.

Wheras the rest are operators.

So, answer is 3 Identifiers and 3 Literals.

Refer this, https://www.cse.iitk.ac.in/users/karkare/cs335/lectures/04LexicalAanalysis.pdf

Related questions

2 votes
1 answer
1
391 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 391 views
2 votes
1 answer
3
222 views
Given Solution: It is given that Program 4 will cause Lexical error as ..09 is octal and assigned to int -- But Lexical analyzer just treat 09 as constant ..So program 4 will give Semantic error than lexical Correct me if i am wrong
asked Nov 23, 2018 in Compiler Design jatin khachane 1 222 views
...