in Compiler Design
4,641 views
6 votes
6 votes

Given answer is 25, while my answer is 26, they have considered -10.0 as single token, which is wrong?

in Compiler Design
4.6k views

4 Comments

yes, it should be 26.
1
1
  1. Keywords               (int, while,etc),
  2. Identifiers               ( main, total,etc),
  3. Constants              ( 10, 20),
  4. Strings                    ( “total”, “hello”),
  5. Special symbols  ( (,), {,} etc),
  6. Operators              ( +, /,-,*,etc)

So yes 26. Minus is included.

1
1
But floating point constants are also allowed right @manu00x , @Joshi_nItIsh , @Warlock lord ?
0
0

1 Answer

1 vote
1 vote

Ans is 25

Sol

i think you done mistak -10.0 take tow token but only 1.

Lexical analyzer checks for a longest valid lexeme which matches the pattern in case of "<=", it is the longest valid pattern so it will see "-10.0" as one pattern (as it is also a longest valid pattern).

edited by

4 Comments

lexical analysis, syntax analysis and symantic checking

all happens in lexer ??

 

Why? then what is the use of parser if lexer will do syntax analysis.

and parsers with SDD does semantic checking right ? 

1
1

you are right @Aakash_

0
0
yes

lexical analysis for lexical error

parser for syntax error

semantic analyzer for semantic error

now right?
0
0