Approaches to implementation
. Use assembly language
Most efficient but most difficult to implement
. Use high level languages like C
Efficient but difficult to implement
. Use tools like lex, flex
Easy to implement but not as efficient as the first two cases
Lexical analyzers can be implemented using many approaches/techniques:
. Assembly language : We have to take input and read it character by character. So we need to have control over low level I/O. Assembly language is the best option for that because it is the most efficient. This implementation produces very efficient lexical analyzers. However, it is most difficult to implement, debug and maintain.
. High level language like C: Here we will have a reasonable control over I/O because of high-level constructs. This approach is efficient but still difficult to implement.
. Tools like Lexical Generators and Parsers: This approach is very easy to implement, only specifications of the lexical analyzer or parser need to be written. The lex tool produces the corresponding C code. But this approach is not very efficient which can sometimes be an issue.
We can also use a hybrid approach wherein we use high level languages or efficient tools to produce the basic code and if there are some hot-spots (some functions are a bottleneck) then they can be replaced by fast and efficient assembly language routines.
|