Skip to content

Uses ANTLR4 Javascript runtime to lex and parse input using rules from a grammar.

License

Notifications You must be signed in to change notification settings

baloodevil/antlr4-calculator-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uses ANTLR4 Javascript runtime to lex and parse input using rules from a grammar. It is derived from this Java example.

The Calculator grammar is in Calculator.g4. A compiled grammar that targets Javascript (instead of the default Java) generates .js and .token files (contained in 'js' folder).
To make changes to the grammar and recompile it, see here. To run the project, simply serve index.html from a web server. The easiest way to do that is to install http-server (an npm package) and run 'http-server' from the project folder and then open 'http://localhost:8080'.

Calculation is done as a user types. This is done by overriding functions from the generated Calculator...js files. Specifically, an listeners are attached to parser error events and listeners attached to rule matching events (to push entries onto the stack to do the actual math).

About

Uses ANTLR4 Javascript runtime to lex and parse input using rules from a grammar.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages