• Stars
    star
    201
  • Rank 194,491 (Top 4 %)
  • Language
    Java
  • License
    The Unlicense
  • Created about 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tiny Language with ANTLR 4

Tiny Language for ANTLR 4

In some blog posts I wrote a while ago, I demonstrated how to create a small dynamically typed programming language called Tiny Language using ANTLR 3.

However, ANTLR 4 is now the leaner (and meaner) version of the popular parser generator. Since the changes from v3 to v4 are significant, making Tiny Language work using ANTLR 4 is non trivial. Most notably, ANTLR 4 does not have any tree rewriting anymore. The new version generates listeners (and/or visitors) that can be used to walk the plain parse tree.

Get up and running

First, clone this repository:

git clone https://github.com/bkiers/tiny-language-antlr4.git
cd tiny-language-antlr4

Then generate the lexer, parser and visitor classes using the antlr4 Maven plugin:

mvn antlr4:antlr4

Compile all classes:

mvn install

and finally run the Main class (which executes the test.tl file):

mvn -q exec:java

Or, combine all the previous commands in a single liner:

mvn -q antlr4:antlr4 install exec:java

which should print:

All Assertions have passed.

No Maven?

If you're unfamiliar with Maven, and are reluctant to install it, here's how to perform all the steps from the (*nix) command line (assuming you're in the root folder of the project tiny-language-antlr4):

Download ANTLR 4:

wget http://www.antlr.org/download/antlr-4.7.1-complete.jar

Generate the lexer, parser and visitor classes and move them to the other .java project sources:

java -cp antlr-4.7.1-complete.jar \
  org.antlr.v4.Tool src/main/antlr4/tl/antlr4/TL.g4 \
  -package tl.antlr4 \
  -visitor

mv src/main/antlr4/tl/antlr4/*.java src/main/java/tl/antlr4

Compile all .java source files:

javac -cp antlr-4.7.1-complete.jar src/main/java/tl/antlr4/*.java

Run the Main class:

java -cp src/main/java:antlr-4.7.1-complete.jar tl.antlr4.Main

(Un)license

The Unlicense

More Repositories

1

retrofit-oauth

A Retrofit + Google OAuth demo.
Java
200
star
2

Liqp

An ANTLR based 'Liquid Template' parser and rendering engine.
Java
165
star
3

sqlite-parser

An ANTLR4 grammar for SQLite statements.
PLpgSQL
124
star
4

Mu

A small demonstration how to use ANTLR 4's visitor feature.
Java
113
star
5

rrd-antlr4

Railroad Diagrams for ANTLR 4 grammar rules.
ANTLR
101
star
6

python3-parser

An ANTLR4 grammar for Python 3
Python
40
star
7

GrahamScan

A Java implementation of the Graham Scan algorithm to find the convex hull of a set of points.
Java
37
star
8

pcre-parser

An ANTLR 4 grammar for PCRE
Java
30
star
9

CompGeom

A computational geometry library using arbitrary-precision arithmetic where possible, written in Java.
Java
26
star
10

RotatingCalipers

A Java implementation of the Rotating Calipers algorithm to find the minimum bounding rectangle of a set of points.
Java
24
star
11

PCREParser

An ANTLR 3 grammar for PCRE
Java
19
star
12

Curta

A small, customizable expression evaluator.
Java
16
star
13

ecmascript-parser

An ANTLR4 grammar for ECMAScript 5.1
Java
15
star
14

lua-parser

A Lua 5.3 parser and AST walker using ANTLR 3
GAP
14
star
15

atlas

Atlas, an offline reverse Geo-coding library written in Java.
Java
13
star
16

antlr4-csv-demo

ANTLR4-CSV-Demo
Java
10
star
17

PGN-parser

A Portable Game Notation (PGN) ANTLR 4 grammar and parser.
ANTLR
7
star
18

antlr-tree-rewriter-java

Java
4
star
19

antlr4android

An Android app with an ANTLR4 expression evaluator.
Java
4
star
20

ICalParser

An iCalendar (RFC 5545) parser backed up by an ANTLR v4 grammar.
Java
3
star
21

iri-parser

An ANTLR 4 grammar and parser for IRI (Internationalized Resource Identifiers).
ANTLR
3
star
22

uri-parser

An ANTLR4 grammar for URIs
ANTLR
2
star
23

antlr-tree-rewriter-cs

C#
1
star
24

ah-bonus-mailer

Albert Heijn bonus mailer
Python
1
star
25

xi

TypeScript
1
star
26

ada2012-parser

Ada
1
star
27

BigO.SPARQLParser

A C# SPARQL parser with rewrite possibilities
C#
1
star