go-antlr-calc

command module
v0.0.0-...-78834a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2020 License: MPL-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

= Go Antlr Calculator

Implements the calculator from chapter 4 of the Antlr book using Go (Golang).

You should buy the book, find a link for it at https://www.antlr.org/

The calculator is an example of Antlr's visitor pattern.

== Warning

I am not an Antlr expert, I haven't even finished reading the book.
If you find a better way please share!

== Setup

. Download the antlr jar and generate the parser for Go.
+
----
$ go generate -x
----

. Run the code and show the help:
+
----
$ go run main.go -h
----

. Run the code and get a single statement result:
+
----
$ go run main.go 1 + 2
  3
----

. Run the code and read statements from file:
+
----
$ go run main.go -f t.expr
> 193
  193
> a=5
  5
> b=6
  6
> a+b*2
  17
> (1+2)*3
  9
----

. Run the code as a repl:
+
----
$ go run main.go
> a = 1
  1
> b = 2
  2
> a + b
  3
----

== License

This file is part of go-antlr-calc.

Copyright (C) 2020  David Gamba Rios

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址