基于 ANTLR4 编写的 Python 计算器 DEMO
Project description
geekcamp-calculator
基于 ANTLR4 编写的 Python 计算器 DEMO
环境准备
poetry install
poetry run antlr4 -Xexact-output-dir -o calculator/antlr4 -Dlanguage=Python3 calculator/grammar/CalculatorLexer.g4
poetry run antlr4 -Xexact-output-dir -o calculator/antlr4 -listener -visitor -Dlanguage=Python3 calculator/grammar/CalculatorParser.g4 calculator/grammar/CalculatorLexer.g4
单元测试
poetry run pytest -s
本地安装
poetry build -f wheel
pip install -U --user dist/geekcamp_calculator-*-py3-none-any.whl
列出 Python 包文件列表:
pip show geekcamp-calculator -f
终端输出:
Name: geekcamp-calculator
Version: 0.0.1.0
Summary:
Home-page:
Author: FifiLyu
Author-email: fifilyu@gmail.com
License:
Location: /home/user/.local/lib/python3.11/site-packages
Requires: antlr4-python3-runtime, antlr4-tools, pytest
Required-by:
Files:
../../../bin/pycalculator
__pycache__/gkcalculator.cpython-311.pyc
calculator/Calculator.py
calculator/__init__.py
calculator/__pycache__/Calculator.cpython-311.pyc
calculator/__pycache__/__init__.cpython-311.pyc
calculator/__pycache__/common.cpython-311.pyc
calculator/antlr4/CalculatorLexer.interp
calculator/antlr4/CalculatorLexer.py
calculator/antlr4/CalculatorLexer.tokens
calculator/antlr4/CalculatorParser.interp
calculator/antlr4/CalculatorParser.py
calculator/antlr4/CalculatorParser.tokens
calculator/antlr4/CalculatorParserListener.py
calculator/antlr4/CalculatorParserVisitor.py
calculator/antlr4/__pycache__/CalculatorLexer.cpython-311.pyc
calculator/antlr4/__pycache__/CalculatorParser.cpython-311.pyc
calculator/antlr4/__pycache__/CalculatorParserListener.cpython-311.pyc
calculator/antlr4/__pycache__/CalculatorParserVisitor.cpython-311.pyc
calculator/common.py
calculator/grammar/CalculatorLexer.g4
calculator/grammar/CalculatorParser.g4
calculator/parser/CalculatorBailLexer.py
calculator/parser/CustomErrorListener.py
calculator/parser/__init__.py
calculator/parser/__pycache__/CalculatorBailLexer.cpython-311.pyc
calculator/parser/__pycache__/CustomErrorListener.cpython-311.pyc
calculator/parser/__pycache__/__init__.cpython-311.pyc
geekcamp_calculator-0.0.1.0.dist-info/INSTALLER
geekcamp_calculator-0.0.1.0.dist-info/LICENSE
geekcamp_calculator-0.0.1.0.dist-info/METADATA
geekcamp_calculator-0.0.1.0.dist-info/RECORD
geekcamp_calculator-0.0.1.0.dist-info/REQUESTED
geekcamp_calculator-0.0.1.0.dist-info/WHEEL
geekcamp_calculator-0.0.1.0.dist-info/direct_url.json
geekcamp_calculator-0.0.1.0.dist-info/entry_points.txt
gkcalculator.py
使用方法
获取命令行工具执行路径:
python -c "import site; print('%s/bin/pycalculator' % site.USER_BASE)"
终端输出:
~/.local/bin/pycalculator
运行
~/.local/bin/pycalculator
分别输入 1+1==2;
、1+1=2;
操作演示:
2023-09-20 00:36:09 94943 [INFO] 未启用日志配置文件,加载默认设置
请输入表达式: 1+1==2;
2023-09-20 00:36:13 94943 [INFO] 语法识别:
1+1==2;
2023-09-20 00:36:13 94943 [DEBUG] Calculator.Antlr4->语法分析成功
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file geekcamp_calculator-0.0.1.2-py3-none-any.whl
.
File metadata
- Download URL: geekcamp_calculator-0.0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.1.52-1-lts
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45603d3b08d06fb9a199f08754f5f0c385c7992e435a1dadcc0556372fddb4fd |
|
MD5 | 44f6dd3030905ccbd72a5d846d6f74bd |
|
BLAKE2b-256 | 2300cd61c4162e09a50e1658c1d1e3dcb76199a7bb404aecc61def9846fca246 |