A simple DFA that recognize words and comments.
This DFA is the first part in the creation of a Lexer. A lexer should take an input string and split it in his base elements: tokens. This DFA job is to recognize specifics tokens.
In this little project we have 3 classes:
- AbstractDFA: this class represent an arbitrary DFA with states and transitions;
- WordDFA: instantiated with a string, this DFA recognize the word specified;
- CommentDFA: DFA that recognise inline comments and multilines comments.
- Makefile: self explanatory, the file for the make command;
- automata.h: header file, with the declaration of the 3 classes.
- automata.cpp: file with classes initializations
- main.cpp: self explanatory.
You need to download ANTLR v4 from the official page and the c++ runtime dev libantlr4-runtime-dev.
You'll find some simple examples in the test directory. There is a Makefile to help you with compiling, using make
(use make clean
to reverse).
After compiling, with the test folder you can use:
./main test/test1.txt
- //comment
- (*comment*)
- {comment}
This project is a test I made for my university (Universita' degli Studi di Padova) in the Automata and Formal Language course, so the "skeleton" of the project is made by them.