Skip to content
/ Mu Public
forked from bkiers/Mu

A small demonstration how to use ANTLR 4's visitor feature.

Notifications You must be signed in to change notification settings

w3b-net-au/Mu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Mu

A small expression parser, using ANTLR 4. It supports most basic operators and for-, while- and log- (print) statements. It is just a basic demonstration of how to use the -visitor functionality of ANTLR 4.

To run the demo script:

Mu has string interpolation with the dollar sign prepended to a string, for example log $"Variable is {varName}";

n = 9
m = true

foo = "foo"
bar = 1
baz = true

log $"foo = {foo} bar = {bar} baz = {baz}"

unless !m log $ "m is {m}"

while n > 0 {

  # expressions can be surrounded by parenthesis, of course
  if (n % 2 == 0) {
    log $ "{n} -> even"
  }
  else {
    log $ "{n} -> odd"
  }

  n = n - 1
}

unless n == 0 log "n is not 0"

for j = 1 to 10
  log $"Hello, World j = {j}"
next

do:

git clone git://github.com/bkiers/Mu.git
mvn clean install
mvn -q exec:java

which will print the following to your console:

parsing: src/main/mu/test.mu
foo = foo bar = 1.0 baz = true
m is true
9.0 -> odd
8.0 -> even
7.0 -> odd
6.0 -> even
5.0 -> odd
4.0 -> even
3.0 -> odd
2.0 -> even
1.0 -> odd
Hello, World j = 1.0
Hello, World j = 2
Hello, World j = 3
Hello, World j = 4
Hello, World j = 5
Hello, World j = 6
Hello, World j = 7
Hello, World j = 8
Hello, World j = 9
Hello, World j = 10

Also see this stackoverflow Q&A.

About

A small demonstration how to use ANTLR 4's visitor feature.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 96.1%
  • ANTLR 3.3%
  • mupad 0.6%