Skip to content

spencerwooo/syntactic-analysis

Repository files navigation

syntactic-analysis

【编译原理】语法分析实验

Design

Usage

Install dependencies:

pipenv install

Enter Python virtual environment:

pipenv shell

Input files are located at:

.
└── test
    ├── input.c         // Input C file
    ├── input.token.xml // Tokenized C file (from last lexcial analysis)
    └── parse.xml       // Created XML file (from this syntatic analysis)

Main executables are located at:

.
├── grammar.txt      // Grammar file
├── main.py          // Main python file
├── parserGeneral.py // Create parse tree
└── parserUtils.py   // Analyze grammar, create LL(1) analyze table

Run a test with command:

python -u main.py

Which will produce the following outputs:

  1. Grammar:

  1. Terminal and non-terminal symbols:

  1. First and follow sets:

  1. LL(1) Parse table:

  1. Analyze stack:

  1. Grammar tree:

  1. XML Document:

Others

  1. firstsetgrammar.txt is for testing purposed only. You can try this grammar by uncommenting the following lines in main.py:
# 5. Demo: 分析一个串 i+i*i
inputString = 'i+i*i'
parserGeneral.parseInputString(
    inputString, grammar, terminalSymbols, nonTerminalSymbols, analyzeTable)

# Then comment the following lines in main.py until the end of the main function.
  1. logLevel = 10 will produce verbose logs, for most circumstances, logLevel = 1 will be sufficient.

About

【编译原理】语法分析实验

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published