/LexicalAnalyzer

a simple Lexical Analyzer made for my principles of programming languages class

Primary LanguageJava

LexicalAnalyzer

a simple Lexical Analyzer made for my principles of programming languages class The directions were as follows

The objective of this project is to implement a lexical analyzer that accepts the 24 token categories plus the following keywords, all in lowercase letters only: if, else, switch, case, default, while, do, for, print, false, true These keywords cannot be used as identifiers, but can be parts of identifiers, like "iff" and "delse". In this and the next three projects, we assume that the identifiers and keywords are case-sensitive. The implementation should be based on the above DFA. Your lexical analyzer program should clearly separate the driver and the state-transition function so that the driver will remain invariant and only state-transition functions will change from DFA to DFA. The enumerated or integer type is suggested for representation of states.

The following keyword recognition method is adequate for this project. Create 11 additional DFA states for the keywords. The DFA initially accepts the keywords as identifiers. Each time the DFA accepts an identifier, check if it is one of the keywords, and if so, move the DFA to the corresponding state. The lexical analyzer program is to read an input text file, extract the tokens in it, and write them out one by one on separate lines. Each token should be flagged with its category. The output should be sent to an output text file. Whenever invalid tokens are found, error messages should be printed, and the reading process should continue.