Compilers
What is commonly used to express the rules for recognizing tokens in lexical analysis?
- AFloating-point rounding rules
- BRegular expressions, processed by finite automata
- CCache replacement policies
Show answer and explanation
Answer: B. Regular expressions, processed by finite automata
Token types can be written concisely as regular expressions, such as "a letter followed by letters or digits" for identifiers and "one or more digits" for numbers. Regular expressions convert to finite automata, machines with a finite number of states that change state with each character read, so tokens are extracted in time proportional to input length. Lexers are therefore often generated automatically from regular expressions by tools. Rounding and cache rules have nothing to do with lexical analysis.
- A. Rounding rules concern numerical computation.
- B. Correct. Rules are written as regular expressions and processed by finite automata.
- C. Cache replacement concerns the memory hierarchy.