Small program for lexical analysis and syntax analysis implemented in java:coffee:
- Lexical Analysis: According to the input character sequence, convert the character sequence into a word
Token
sequence, identify each character, and give the corresponding type - Syntax analysis: According to the given grammar, judge whether it is
LL(1) grammar
, and analyze it from top to bottom. Predictive analysis method is adopted: starting from the grammar start character S, scan the source program from left to right, look forward 1 character at a time, select the appropriate production, and generate the leftmost derivation of the sentence. - step:
- Automatically distinguish between terminal
VT
and non-terminalVN
when reading a grammar from a file - Eliminate direct left recursion
- Generate
FIRST
andFOLLOW
collections - Check if it is an
LL(1)
grammar - Build a predictive analytics table
- Input the word string to be analyzed and automatically output the analysis process
- lexical analysis
- Parsing
- Determine whether it is an LL(1) grammar
- Put the
grammer
folder under the F drive, I also attached a file calledgrammer test.txt
in the code package, which contains the corresponding four grammars and the string examples that need to be input. - Run the Main main function, you can...