What is an example of a lexical error and is it possible that a language has no lexical errors?

A lexical error is any input that can be rejected by the lexer. This generally results from token recognition falling off the end of the rules you’ve defined. For example (in no particular syntax):

[0-9]+   ===> NUMBER token
[a-zA-Z] ===> LETTERS token
anything else ===> error!

If you think about a lexer as a finite state machine that accepts valid input strings, then errors are going to be any input strings that do not result in that finite state machine reaching an accepting state.

The rest of your question was rather unclear to me. If you already have some tools you are using, then perhaps you’re best to learn how to achieve what you want to achieve using those tools (I have no experience with either of the tools you mentioned).

EDIT: Having re-read your question, there’s a second part I can answer. It is possible that a language could have no lexical errors – it’s the language in which any input string at all is valid input.

Leave a Comment