GithubHelp home page GithubHelp logo

py3antlr4book's Introduction

py3antlr4book

Covert ANTLR4 book source code to Python 3 version.

How to use

Windows

  • Install Python
  • Install antlr4 python3 runtime
 pip install antlr4-python3-runtime
  • open command and run bin/antlr4.bat

You may need to compile the latest ANTLR4 and put it into bin, modify the bat file

You may also need to use the latest runtime, just copy the source to [PythonDir]\Lib\site-packages\antlr4

Ubuntu

sudo apt install environment-modules
sudo -H pip3 install antlr4-python3-runtime
git clone https://github.com/jszheng/py3antlr4book.git
cd py3antlr4book
# goto https://www.antlr.org/download.html 
# download the latest ver
wget https://www.antlr.org/download/antlr-4.7.2-complete.jar
ln -s antlr-4.7.2-complete.jar antlr.jar
module load ./antlr4module

run first example

% antlr4py3 Hello.g4
% pygrun Hello r --tokens input.txt
[@0,0:4='hello',<1>,1:0]
[@1,6:10='world',<2>,1:6]
[@2,11:10='<EOF>',<-1>,1:11]

% pygrun Hello r --tree input.txt
(r hello world)

% python test_hello.py input.txt
(r hello world)

IDE

You can install the best python IDE in the world (no 'one of') from www.jetbrains.com. They provide two community version free of charge and just enough for the experiment here.

The only problem is the tool take a large amount of memory just like all JAVA based IDE, you may not want to open IDEA and PyCharm at the same time. I only install IDEA and install the python community plug-in and also ANTLR4 plug-in to debug the .g4 file. IDEA example

py3antlr4book's People

Contributors

jszheng avatar lovemyliwu avatar niuniu4 avatar rbarzic avatar xiyusullos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py3antlr4book's Issues

What is pygrun?

What is bat-file mentioned in README and what is alias for pygrun?

Missing last char

Last char missing after beautifying lisp-like code in pygrun.

for i in range(1, len(in_string) - 1):

should be

for i in range(1, len(in_string)):

PyQt5

Would be great to have a PyQt5 version, I'm having 23483 problems installing pyqt4 on Mojave

Title of Project should be Py3

Is a minor issue but, should the title of this project be Covert ANTLR4 book source code to Py4 version.

maybe Py4 is a typo (?)

pygrun is wrong

when i run pygrun Hello r --tokens input.txt
Traceback (most recent call last):
File "/home/hehongbin/桌面/py3antlr4book-master/bin/pygrun", line 178, in
module_lexer = import(lexerName, globals(), locals(), lexerName)
File "/home/hehongbin/.local/lib/python3.8/site-packages/shiboken2/files.dir/shibokensupport/feature.py", line 142, in _import
return original_import(name, *args, **kwargs)
File "/home/hehongbin/桌面/py3antlr4book-master/01-Hello/./HelloLexer.py", line 25, in
class HelloLexer(Lexer):
File "/home/hehongbin/桌面/py3antlr4book-master/01-Hello/./HelloLexer.py", line 27, in HelloLexer
atn = ATNDeserializer().deserialize(serializedATN())
File "/usr/local/lib/python3.8/dist-packages/antlr4/atn/ATNDeserializer.py", line 28, in deserialize
self.checkVersion()
File "/usr/local/lib/python3.8/dist-packages/antlr4/atn/ATNDeserializer.py", line 50, in checkVersion
raise Exception("Could not deserialize ATN with version " + str(version) + " (expected " + str(SERIALIZED_VERSION) + ").")
Exception: Could not deserialize ATN with version (expected 4).
this question arises, how can i solve this question?thanks

Where are the examples of ch9

Hi,

I tried to use the same python API as Java. For example,

parser.removeErrorListeners()
parser.addErrorListener(VerboseListener())

But, it does not work, and it still uses ConsoleErrorListener with outputs like:

line 1:7 token recognition error at: '('

BTW, I use python3 and antlr4 v4.5.3.

pygrun -g option not working

It seems that the GUI Version of the tree with pygrun cannot be displayed, at least I could not run it. It seems that also the -t option is necessary to even have a chance to view the GUI Version. I have little experience with Qt but i would be happy to help in testing.
Otherwise I suggest to remove the -g option completely.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.