JavaCC is a lexer and parser generator for LL(k) grammars. You specify a language’s lexical and syntactic description in a JJ file, then run javacc on the JJ file. You will get seven java files as output, including a lexer and a parser.
We’ll look at three things you can do with JavaCC
Do a simple syntax check only ( Lexical Analysis )
JavaCC will generate seven classes each in a separate file.
TokenMgrError is a simple error class; it is used for errors detected by the lexical analyser and is a subclass of Throwable
ParseException is another error class; it is used for errors detected by the parser and is a subclass of Exception and hence of Throwable
Token is a class representing tokens. Each Token object has an integer ﬁeld kind that represents the kind of the token (PLUS, NUMBER, or EOF) and a String ﬁeld image, which represents the sequence of characters from the input ﬁle that the token represents
SimpleCharStream is an adapter class that delivers characters to the lexical analyser
BasicConstants is an interface that deﬁnes a number of classes used in both the lexical analyser and the parser
BasicTokenManager is the lexical analyser
Basic is the parser
Next Step is to compile these classes with a javac command. For example
Text inside the example.txt file is