A lexical analyzer uses the following regular expressions to recognise tokens in a programming language:
A lexical analyzer uses the following regular expressions to recognise tokens in a programming language:
Identifier (ID): (letter)(letter|digit)*
Number (NUM): (digit)+(\.(digit)+)?
Relational Operator (REL_OP): < <= > >= == !=
Whitespace: (blank|tab|newline)+
Consider the input string:
count<=total1
If the lexical analyzer applies maximal munch (longest match rule) and priority-based resolution (in the order: REL_OP > NUM > ID > WHITESPACE), what will be the correct sequence of tokens recognised?
Show answerHide answer
Correct answer: (A) ⟨ID, count⟩ ⟨REL_OP, <=⟩ ⟨ID, total1⟩