Hi,
I am a noob to the world of compilers, was trying to compile and play with the grammer for Python2(in Golang), and the code generated by antlr4 seems to be giving compile issues. Please check below for more information:
- Antlr Installation: I installed antlr basis the instruction given here.
- Python2 Grammer: I am using the grammer in the git repo here. I am at the commit hash: 1b1ba88ef71d9e53ef55abcb8ed25be02dffea98
- Golang version: 1.11 darwin/amd64
- ANTLR version: 4
- The code I am using to invoke the everything is mentioned below, along with the errors:
package main
import (
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/test/parser"
"os"
"fmt"
)
type TreeShapeListener struct {
*parser.BasePython2Listener
}
func NewTreeShapeListener() *TreeShapeListener {
return new(TreeShapeListener)
}
func (this *TreeShapeListener) EnterEveryRule(ctx antlr.ParserRuleContext) {
fmt.Println(ctx.GetText())
}
func main() {
input, _ := antlr.NewFileStream(os.Args[1])
lexer := parser.NewPython2Lexer(input)
stream := antlr.NewCommonTokenStream(lexer,0)
p := parser.NewPython2Parser(stream)
p.AddErrorListener(antlr.NewDiagnosticErrorListener(true))
p.BuildParseTrees = true
tree := p.Json()
antlr.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)
}
and the errors I get are:
parser/python2_lexer.go:13:1: syntax error: non-declaration statement outside function body
parser/python2_lexer.go:529:5: invalid character U+0023 '#'
parser/python2_lexer.go:529:7: syntax error: non-declaration statement outside function body
parser/python2_lexer.go:541:19: syntax error: unexpected !=, expecting name
parser/python2_lexer.go:554:37: invalid character literal (more than one character)
parser/python2_lexer.go:559:48: invalid character literal (more than one character)
parser/python2_lexer.go:568:51: invalid character literal (more than one character)
parser/python2_lexer.go:572:49: invalid character literal (more than one character)
parser/python2_lexer.go:635:30: syntax error: unexpected and, expecting {
parser/python2_lexer.go:636:15: syntax error: unexpected self, expecting {
parser/python2_lexer.go:636:15: too many errors
Am I doing something wrong , or is this broken?!?!