/Lexer-Parser

:loudspeaker:Compilation principle, lexical analyzer & syntax analyzer implemented by java, with running window:computer:,with instructions for use:green_book:

Primary LanguageJava

👀Lexer-Parser

Small program for lexical analysis and syntax analysis implemented in java:coffee:

Overview

  • 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:
  1. Automatically distinguish between terminal VT and non-terminal VN when reading a grammar from a file
  2. Eliminate direct left recursion
  3. Generate FIRST and FOLLOW collections
  4. Check if it is an LL(1) grammar
  5. Build a predictive analytics table
  6. Input the word string to be analyzed and automatically output the analysis process

📺result graph

  • lexical analysis

insert image description here

  • Parsing

insert image description here

insert image description here

  • Determine whether it is an LL(1) grammar

insert image description here

code structure

在这里插入图片描述

Instructions for use

  • Put the grammer folder under the F drive, I also attached a file called grammer 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...

insert image description here