Vensim grammar built in ANTLR 4

Usage no npm install needed!

<script type="module">
  import antlr4Vensim from '';


antlr4-vensim Vensim grammar in ANTLR 4

Using the parser

Install the package with npm in your project.

npm install antlr4-vensim

Require the lexer, parser, and/or visitor.

const { ModelLexer, ModelParser, ModelVisitor } = require('antlr4-vensim')

Refer to the ANTLR 4 JavaScript runtime documentation for further details about using the parser.

Installing tools

The grammar development tools in this package require macOS. They are not required to use the parser.

Vensim grammar development uses the ANTLR 4 parser generator.

Install the latest Java SE JDK. We are only using Java for development purposes, which is covered by the license for Java SE.

Install ANTLR 4 Java tools version 4.8.

cd /usr/local/lib
sudo curl -O

Set up ANTLR 4 in .bash_profile.

export CLASSPATH=".:/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH"

Developing the parser

Build the parser after modifying the grammar.

npm install
npm run build

The build process generates a Vensim parser in JavaScript in the parser directory.


Command line utility

The a4 script generates and runs a lexer and parser in Java. It is useful in development when you are trying to understand how the lexer is tokenizing your model and what parse tree the parser is generating.


./a4 generate

Generate the parser in Java (not JavaScript) in the java directory.


./a4 lex <mdl-file-pathname>

Run the lexer on the .mdl file to print the token stream. The generate command must be run first.


./a4 tree <mdl-file-pathname>

Run the parser on the .mdl file to print the parse tree. The generate command must be run first.


./a4 clean

Clean out the generated parser files in the java directory.


./a4 tokens

Print the lexer token list.