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

Viewed 86987

for our compiler theory class, we are tasked with creating a simple interpreter for our own designed programming language. I am using jflex and cup as my generators but i'm a bit stuck with what a lexical error is. Also, is it recommended that i use the state feature of jflex? it feels wrong as it seems like the parser is better suited to handling that aspect. and do you recommend any other tools to create the language. I'm sorry if i'm impatient but it's due on tuesday.

4 Answers

lexical error is when the input doesn't belong to any of these lists: key words: "if", "else", "main"... symbols: '=','+',';'... double symbols: ">=", "<=", "!=", "++" variables: [a-z/A-Z]+[0-9]*
numbers: [0-9]*

examples: 9var: error, number before characters, not a variable and not a key word either. $: error

what I don't know is whether something like more than one symbol after each other is accepted, like "+-"

Related