Some cleanup

This commit is contained in:
Peter Boyer 2016-01-11 14:51:59 -05:00
parent 260ccd056b
commit 20e3b385ab
30 changed files with 0 additions and 3830 deletions

View File

@ -1,34 +0,0 @@
package main
import (
"antlr4"
"./parser"
"os"
)
type TreeShapeListener struct {
*parser.BaseTListener
}
func NewTreeShapeListener() *TreeShapeListener {
return new(TreeShapeListener)
}
func (this *TreeShapeListener) EnterEveryRule(ctx antlr4.ParserRuleContext) {
for i := 0; i<ctx.GetChildCount(); i++ {
child := ctx.GetChild(i)
parentR,ok := child.GetParent().(antlr4.RuleNode)
if !ok || parentR.GetBaseRuleContext() != ctx.GetBaseRuleContext() {
panic("Invalid parse tree shape detected.")
}
}
}
func main() {
input := antlr4.NewFileStream(os.Args[1])
lexer := parser.NewTLexer(input)
stream := antlr4.NewCommonTokenStream(lexer,0)
p := parser.NewTParser(stream)
p.BuildParseTrees = true
tree := p.Expression()
antlr4.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)
}

View File

@ -1 +0,0 @@
a

View File

@ -1,20 +0,0 @@
grammar T;
ifStatement
@after {
List<?> __ttt__ = $ctx.elseIfStatement();
}
: 'if' expression
( ( 'then'
executableStatement*
elseIfStatement* // <--- problem is here; should yield a list not node
elseStatement?
'end' 'if'
) | executableStatement )
;
elseIfStatement
: 'else' 'if' expression 'then' executableStatement*
;
expression : 'a' ;
executableStatement : 'a' ;
elseStatement : 'a' ;

View File

@ -1,10 +0,0 @@
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
'if'=1
'then'=2
'end'=3
'else'=4
'a'=5

View File

@ -1,38 +0,0 @@
// Generated from /var/folders/64/k10py5tj6r72zsmq16t6zy3r0000gn/T/TestParserExec-1452205020397/parser/T.g4 by ANTLR 4.5.1
package parser // T
import "antlr4"
// A complete base listener for a parse tree produced by TParser
type BaseTListener struct {
}
func (s *BaseTListener) VisitTerminal(node antlr4.TerminalNode){}
func (s *BaseTListener) VisitErrorNode(node antlr4.ErrorNode){}
func (s *BaseTListener) EnterEveryRule(ctx antlr4.ParserRuleContext){}
func (s *BaseTListener) ExitEveryRule(ctx antlr4.ParserRuleContext){}
func (s *BaseTListener) EnterIfStatement(ctx *IfStatementContext) {}
func (s *BaseTListener) ExitIfStatement(ctx *IfStatementContext){}
func (s *BaseTListener) EnterElseIfStatement(ctx *ElseIfStatementContext) {}
func (s *BaseTListener) ExitElseIfStatement(ctx *ElseIfStatementContext){}
func (s *BaseTListener) EnterExpression(ctx *ExpressionContext) {}
func (s *BaseTListener) ExitExpression(ctx *ExpressionContext){}
func (s *BaseTListener) EnterExecutableStatement(ctx *ExecutableStatementContext) {}
func (s *BaseTListener) ExitExecutableStatement(ctx *ExecutableStatementContext){}
func (s *BaseTListener) EnterElseStatement(ctx *ElseStatementContext) {}
func (s *BaseTListener) ExitElseStatement(ctx *ElseStatementContext){}

View File

@ -1,24 +0,0 @@
// Generated from /var/folders/64/k10py5tj6r72zsmq16t6zy3r0000gn/T/TestParserExec-1452205020397/parser/T.g4 by ANTLR 4.5.1
package parser // T
import "antlr4"
type BaseTVisitor struct {
*antlr4.BaseParseTreeVisitor
}
func (v *BaseTVisitor) VisitIfStatement(ctx *IfStatementContext) interface{} {
return v.VisitChildren(ctx)
}
func (v *BaseTVisitor) VisitElseIfStatement(ctx *ElseIfStatementContext) interface{} {
return v.VisitChildren(ctx)
}
func (v *BaseTVisitor) VisitExpression(ctx *ExpressionContext) interface{} {
return v.VisitChildren(ctx)
}
func (v *BaseTVisitor) VisitExecutableStatement(ctx *ExecutableStatementContext) interface{} {
return v.VisitChildren(ctx)
}
func (v *BaseTVisitor) VisitElseStatement(ctx *ElseStatementContext) interface{} {
return v.VisitChildren(ctx)
}

View File

@ -1,77 +0,0 @@
// Generated from /var/folders/64/k10py5tj6r72zsmq16t6zy3r0000gn/T/TestParserExec-1452205020397/parser/T.g4 by ANTLR 4.5.1
package parser
import (
"antlr4"
"fmt"
)
// suppress unused import error, many tests
// require fmt.
var _ = fmt.Printf
var serializedLexerAtn = []uint16{ 3,1072,54993,33286,44333,17431,44785,
36224,43741,2,7,32,8,1,4,2,9,2,4,3,9,3,4,4,9,4,4,5,9,5,4,6,9,6,3,2,3,
2,3,2,3,3,3,3,3,3,3,3,3,3,3,4,3,4,3,4,3,4,3,5,3,5,3,5,3,5,3,5,3,6,3,
6,2,2,7,3,3,5,4,7,5,9,6,11,7,3,2,2,31,2,3,3,2,2,2,2,5,3,2,2,2,2,7,3,
2,2,2,2,9,3,2,2,2,2,11,3,2,2,2,3,13,3,2,2,2,5,16,3,2,2,2,7,21,3,2,2,
2,9,25,3,2,2,2,11,30,3,2,2,2,13,14,7,107,2,2,14,15,7,104,2,2,15,4,3,
2,2,2,16,17,7,118,2,2,17,18,7,106,2,2,18,19,7,103,2,2,19,20,7,112,2,
2,20,6,3,2,2,2,21,22,7,103,2,2,22,23,7,112,2,2,23,24,7,102,2,2,24,8,
3,2,2,2,25,26,7,103,2,2,26,27,7,110,2,2,27,28,7,117,2,2,28,29,7,103,
2,2,29,10,3,2,2,2,30,31,7,99,2,2,31,12,3,2,2,2,3,2,2, }
var lexerDeserializer = antlr4.NewATNDeserializer(nil)
var lexerAtn = lexerDeserializer.DeserializeFromUInt16( serializedLexerAtn )
var lexerModeNames = []string{ "DEFAULT_MODE" }
var lexerLiteralNames = []string{ "", "'if'", "'then'", "'end'", "'else'",
"'a'" }
var lexerSymbolicNames = []string{ }
var lexerRuleNames = []string{ "T__0", "T__1", "T__2", "T__3", "T__4" }
type TLexer struct {
*antlr4.BaseLexer
modeNames []string
// EOF string
}
func NewTLexer(input antlr4.CharStream) *TLexer {
var lexerDecisionToDFA = make([]*antlr4.DFA,len(lexerAtn.DecisionToState))
for index, ds := range lexerAtn.DecisionToState {
lexerDecisionToDFA[index] = antlr4.NewDFA(ds, index)
}
lex := new(TLexer)
lex.BaseLexer = antlr4.NewBaseLexer(input)
lex.Interpreter = antlr4.NewLexerATNSimulator(lex, lexerAtn, lexerDecisionToDFA, antlr4.NewPredictionContextCache())
lex.modeNames = lexerModeNames
lex.RuleNames = lexerRuleNames
lex.LiteralNames = lexerLiteralNames
lex.SymbolicNames = lexerSymbolicNames
lex.GrammarFileName = "T.g4"
//lex.EOF = antlr4.TokenEOF
return lex
}
const (
TLexerT__0 = 1
TLexerT__1 = 2
TLexerT__2 = 3
TLexerT__3 = 4
TLexerT__4 = 5
)
const (
)

View File

@ -1,10 +0,0 @@
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
'if'=1
'then'=2
'end'=3
'else'=4
'a'=5

View File

@ -1,26 +0,0 @@
// Generated from /var/folders/64/k10py5tj6r72zsmq16t6zy3r0000gn/T/TestParserExec-1452205020397/parser/T.g4 by ANTLR 4.5.1
package parser // T
import "antlr4"
// A complete listener for a parse tree produced by TParser
type TListener interface {
antlr4.ParseTreeListener
EnterIfStatement(*IfStatementContext)
ExitIfStatement(*IfStatementContext)
EnterElseIfStatement(*ElseIfStatementContext)
ExitElseIfStatement(*ElseIfStatementContext)
EnterExpression(*ExpressionContext)
ExitExpression(*ExpressionContext)
EnterExecutableStatement(*ExecutableStatementContext)
ExitExecutableStatement(*ExecutableStatementContext)
EnterElseStatement(*ElseStatementContext)
ExitElseStatement(*ElseStatementContext)
}

View File

@ -1,663 +0,0 @@
// Generated from /var/folders/64/k10py5tj6r72zsmq16t6zy3r0000gn/T/TestParserExec-1452205020397/parser/T.g4 by ANTLR 4.5.1
package parser // T
import (
"antlr4"
"reflect"
"fmt"
"strconv"
)
// Stopgap to suppress unused import error. We aren't certain
// to have these imports used in the generated code below
var _ = fmt.Printf
var _ = reflect.Copy
var _ = strconv.Itoa
// Stopgap to shadow the Java types of the same name
type String string
var parserATN = []uint16{ 3,1072,54993,33286,44333,17431,44785,36224,43741,
3,7,52,4,2,9,2,4,3,9,3,4,4,9,4,4,5,9,5,4,6,9,6,3,2,3,2,3,2,3,2,7,2,17,
10,2,12,2,14,2,20,11,2,3,2,7,2,23,10,2,12,2,14,2,26,11,2,3,2,5,2,29,
10,2,3,2,3,2,3,2,5,2,34,10,2,3,3,3,3,3,3,3,3,3,3,7,3,41,10,3,12,3,14,
3,44,11,3,3,4,3,4,3,5,3,5,3,6,3,6,3,6,2,2,7,2,4,6,8,10,2,2,51,2,12,3,
2,2,2,4,35,3,2,2,2,6,45,3,2,2,2,8,47,3,2,2,2,10,49,3,2,2,2,12,13,7,3,
2,2,13,33,5,6,4,2,14,18,7,4,2,2,15,17,5,8,5,2,16,15,3,2,2,2,17,20,3,
2,2,2,18,16,3,2,2,2,18,19,3,2,2,2,19,24,3,2,2,2,20,18,3,2,2,2,21,23,
5,4,3,2,22,21,3,2,2,2,23,26,3,2,2,2,24,22,3,2,2,2,24,25,3,2,2,2,25,28,
3,2,2,2,26,24,3,2,2,2,27,29,5,10,6,2,28,27,3,2,2,2,28,29,3,2,2,2,29,
30,3,2,2,2,30,31,7,5,2,2,31,34,7,3,2,2,32,34,5,8,5,2,33,14,3,2,2,2,33,
32,3,2,2,2,34,3,3,2,2,2,35,36,7,6,2,2,36,37,7,3,2,2,37,38,5,6,4,2,38,
42,7,4,2,2,39,41,5,8,5,2,40,39,3,2,2,2,41,44,3,2,2,2,42,40,3,2,2,2,42,
43,3,2,2,2,43,5,3,2,2,2,44,42,3,2,2,2,45,46,7,7,2,2,46,7,3,2,2,2,47,
48,7,7,2,2,48,9,3,2,2,2,49,50,7,7,2,2,50,11,3,2,2,2,7,18,24,28,33,42, }
var deserializer = antlr4.NewATNDeserializer(nil)
var deserializedATN = deserializer.DeserializeFromUInt16( parserATN )
var literalNames = []string{ "", "'if'", "'then'", "'end'", "'else'", "'a'" }
var symbolicNames = []string{ }
var ruleNames = []string{ "ifStatement", "elseIfStatement", "expression",
"executableStatement", "elseStatement" }
type TParser struct {
*antlr4.BaseParser
}
func NewTParser(input antlr4.TokenStream) *TParser {
var decisionToDFA = make([]*antlr4.DFA,len(deserializedATN.DecisionToState))
var sharedContextCache = antlr4.NewPredictionContextCache()
for index, ds := range deserializedATN.DecisionToState {
decisionToDFA[index] = antlr4.NewDFA(ds, index)
}
parser := new(TParser)
parser.BaseParser = antlr4.NewBaseParser(input)
parser.Interpreter = antlr4.NewParserATNSimulator(parser, deserializedATN, decisionToDFA, sharedContextCache)
parser.RuleNames = ruleNames
parser.LiteralNames = literalNames
parser.SymbolicNames = symbolicNames
parser.GrammarFileName = "T.g4"
return parser
}
const(
TParserEOF = antlr4.TokenEOF
TParserT__0 = 1
TParserT__1 = 2
TParserT__2 = 3
TParserT__3 = 4
TParserT__4 = 5
)
const (
TParserRULE_ifStatement = 0
TParserRULE_elseIfStatement = 1
TParserRULE_expression = 2
TParserRULE_executableStatement = 3
TParserRULE_elseStatement = 4
)
// an interface to support dynamic dispatch (subclassing)
type IIfStatementContext interface {
antlr4.ParserRuleContext
getParser() antlr4.Parser
}
type IfStatementContext struct {
*antlr4.BaseParserRuleContext
parser antlr4.Parser
}
func NewEmptyIfStatementContext() *IfStatementContext {
var p = new(IfStatementContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( nil, -1 )
p.RuleIndex = TParserRULE_ifStatement
return p
}
func NewIfStatementContext(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int) *IfStatementContext {
var p = new(IfStatementContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( parent, invokingState )
p.parser = parser
p.RuleIndex = TParserRULE_ifStatement
// TODO initialize list attrs
return p
}
func (s *IfStatementContext) getParser() antlr4.Parser { return s.parser }
func (s *IfStatementContext) Expression() interface{} {
return s.GetTypedRuleContext(reflect.TypeOf((*ExpressionContext)(nil)).Elem(),0)
}
func (s *IfStatementContext) ExecutableStatement(i int) interface{} {
if i < 0 {
return s.GetTypedRuleContexts(reflect.TypeOf((*ExecutableStatementContext)(nil)).Elem())
} else {
return s.GetTypedRuleContext(reflect.TypeOf((*ExecutableStatementContext)(nil)).Elem(),i)
}
}
func (s *IfStatementContext) ElseIfStatement(i int) interface{} {
if i < 0 {
return s.GetTypedRuleContexts(reflect.TypeOf((*ElseIfStatementContext)(nil)).Elem())
} else {
return s.GetTypedRuleContext(reflect.TypeOf((*ElseIfStatementContext)(nil)).Elem(),i)
}
}
func (s *IfStatementContext) ElseStatement() interface{} {
return s.GetTypedRuleContext(reflect.TypeOf((*ElseStatementContext)(nil)).Elem(),0)
}
func (s *IfStatementContext) GetRuleContext() antlr4.RuleContext {
// Go does not truly support inheritance nor virtual method calls, so we need to implement this directly
return s
}
func (s *IfStatementContext) EnterRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.EnterIfStatement(s)
}
}
func (s *IfStatementContext) ExitRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.ExitIfStatement(s)
}
}
func (s *IfStatementContext) Accept(visitor antlr4.ParseTreeVisitor) interface{} {
switch t := visitor.(type) {
case TVisitor:
return t.VisitIfStatement(s)
default:
return t.VisitChildren(s)
}
}
func (p *TParser) IfStatement() IIfStatementContext {
var localctx IIfStatementContext = NewIfStatementContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 0, TParserRULE_ifStatement)
var _la int
defer func(){
p.ExitRule()
}()
defer func() {
if err := recover(); err != nil {
if v, ok := err.(antlr4.RecognitionException); ok {
localctx.SetException( v )
p.GetErrorHandler().ReportError(p, v)
p.GetErrorHandler().Recover(p, v)
} else {
panic(err)
}
}
}()
p.EnterOuterAlt(localctx, 1)
p.SetState(10)
p.Match(TParserT__0)
p.SetState(11)
p.Expression()
p.SetState(31)
switch p.GetTokenStream().LA(1) {
case TParserT__1:
p.SetState(12)
p.Match(TParserT__1)
p.SetState(16)
p.GetErrorHandler().Sync(p)
_alt := p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),0,p.GetParserRuleContext())
for _alt!=2 && _alt!= antlr4.ATNInvalidAltNumber {
if(_alt==1) {
p.SetState(13)
p.ExecutableStatement()
}
p.SetState(18)
p.GetErrorHandler().Sync(p)
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),0,p.GetParserRuleContext())
}
p.SetState(22)
p.GetErrorHandler().Sync(p)
_la = p.GetTokenStream().LA(1);
for _la==TParserT__3 {
p.SetState(19)
p.ElseIfStatement()
p.SetState(24)
p.GetErrorHandler().Sync(p)
_la = p.GetTokenStream().LA(1);
}
p.SetState(26)
_la = p.GetTokenStream().LA(1);
if _la==TParserT__4 {
p.SetState(25)
p.ElseStatement()
}
p.SetState(28)
p.Match(TParserT__2)
p.SetState(29)
p.Match(TParserT__0)
case TParserT__4:
p.SetState(30)
p.ExecutableStatement()
default:
panic(antlr4.NewNoViableAltException(p, nil, nil, nil, nil, nil))
}
List<?> __ttt__ = localctx.elseIfStatement();
return localctx
}
// an interface to support dynamic dispatch (subclassing)
type IElseIfStatementContext interface {
antlr4.ParserRuleContext
getParser() antlr4.Parser
}
type ElseIfStatementContext struct {
*antlr4.BaseParserRuleContext
parser antlr4.Parser
}
func NewEmptyElseIfStatementContext() *ElseIfStatementContext {
var p = new(ElseIfStatementContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( nil, -1 )
p.RuleIndex = TParserRULE_elseIfStatement
return p
}
func NewElseIfStatementContext(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int) *ElseIfStatementContext {
var p = new(ElseIfStatementContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( parent, invokingState )
p.parser = parser
p.RuleIndex = TParserRULE_elseIfStatement
// TODO initialize list attrs
return p
}
func (s *ElseIfStatementContext) getParser() antlr4.Parser { return s.parser }
func (s *ElseIfStatementContext) Expression() interface{} {
return s.GetTypedRuleContext(reflect.TypeOf((*ExpressionContext)(nil)).Elem(),0)
}
func (s *ElseIfStatementContext) ExecutableStatement(i int) interface{} {
if i < 0 {
return s.GetTypedRuleContexts(reflect.TypeOf((*ExecutableStatementContext)(nil)).Elem())
} else {
return s.GetTypedRuleContext(reflect.TypeOf((*ExecutableStatementContext)(nil)).Elem(),i)
}
}
func (s *ElseIfStatementContext) GetRuleContext() antlr4.RuleContext {
// Go does not truly support inheritance nor virtual method calls, so we need to implement this directly
return s
}
func (s *ElseIfStatementContext) EnterRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.EnterElseIfStatement(s)
}
}
func (s *ElseIfStatementContext) ExitRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.ExitElseIfStatement(s)
}
}
func (s *ElseIfStatementContext) Accept(visitor antlr4.ParseTreeVisitor) interface{} {
switch t := visitor.(type) {
case TVisitor:
return t.VisitElseIfStatement(s)
default:
return t.VisitChildren(s)
}
}
func (p *TParser) ElseIfStatement() IElseIfStatementContext {
var localctx IElseIfStatementContext = NewElseIfStatementContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 2, TParserRULE_elseIfStatement)
defer func(){
p.ExitRule()
}()
defer func() {
if err := recover(); err != nil {
if v, ok := err.(antlr4.RecognitionException); ok {
localctx.SetException( v )
p.GetErrorHandler().ReportError(p, v)
p.GetErrorHandler().Recover(p, v)
} else {
panic(err)
}
}
}()
p.EnterOuterAlt(localctx, 1)
p.SetState(33)
p.Match(TParserT__3)
p.SetState(34)
p.Match(TParserT__0)
p.SetState(35)
p.Expression()
p.SetState(36)
p.Match(TParserT__1)
p.SetState(40)
p.GetErrorHandler().Sync(p)
_alt := p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),4,p.GetParserRuleContext())
for _alt!=2 && _alt!= antlr4.ATNInvalidAltNumber {
if(_alt==1) {
p.SetState(37)
p.ExecutableStatement()
}
p.SetState(42)
p.GetErrorHandler().Sync(p)
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(),4,p.GetParserRuleContext())
}
return localctx
}
// an interface to support dynamic dispatch (subclassing)
type IExpressionContext interface {
antlr4.ParserRuleContext
getParser() antlr4.Parser
}
type ExpressionContext struct {
*antlr4.BaseParserRuleContext
parser antlr4.Parser
}
func NewEmptyExpressionContext() *ExpressionContext {
var p = new(ExpressionContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( nil, -1 )
p.RuleIndex = TParserRULE_expression
return p
}
func NewExpressionContext(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int) *ExpressionContext {
var p = new(ExpressionContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( parent, invokingState )
p.parser = parser
p.RuleIndex = TParserRULE_expression
// TODO initialize list attrs
return p
}
func (s *ExpressionContext) getParser() antlr4.Parser { return s.parser }
func (s *ExpressionContext) GetRuleContext() antlr4.RuleContext {
// Go does not truly support inheritance nor virtual method calls, so we need to implement this directly
return s
}
func (s *ExpressionContext) EnterRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.EnterExpression(s)
}
}
func (s *ExpressionContext) ExitRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.ExitExpression(s)
}
}
func (s *ExpressionContext) Accept(visitor antlr4.ParseTreeVisitor) interface{} {
switch t := visitor.(type) {
case TVisitor:
return t.VisitExpression(s)
default:
return t.VisitChildren(s)
}
}
func (p *TParser) Expression() IExpressionContext {
var localctx IExpressionContext = NewExpressionContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 4, TParserRULE_expression)
defer func(){
p.ExitRule()
}()
defer func() {
if err := recover(); err != nil {
if v, ok := err.(antlr4.RecognitionException); ok {
localctx.SetException( v )
p.GetErrorHandler().ReportError(p, v)
p.GetErrorHandler().Recover(p, v)
} else {
panic(err)
}
}
}()
p.EnterOuterAlt(localctx, 1)
p.SetState(43)
p.Match(TParserT__4)
return localctx
}
// an interface to support dynamic dispatch (subclassing)
type IExecutableStatementContext interface {
antlr4.ParserRuleContext
getParser() antlr4.Parser
}
type ExecutableStatementContext struct {
*antlr4.BaseParserRuleContext
parser antlr4.Parser
}
func NewEmptyExecutableStatementContext() *ExecutableStatementContext {
var p = new(ExecutableStatementContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( nil, -1 )
p.RuleIndex = TParserRULE_executableStatement
return p
}
func NewExecutableStatementContext(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int) *ExecutableStatementContext {
var p = new(ExecutableStatementContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( parent, invokingState )
p.parser = parser
p.RuleIndex = TParserRULE_executableStatement
// TODO initialize list attrs
return p
}
func (s *ExecutableStatementContext) getParser() antlr4.Parser { return s.parser }
func (s *ExecutableStatementContext) GetRuleContext() antlr4.RuleContext {
// Go does not truly support inheritance nor virtual method calls, so we need to implement this directly
return s
}
func (s *ExecutableStatementContext) EnterRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.EnterExecutableStatement(s)
}
}
func (s *ExecutableStatementContext) ExitRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.ExitExecutableStatement(s)
}
}
func (s *ExecutableStatementContext) Accept(visitor antlr4.ParseTreeVisitor) interface{} {
switch t := visitor.(type) {
case TVisitor:
return t.VisitExecutableStatement(s)
default:
return t.VisitChildren(s)
}
}
func (p *TParser) ExecutableStatement() IExecutableStatementContext {
var localctx IExecutableStatementContext = NewExecutableStatementContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 6, TParserRULE_executableStatement)
defer func(){
p.ExitRule()
}()
defer func() {
if err := recover(); err != nil {
if v, ok := err.(antlr4.RecognitionException); ok {
localctx.SetException( v )
p.GetErrorHandler().ReportError(p, v)
p.GetErrorHandler().Recover(p, v)
} else {
panic(err)
}
}
}()
p.EnterOuterAlt(localctx, 1)
p.SetState(45)
p.Match(TParserT__4)
return localctx
}
// an interface to support dynamic dispatch (subclassing)
type IElseStatementContext interface {
antlr4.ParserRuleContext
getParser() antlr4.Parser
}
type ElseStatementContext struct {
*antlr4.BaseParserRuleContext
parser antlr4.Parser
}
func NewEmptyElseStatementContext() *ElseStatementContext {
var p = new(ElseStatementContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( nil, -1 )
p.RuleIndex = TParserRULE_elseStatement
return p
}
func NewElseStatementContext(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int) *ElseStatementContext {
var p = new(ElseStatementContext)
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( parent, invokingState )
p.parser = parser
p.RuleIndex = TParserRULE_elseStatement
// TODO initialize list attrs
return p
}
func (s *ElseStatementContext) getParser() antlr4.Parser { return s.parser }
func (s *ElseStatementContext) GetRuleContext() antlr4.RuleContext {
// Go does not truly support inheritance nor virtual method calls, so we need to implement this directly
return s
}
func (s *ElseStatementContext) EnterRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.EnterElseStatement(s)
}
}
func (s *ElseStatementContext) ExitRule(listener antlr4.ParseTreeListener) {
if listenerT, ok := listener.(TListener); ok {
listenerT.ExitElseStatement(s)
}
}
func (s *ElseStatementContext) Accept(visitor antlr4.ParseTreeVisitor) interface{} {
switch t := visitor.(type) {
case TVisitor:
return t.VisitElseStatement(s)
default:
return t.VisitChildren(s)
}
}
func (p *TParser) ElseStatement() IElseStatementContext {
var localctx IElseStatementContext = NewElseStatementContext(p, p.GetParserRuleContext(), p.GetState())
p.EnterRule(localctx, 8, TParserRULE_elseStatement)
defer func(){
p.ExitRule()
}()
defer func() {
if err := recover(); err != nil {
if v, ok := err.(antlr4.RecognitionException); ok {
localctx.SetException( v )
p.GetErrorHandler().ReportError(p, v)
p.GetErrorHandler().Recover(p, v)
} else {
panic(err)
}
}
}()
p.EnterOuterAlt(localctx, 1)
p.SetState(47)
p.Match(TParserT__4)
return localctx
}

View File

@ -1,27 +0,0 @@
// Generated from /var/folders/64/k10py5tj6r72zsmq16t6zy3r0000gn/T/TestParserExec-1452205020397/parser/T.g4 by ANTLR 4.5.1
package parser // T
import "antlr4"
// A complete Visitor for a parse tree produced by TParser.
type TVisitor interface {
antlr4.ParseTreeVisitor
// Visit a parse tree produced by TParser#ifStatement.
VisitIfStatement(ctx *IfStatementContext) interface{}
// Visit a parse tree produced by TParser#elseIfStatement.
VisitElseIfStatement(ctx *ElseIfStatementContext) interface{}
// Visit a parse tree produced by TParser#expression.
VisitExpression(ctx *ExpressionContext) interface{}
// Visit a parse tree produced by TParser#executableStatement.
VisitExecutableStatement(ctx *ExecutableStatementContext) interface{}
// Visit a parse tree produced by TParser#elseStatement.
VisitElseStatement(ctx *ElseStatementContext) interface{}
}

View File

@ -1,146 +0,0 @@
// Generated from Arithmetic.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link ArithmeticListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class ArithmeticBaseListener implements ArithmeticListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEquation(ArithmeticParser.EquationContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEquation(ArithmeticParser.EquationContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExpression(ArithmeticParser.ExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExpression(ArithmeticParser.ExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterMultiplyingExpression(ArithmeticParser.MultiplyingExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitMultiplyingExpression(ArithmeticParser.MultiplyingExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterPowExpression(ArithmeticParser.PowExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitPowExpression(ArithmeticParser.PowExpressionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAtom(ArithmeticParser.AtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAtom(ArithmeticParser.AtomContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterScientific(ArithmeticParser.ScientificContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitScientific(ArithmeticParser.ScientificContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterRelop(ArithmeticParser.RelopContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitRelop(ArithmeticParser.RelopContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterNumber(ArithmeticParser.NumberContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitNumber(ArithmeticParser.NumberContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterVariable(ArithmeticParser.VariableContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitVariable(ArithmeticParser.VariableContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

View File

@ -1,120 +0,0 @@
// Generated from Arithmetic.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class ArithmeticLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
LPAREN=1, RPAREN=2, PLUS=3, MINUS=4, TIMES=5, DIV=6, GT=7, LT=8, EQ=9,
POINT=10, E=11, POW=12, LETTER=13, DIGIT=14, WS=15;
public static String[] modeNames = {
"DEFAULT_MODE"
};
public static final String[] ruleNames = {
"LPAREN", "RPAREN", "PLUS", "MINUS", "TIMES", "DIV", "GT", "LT", "EQ",
"POINT", "E", "POW", "LETTER", "DIGIT", "WS"
};
private static final String[] _LITERAL_NAMES = {
null, "'('", "')'", "'+'", "'-'", "'*'", "'/'", "'>'", "'<'", "'='", "'.'",
null, "'^'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, "LPAREN", "RPAREN", "PLUS", "MINUS", "TIMES", "DIV", "GT", "LT",
"EQ", "POINT", "E", "POW", "LETTER", "DIGIT", "WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public ArithmeticLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "Arithmetic.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2\21E\b\1\4\2\t\2\4"+
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
"\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\3\2\3\2\3\3\3\3\3\4"+
"\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\13\3\13\3\f\3\f"+
"\3\r\3\r\3\16\5\16;\n\16\3\17\3\17\3\20\6\20@\n\20\r\20\16\20A\3\20\3"+
"\20\2\2\21\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33"+
"\17\35\20\37\21\3\2\5\4\2GGgg\4\2C\\c|\5\2\13\f\17\17\"\"E\2\3\3\2\2\2"+
"\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2"+
"\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2"+
"\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\3!\3\2\2\2\5#\3\2\2\2\7%\3\2\2"+
"\2\t\'\3\2\2\2\13)\3\2\2\2\r+\3\2\2\2\17-\3\2\2\2\21/\3\2\2\2\23\61\3"+
"\2\2\2\25\63\3\2\2\2\27\65\3\2\2\2\31\67\3\2\2\2\33:\3\2\2\2\35<\3\2\2"+
"\2\37?\3\2\2\2!\"\7*\2\2\"\4\3\2\2\2#$\7+\2\2$\6\3\2\2\2%&\7-\2\2&\b\3"+
"\2\2\2\'(\7/\2\2(\n\3\2\2\2)*\7,\2\2*\f\3\2\2\2+,\7\61\2\2,\16\3\2\2\2"+
"-.\7@\2\2.\20\3\2\2\2/\60\7>\2\2\60\22\3\2\2\2\61\62\7?\2\2\62\24\3\2"+
"\2\2\63\64\7\60\2\2\64\26\3\2\2\2\65\66\t\2\2\2\66\30\3\2\2\2\678\7`\2"+
"\28\32\3\2\2\29;\t\3\2\2:9\3\2\2\2;\34\3\2\2\2<=\4\62;\2=\36\3\2\2\2>"+
"@\t\4\2\2?>\3\2\2\2@A\3\2\2\2A?\3\2\2\2AB\3\2\2\2BC\3\2\2\2CD\b\20\2\2"+
"D \3\2\2\2\5\2:A\3\2\3\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -1,99 +0,0 @@
// Generated from Arithmetic.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link ArithmeticParser}.
*/
public interface ArithmeticListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link ArithmeticParser#equation}.
* @param ctx the parse tree
*/
void enterEquation(ArithmeticParser.EquationContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#equation}.
* @param ctx the parse tree
*/
void exitEquation(ArithmeticParser.EquationContext ctx);
/**
* Enter a parse tree produced by {@link ArithmeticParser#expression}.
* @param ctx the parse tree
*/
void enterExpression(ArithmeticParser.ExpressionContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#expression}.
* @param ctx the parse tree
*/
void exitExpression(ArithmeticParser.ExpressionContext ctx);
/**
* Enter a parse tree produced by {@link ArithmeticParser#multiplyingExpression}.
* @param ctx the parse tree
*/
void enterMultiplyingExpression(ArithmeticParser.MultiplyingExpressionContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#multiplyingExpression}.
* @param ctx the parse tree
*/
void exitMultiplyingExpression(ArithmeticParser.MultiplyingExpressionContext ctx);
/**
* Enter a parse tree produced by {@link ArithmeticParser#powExpression}.
* @param ctx the parse tree
*/
void enterPowExpression(ArithmeticParser.PowExpressionContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#powExpression}.
* @param ctx the parse tree
*/
void exitPowExpression(ArithmeticParser.PowExpressionContext ctx);
/**
* Enter a parse tree produced by {@link ArithmeticParser#atom}.
* @param ctx the parse tree
*/
void enterAtom(ArithmeticParser.AtomContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#atom}.
* @param ctx the parse tree
*/
void exitAtom(ArithmeticParser.AtomContext ctx);
/**
* Enter a parse tree produced by {@link ArithmeticParser#scientific}.
* @param ctx the parse tree
*/
void enterScientific(ArithmeticParser.ScientificContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#scientific}.
* @param ctx the parse tree
*/
void exitScientific(ArithmeticParser.ScientificContext ctx);
/**
* Enter a parse tree produced by {@link ArithmeticParser#relop}.
* @param ctx the parse tree
*/
void enterRelop(ArithmeticParser.RelopContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#relop}.
* @param ctx the parse tree
*/
void exitRelop(ArithmeticParser.RelopContext ctx);
/**
* Enter a parse tree produced by {@link ArithmeticParser#number}.
* @param ctx the parse tree
*/
void enterNumber(ArithmeticParser.NumberContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#number}.
* @param ctx the parse tree
*/
void exitNumber(ArithmeticParser.NumberContext ctx);
/**
* Enter a parse tree produced by {@link ArithmeticParser#variable}.
* @param ctx the parse tree
*/
void enterVariable(ArithmeticParser.VariableContext ctx);
/**
* Exit a parse tree produced by {@link ArithmeticParser#variable}.
* @param ctx the parse tree
*/
void exitVariable(ArithmeticParser.VariableContext ctx);
}

View File

@ -1,704 +0,0 @@
// Generated from Arithmetic.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class ArithmeticParser extends Parser {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
LPAREN=1, RPAREN=2, PLUS=3, MINUS=4, TIMES=5, DIV=6, GT=7, LT=8, EQ=9,
POINT=10, E=11, POW=12, LETTER=13, DIGIT=14, WS=15;
public static final int
RULE_equation = 0, RULE_expression = 1, RULE_multiplyingExpression = 2,
RULE_powExpression = 3, RULE_atom = 4, RULE_scientific = 5, RULE_relop = 6,
RULE_number = 7, RULE_variable = 8;
public static final String[] ruleNames = {
"equation", "expression", "multiplyingExpression", "powExpression", "atom",
"scientific", "relop", "number", "variable"
};
private static final String[] _LITERAL_NAMES = {
null, "'('", "')'", "'+'", "'-'", "'*'", "'/'", "'>'", "'<'", "'='", "'.'",
null, "'^'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, "LPAREN", "RPAREN", "PLUS", "MINUS", "TIMES", "DIV", "GT", "LT",
"EQ", "POINT", "E", "POW", "LETTER", "DIGIT", "WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "Arithmetic.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public ArithmeticParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class EquationContext extends ParserRuleContext {
public List<ExpressionContext> expression() {
return getRuleContexts(ExpressionContext.class);
}
public ExpressionContext expression(int i) {
return getRuleContext(ExpressionContext.class,i);
}
public RelopContext relop() {
return getRuleContext(RelopContext.class,0);
}
public EquationContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_equation; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterEquation(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitEquation(this);
}
}
public final EquationContext equation() throws RecognitionException {
EquationContext _localctx = new EquationContext(_ctx, getState());
enterRule(_localctx, 0, RULE_equation);
try {
enterOuterAlt(_localctx, 1);
{
setState(18);
expression();
setState(19);
relop();
setState(20);
expression();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ExpressionContext extends ParserRuleContext {
public List<MultiplyingExpressionContext> multiplyingExpression() {
return getRuleContexts(MultiplyingExpressionContext.class);
}
public MultiplyingExpressionContext multiplyingExpression(int i) {
return getRuleContext(MultiplyingExpressionContext.class,i);
}
public List<TerminalNode> PLUS() { return getTokens(ArithmeticParser.PLUS); }
public TerminalNode PLUS(int i) {
return getToken(ArithmeticParser.PLUS, i);
}
public List<TerminalNode> MINUS() { return getTokens(ArithmeticParser.MINUS); }
public TerminalNode MINUS(int i) {
return getToken(ArithmeticParser.MINUS, i);
}
public ExpressionContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expression; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterExpression(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitExpression(this);
}
}
public final ExpressionContext expression() throws RecognitionException {
ExpressionContext _localctx = new ExpressionContext(_ctx, getState());
enterRule(_localctx, 2, RULE_expression);
int _la;
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(22);
multiplyingExpression();
setState(27);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,0,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
setState(23);
_la = _input.LA(1);
if ( !(_la==PLUS || _la==MINUS) ) {
_errHandler.recoverInline(this);
} else {
consume();
}
setState(24);
multiplyingExpression();
}
}
}
setState(29);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,0,_ctx);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class MultiplyingExpressionContext extends ParserRuleContext {
public List<PowExpressionContext> powExpression() {
return getRuleContexts(PowExpressionContext.class);
}
public PowExpressionContext powExpression(int i) {
return getRuleContext(PowExpressionContext.class,i);
}
public List<TerminalNode> TIMES() { return getTokens(ArithmeticParser.TIMES); }
public TerminalNode TIMES(int i) {
return getToken(ArithmeticParser.TIMES, i);
}
public List<TerminalNode> DIV() { return getTokens(ArithmeticParser.DIV); }
public TerminalNode DIV(int i) {
return getToken(ArithmeticParser.DIV, i);
}
public MultiplyingExpressionContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_multiplyingExpression; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterMultiplyingExpression(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitMultiplyingExpression(this);
}
}
public final MultiplyingExpressionContext multiplyingExpression() throws RecognitionException {
MultiplyingExpressionContext _localctx = new MultiplyingExpressionContext(_ctx, getState());
enterRule(_localctx, 4, RULE_multiplyingExpression);
int _la;
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(30);
powExpression();
setState(35);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,1,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
setState(31);
_la = _input.LA(1);
if ( !(_la==TIMES || _la==DIV) ) {
_errHandler.recoverInline(this);
} else {
consume();
}
setState(32);
powExpression();
}
}
}
setState(37);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,1,_ctx);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class PowExpressionContext extends ParserRuleContext {
public AtomContext atom() {
return getRuleContext(AtomContext.class,0);
}
public TerminalNode POW() { return getToken(ArithmeticParser.POW, 0); }
public ExpressionContext expression() {
return getRuleContext(ExpressionContext.class,0);
}
public PowExpressionContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_powExpression; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterPowExpression(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitPowExpression(this);
}
}
public final PowExpressionContext powExpression() throws RecognitionException {
PowExpressionContext _localctx = new PowExpressionContext(_ctx, getState());
enterRule(_localctx, 6, RULE_powExpression);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(38);
atom();
setState(41);
_la = _input.LA(1);
if (_la==POW) {
{
setState(39);
match(POW);
setState(40);
expression();
}
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class AtomContext extends ParserRuleContext {
public ScientificContext scientific() {
return getRuleContext(ScientificContext.class,0);
}
public VariableContext variable() {
return getRuleContext(VariableContext.class,0);
}
public TerminalNode LPAREN() { return getToken(ArithmeticParser.LPAREN, 0); }
public ExpressionContext expression() {
return getRuleContext(ExpressionContext.class,0);
}
public TerminalNode RPAREN() { return getToken(ArithmeticParser.RPAREN, 0); }
public AtomContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_atom; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterAtom(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitAtom(this);
}
}
public final AtomContext atom() throws RecognitionException {
AtomContext _localctx = new AtomContext(_ctx, getState());
enterRule(_localctx, 8, RULE_atom);
try {
setState(49);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(43);
scientific();
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(44);
variable();
}
break;
case 3:
enterOuterAlt(_localctx, 3);
{
setState(45);
match(LPAREN);
setState(46);
expression();
setState(47);
match(RPAREN);
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ScientificContext extends ParserRuleContext {
public List<NumberContext> number() {
return getRuleContexts(NumberContext.class);
}
public NumberContext number(int i) {
return getRuleContext(NumberContext.class,i);
}
public TerminalNode E() { return getToken(ArithmeticParser.E, 0); }
public ScientificContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_scientific; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterScientific(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitScientific(this);
}
}
public final ScientificContext scientific() throws RecognitionException {
ScientificContext _localctx = new ScientificContext(_ctx, getState());
enterRule(_localctx, 10, RULE_scientific);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(51);
number();
setState(54);
_la = _input.LA(1);
if (_la==E) {
{
setState(52);
match(E);
setState(53);
number();
}
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class RelopContext extends ParserRuleContext {
public TerminalNode EQ() { return getToken(ArithmeticParser.EQ, 0); }
public TerminalNode GT() { return getToken(ArithmeticParser.GT, 0); }
public TerminalNode LT() { return getToken(ArithmeticParser.LT, 0); }
public RelopContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_relop; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterRelop(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitRelop(this);
}
}
public final RelopContext relop() throws RecognitionException {
RelopContext _localctx = new RelopContext(_ctx, getState());
enterRule(_localctx, 12, RULE_relop);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(56);
_la = _input.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << GT) | (1L << LT) | (1L << EQ))) != 0)) ) {
_errHandler.recoverInline(this);
} else {
consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class NumberContext extends ParserRuleContext {
public TerminalNode MINUS() { return getToken(ArithmeticParser.MINUS, 0); }
public List<TerminalNode> DIGIT() { return getTokens(ArithmeticParser.DIGIT); }
public TerminalNode DIGIT(int i) {
return getToken(ArithmeticParser.DIGIT, i);
}
public TerminalNode POINT() { return getToken(ArithmeticParser.POINT, 0); }
public NumberContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_number; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterNumber(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitNumber(this);
}
}
public final NumberContext number() throws RecognitionException {
NumberContext _localctx = new NumberContext(_ctx, getState());
enterRule(_localctx, 14, RULE_number);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(59);
_la = _input.LA(1);
if (_la==MINUS) {
{
setState(58);
match(MINUS);
}
}
setState(62);
_errHandler.sync(this);
_la = _input.LA(1);
do {
{
{
setState(61);
match(DIGIT);
}
}
setState(64);
_errHandler.sync(this);
_la = _input.LA(1);
} while ( _la==DIGIT );
setState(72);
_la = _input.LA(1);
if (_la==POINT) {
{
setState(66);
match(POINT);
setState(68);
_errHandler.sync(this);
_la = _input.LA(1);
do {
{
{
setState(67);
match(DIGIT);
}
}
setState(70);
_errHandler.sync(this);
_la = _input.LA(1);
} while ( _la==DIGIT );
}
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class VariableContext extends ParserRuleContext {
public List<TerminalNode> LETTER() { return getTokens(ArithmeticParser.LETTER); }
public TerminalNode LETTER(int i) {
return getToken(ArithmeticParser.LETTER, i);
}
public TerminalNode MINUS() { return getToken(ArithmeticParser.MINUS, 0); }
public List<TerminalNode> DIGIT() { return getTokens(ArithmeticParser.DIGIT); }
public TerminalNode DIGIT(int i) {
return getToken(ArithmeticParser.DIGIT, i);
}
public VariableContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_variable; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).enterVariable(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ArithmeticListener ) ((ArithmeticListener)listener).exitVariable(this);
}
}
public final VariableContext variable() throws RecognitionException {
VariableContext _localctx = new VariableContext(_ctx, getState());
enterRule(_localctx, 16, RULE_variable);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(75);
_la = _input.LA(1);
if (_la==MINUS) {
{
setState(74);
match(MINUS);
}
}
setState(77);
match(LETTER);
setState(81);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==LETTER || _la==DIGIT) {
{
{
setState(78);
_la = _input.LA(1);
if ( !(_la==LETTER || _la==DIGIT) ) {
_errHandler.recoverInline(this);
} else {
consume();
}
}
}
setState(83);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\21W\4\2\t\2\4\3\t"+
"\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\3\2\3\2\3\2"+
"\3\2\3\3\3\3\3\3\7\3\34\n\3\f\3\16\3\37\13\3\3\4\3\4\3\4\7\4$\n\4\f\4"+
"\16\4\'\13\4\3\5\3\5\3\5\5\5,\n\5\3\6\3\6\3\6\3\6\3\6\3\6\5\6\64\n\6\3"+
"\7\3\7\3\7\5\79\n\7\3\b\3\b\3\t\5\t>\n\t\3\t\6\tA\n\t\r\t\16\tB\3\t\3"+
"\t\6\tG\n\t\r\t\16\tH\5\tK\n\t\3\n\5\nN\n\n\3\n\3\n\7\nR\n\n\f\n\16\n"+
"U\13\n\3\n\2\2\13\2\4\6\b\n\f\16\20\22\2\6\3\2\5\6\3\2\7\b\3\2\t\13\3"+
"\2\17\20Y\2\24\3\2\2\2\4\30\3\2\2\2\6 \3\2\2\2\b(\3\2\2\2\n\63\3\2\2\2"+
"\f\65\3\2\2\2\16:\3\2\2\2\20=\3\2\2\2\22M\3\2\2\2\24\25\5\4\3\2\25\26"+
"\5\16\b\2\26\27\5\4\3\2\27\3\3\2\2\2\30\35\5\6\4\2\31\32\t\2\2\2\32\34"+
"\5\6\4\2\33\31\3\2\2\2\34\37\3\2\2\2\35\33\3\2\2\2\35\36\3\2\2\2\36\5"+
"\3\2\2\2\37\35\3\2\2\2 %\5\b\5\2!\"\t\3\2\2\"$\5\b\5\2#!\3\2\2\2$\'\3"+
"\2\2\2%#\3\2\2\2%&\3\2\2\2&\7\3\2\2\2\'%\3\2\2\2(+\5\n\6\2)*\7\16\2\2"+
"*,\5\4\3\2+)\3\2\2\2+,\3\2\2\2,\t\3\2\2\2-\64\5\f\7\2.\64\5\22\n\2/\60"+
"\7\3\2\2\60\61\5\4\3\2\61\62\7\4\2\2\62\64\3\2\2\2\63-\3\2\2\2\63.\3\2"+
"\2\2\63/\3\2\2\2\64\13\3\2\2\2\658\5\20\t\2\66\67\7\r\2\2\679\5\20\t\2"+
"8\66\3\2\2\289\3\2\2\29\r\3\2\2\2:;\t\4\2\2;\17\3\2\2\2<>\7\6\2\2=<\3"+
"\2\2\2=>\3\2\2\2>@\3\2\2\2?A\7\20\2\2@?\3\2\2\2AB\3\2\2\2B@\3\2\2\2BC"+
"\3\2\2\2CJ\3\2\2\2DF\7\f\2\2EG\7\20\2\2FE\3\2\2\2GH\3\2\2\2HF\3\2\2\2"+
"HI\3\2\2\2IK\3\2\2\2JD\3\2\2\2JK\3\2\2\2K\21\3\2\2\2LN\7\6\2\2ML\3\2\2"+
"\2MN\3\2\2\2NO\3\2\2\2OS\7\17\2\2PR\t\5\2\2QP\3\2\2\2RU\3\2\2\2SQ\3\2"+
"\2\2ST\3\2\2\2T\23\3\2\2\2US\3\2\2\2\r\35%+\638=BHJMS";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -1,146 +0,0 @@
// Generated from Expr.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link ExprListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class ExprBaseListener implements ExprListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterProg(ExprParser.ProgContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitProg(ExprParser.ProgContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterPrintExpr(ExprParser.PrintExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitPrintExpr(ExprParser.PrintExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAssign(ExprParser.AssignContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAssign(ExprParser.AssignContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterBlank(ExprParser.BlankContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitBlank(ExprParser.BlankContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterId(ExprParser.IdContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitId(ExprParser.IdContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterInt(ExprParser.IntContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitInt(ExprParser.IntContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAddSub(ExprParser.AddSubContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAddSub(ExprParser.AddSubContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterParens(ExprParser.ParensContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitParens(ExprParser.ParensContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterMulDiv(ExprParser.MulDivContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitMulDiv(ExprParser.MulDivContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

View File

@ -1,117 +0,0 @@
// Generated from Expr.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class ExprLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, MUL=4, DIV=5, ADD=6, SUB=7, ID=8, INT=9, NEWLINE=10,
WS=11;
public static String[] modeNames = {
"DEFAULT_MODE"
};
public static final String[] ruleNames = {
"T__0", "T__1", "T__2", "MUL", "DIV", "ADD", "SUB", "ID", "INT", "NEWLINE",
"WS"
};
private static final String[] _LITERAL_NAMES = {
null, "'='", "'('", "')'", "'*'", "'/'", "'+'", "'-'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, "MUL", "DIV", "ADD", "SUB", "ID", "INT", "NEWLINE",
"WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public ExprLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "Expr.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2\r=\b\1\4\2\t\2\4"+
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
"\13\4\f\t\f\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3"+
"\t\6\t)\n\t\r\t\16\t*\3\n\6\n.\n\n\r\n\16\n/\3\13\5\13\63\n\13\3\13\3"+
"\13\3\f\6\f8\n\f\r\f\16\f9\3\f\3\f\2\2\r\3\3\5\4\7\5\t\6\13\7\r\b\17\t"+
"\21\n\23\13\25\f\27\r\3\2\5\4\2C\\c|\3\2\62;\4\2\13\13\"\"@\2\3\3\2\2"+
"\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3"+
"\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\3\31\3\2\2"+
"\2\5\33\3\2\2\2\7\35\3\2\2\2\t\37\3\2\2\2\13!\3\2\2\2\r#\3\2\2\2\17%\3"+
"\2\2\2\21(\3\2\2\2\23-\3\2\2\2\25\62\3\2\2\2\27\67\3\2\2\2\31\32\7?\2"+
"\2\32\4\3\2\2\2\33\34\7*\2\2\34\6\3\2\2\2\35\36\7+\2\2\36\b\3\2\2\2\37"+
" \7,\2\2 \n\3\2\2\2!\"\7\61\2\2\"\f\3\2\2\2#$\7-\2\2$\16\3\2\2\2%&\7/"+
"\2\2&\20\3\2\2\2\')\t\2\2\2(\'\3\2\2\2)*\3\2\2\2*(\3\2\2\2*+\3\2\2\2+"+
"\22\3\2\2\2,.\t\3\2\2-,\3\2\2\2./\3\2\2\2/-\3\2\2\2/\60\3\2\2\2\60\24"+
"\3\2\2\2\61\63\7\17\2\2\62\61\3\2\2\2\62\63\3\2\2\2\63\64\3\2\2\2\64\65"+
"\7\f\2\2\65\26\3\2\2\2\668\t\4\2\2\67\66\3\2\2\289\3\2\2\29\67\3\2\2\2"+
"9:\3\2\2\2:;\3\2\2\2;<\b\f\2\2<\30\3\2\2\2\7\2*/\629\3\b\2\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -1,115 +0,0 @@
// Generated from Expr.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link ExprParser}.
*/
public interface ExprListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link ExprParser#prog}.
* @param ctx the parse tree
*/
void enterProg(ExprParser.ProgContext ctx);
/**
* Exit a parse tree produced by {@link ExprParser#prog}.
* @param ctx the parse tree
*/
void exitProg(ExprParser.ProgContext ctx);
/**
* Enter a parse tree produced by the {@code printExpr}
* labeled alternative in {@link ExprParser#stat}.
* @param ctx the parse tree
*/
void enterPrintExpr(ExprParser.PrintExprContext ctx);
/**
* Exit a parse tree produced by the {@code printExpr}
* labeled alternative in {@link ExprParser#stat}.
* @param ctx the parse tree
*/
void exitPrintExpr(ExprParser.PrintExprContext ctx);
/**
* Enter a parse tree produced by the {@code assign}
* labeled alternative in {@link ExprParser#stat}.
* @param ctx the parse tree
*/
void enterAssign(ExprParser.AssignContext ctx);
/**
* Exit a parse tree produced by the {@code assign}
* labeled alternative in {@link ExprParser#stat}.
* @param ctx the parse tree
*/
void exitAssign(ExprParser.AssignContext ctx);
/**
* Enter a parse tree produced by the {@code blank}
* labeled alternative in {@link ExprParser#stat}.
* @param ctx the parse tree
*/
void enterBlank(ExprParser.BlankContext ctx);
/**
* Exit a parse tree produced by the {@code blank}
* labeled alternative in {@link ExprParser#stat}.
* @param ctx the parse tree
*/
void exitBlank(ExprParser.BlankContext ctx);
/**
* Enter a parse tree produced by the {@code id}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void enterId(ExprParser.IdContext ctx);
/**
* Exit a parse tree produced by the {@code id}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void exitId(ExprParser.IdContext ctx);
/**
* Enter a parse tree produced by the {@code int}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void enterInt(ExprParser.IntContext ctx);
/**
* Exit a parse tree produced by the {@code int}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void exitInt(ExprParser.IntContext ctx);
/**
* Enter a parse tree produced by the {@code AddSub}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void enterAddSub(ExprParser.AddSubContext ctx);
/**
* Exit a parse tree produced by the {@code AddSub}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void exitAddSub(ExprParser.AddSubContext ctx);
/**
* Enter a parse tree produced by the {@code parens}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void enterParens(ExprParser.ParensContext ctx);
/**
* Exit a parse tree produced by the {@code parens}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void exitParens(ExprParser.ParensContext ctx);
/**
* Enter a parse tree produced by the {@code MulDiv}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void enterMulDiv(ExprParser.MulDivContext ctx);
/**
* Exit a parse tree produced by the {@code MulDiv}
* labeled alternative in {@link ExprParser#expr}.
* @param ctx the parse tree
*/
void exitMulDiv(ExprParser.MulDivContext ctx);
}

View File

@ -1,470 +0,0 @@
// Generated from Expr.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class ExprParser extends Parser {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, MUL=4, DIV=5, ADD=6, SUB=7, ID=8, INT=9, NEWLINE=10,
WS=11;
public static final int
RULE_prog = 0, RULE_stat = 1, RULE_expr = 2;
public static final String[] ruleNames = {
"prog", "stat", "expr"
};
private static final String[] _LITERAL_NAMES = {
null, "'='", "'('", "')'", "'*'", "'/'", "'+'", "'-'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, "MUL", "DIV", "ADD", "SUB", "ID", "INT", "NEWLINE",
"WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "Expr.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public ExprParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class ProgContext extends ParserRuleContext {
public StatContext stat() {
return getRuleContext(StatContext.class,0);
}
public ProgContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_prog; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterProg(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitProg(this);
}
}
public final ProgContext prog() throws RecognitionException {
ProgContext _localctx = new ProgContext(_ctx, getState());
enterRule(_localctx, 0, RULE_prog);
try {
enterOuterAlt(_localctx, 1);
{
setState(6);
stat();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class StatContext extends ParserRuleContext {
public StatContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_stat; }
public StatContext() { }
public void copyFrom(StatContext ctx) {
super.copyFrom(ctx);
}
}
public static class AssignContext extends StatContext {
public TerminalNode ID() { return getToken(ExprParser.ID, 0); }
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public TerminalNode NEWLINE() { return getToken(ExprParser.NEWLINE, 0); }
public AssignContext(StatContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterAssign(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitAssign(this);
}
}
public static class BlankContext extends StatContext {
public TerminalNode NEWLINE() { return getToken(ExprParser.NEWLINE, 0); }
public BlankContext(StatContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterBlank(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitBlank(this);
}
}
public static class PrintExprContext extends StatContext {
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public TerminalNode NEWLINE() { return getToken(ExprParser.NEWLINE, 0); }
public PrintExprContext(StatContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterPrintExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitPrintExpr(this);
}
}
public final StatContext stat() throws RecognitionException {
StatContext _localctx = new StatContext(_ctx, getState());
enterRule(_localctx, 2, RULE_stat);
try {
setState(17);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) {
case 1:
_localctx = new PrintExprContext(_localctx);
enterOuterAlt(_localctx, 1);
{
setState(8);
expr(0);
setState(9);
match(NEWLINE);
}
break;
case 2:
_localctx = new AssignContext(_localctx);
enterOuterAlt(_localctx, 2);
{
setState(11);
match(ID);
setState(12);
match(T__0);
setState(13);
expr(0);
setState(14);
match(NEWLINE);
}
break;
case 3:
_localctx = new BlankContext(_localctx);
enterOuterAlt(_localctx, 3);
{
setState(16);
match(NEWLINE);
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ExprContext extends ParserRuleContext {
public ExprContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr; }
public ExprContext() { }
public void copyFrom(ExprContext ctx) {
super.copyFrom(ctx);
}
}
public static class IdContext extends ExprContext {
public TerminalNode ID() { return getToken(ExprParser.ID, 0); }
public IdContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterId(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitId(this);
}
}
public static class IntContext extends ExprContext {
public TerminalNode INT() { return getToken(ExprParser.INT, 0); }
public IntContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterInt(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitInt(this);
}
}
public static class AddSubContext extends ExprContext {
public List<ExprContext> expr() {
return getRuleContexts(ExprContext.class);
}
public ExprContext expr(int i) {
return getRuleContext(ExprContext.class,i);
}
public AddSubContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterAddSub(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitAddSub(this);
}
}
public static class ParensContext extends ExprContext {
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public ParensContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterParens(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitParens(this);
}
}
public static class MulDivContext extends ExprContext {
public List<ExprContext> expr() {
return getRuleContexts(ExprContext.class);
}
public ExprContext expr(int i) {
return getRuleContext(ExprContext.class,i);
}
public MulDivContext(ExprContext ctx) { copyFrom(ctx); }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).enterMulDiv(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof ExprListener ) ((ExprListener)listener).exitMulDiv(this);
}
}
public final ExprContext expr() throws RecognitionException {
return expr(0);
}
private ExprContext expr(int _p) throws RecognitionException {
ParserRuleContext _parentctx = _ctx;
int _parentState = getState();
ExprContext _localctx = new ExprContext(_ctx, _parentState);
ExprContext _prevctx = _localctx;
int _startState = 4;
enterRecursionRule(_localctx, 4, RULE_expr, _p);
int _la;
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
setState(26);
switch (_input.LA(1)) {
case INT:
{
_localctx = new IntContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(20);
match(INT);
}
break;
case ID:
{
_localctx = new IdContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(21);
match(ID);
}
break;
case T__1:
{
_localctx = new ParensContext(_localctx);
_ctx = _localctx;
_prevctx = _localctx;
setState(22);
match(T__1);
setState(23);
expr(0);
setState(24);
match(T__2);
}
break;
default:
throw new NoViableAltException(this);
}
_ctx.stop = _input.LT(-1);
setState(36);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,3,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( _parseListeners!=null ) triggerExitRuleEvent();
_prevctx = _localctx;
{
setState(34);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) {
case 1:
{
_localctx = new MulDivContext(new ExprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(28);
if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)");
setState(29);
_la = _input.LA(1);
if ( !(_la==MUL || _la==DIV) ) {
_errHandler.recoverInline(this);
} else {
consume();
}
setState(30);
expr(6);
}
break;
case 2:
{
_localctx = new AddSubContext(new ExprContext(_parentctx, _parentState));
pushNewRecursionContext(_localctx, _startState, RULE_expr);
setState(31);
if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)");
setState(32);
_la = _input.LA(1);
if ( !(_la==ADD || _la==SUB) ) {
_errHandler.recoverInline(this);
} else {
consume();
}
setState(33);
expr(5);
}
break;
}
}
}
setState(38);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,3,_ctx);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
unrollRecursionContexts(_parentctx);
}
return _localctx;
}
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
case 2:
return expr_sempred((ExprContext)_localctx, predIndex);
}
return true;
}
private boolean expr_sempred(ExprContext _localctx, int predIndex) {
switch (predIndex) {
case 0:
return precpred(_ctx, 5);
case 1:
return precpred(_ctx, 4);
}
return true;
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\r*\4\2\t\2\4\3\t"+
"\3\4\4\t\4\3\2\3\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\5\3\24\n\3\3\4"+
"\3\4\3\4\3\4\3\4\3\4\3\4\5\4\35\n\4\3\4\3\4\3\4\3\4\3\4\3\4\7\4%\n\4\f"+
"\4\16\4(\13\4\3\4\2\3\6\5\2\4\6\2\4\3\2\6\7\3\2\b\t,\2\b\3\2\2\2\4\23"+
"\3\2\2\2\6\34\3\2\2\2\b\t\5\4\3\2\t\3\3\2\2\2\n\13\5\6\4\2\13\f\7\f\2"+
"\2\f\24\3\2\2\2\r\16\7\n\2\2\16\17\7\3\2\2\17\20\5\6\4\2\20\21\7\f\2\2"+
"\21\24\3\2\2\2\22\24\7\f\2\2\23\n\3\2\2\2\23\r\3\2\2\2\23\22\3\2\2\2\24"+
"\5\3\2\2\2\25\26\b\4\1\2\26\35\7\13\2\2\27\35\7\n\2\2\30\31\7\4\2\2\31"+
"\32\5\6\4\2\32\33\7\5\2\2\33\35\3\2\2\2\34\25\3\2\2\2\34\27\3\2\2\2\34"+
"\30\3\2\2\2\35&\3\2\2\2\36\37\f\7\2\2\37 \t\2\2\2 %\5\6\4\b!\"\f\6\2\2"+
"\"#\t\3\2\2#%\5\6\4\7$\36\3\2\2\2$!\3\2\2\2%(\3\2\2\2&$\3\2\2\2&\'\3\2"+
"\2\2\'\7\3\2\2\2(&\3\2\2\2\6\23\34$&";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -1,62 +0,0 @@
// Generated from M.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link MListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class MBaseListener implements MListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterS(MParser.SContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitS(MParser.SContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterA(MParser.AContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitA(MParser.AContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

View File

@ -1,101 +0,0 @@
// Generated from M.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class MLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
B=1, WS=2;
public static String[] modeNames = {
"DEFAULT_MODE"
};
public static final String[] ruleNames = {
"B", "WS"
};
private static final String[] _LITERAL_NAMES = {
null, "'b'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, "B", "WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public MLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "M.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2\4\r\b\1\4\2\t\2\4"+
"\3\t\3\3\2\3\2\3\3\3\3\3\3\3\3\2\2\4\3\3\5\4\3\2\3\4\2\f\f\"\"\f\2\3\3"+
"\2\2\2\2\5\3\2\2\2\3\7\3\2\2\2\5\t\3\2\2\2\7\b\7d\2\2\b\4\3\2\2\2\t\n"+
"\t\2\2\2\n\13\3\2\2\2\13\f\b\3\2\2\f\6\3\2\2\2\3\2\3\b\2\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -1,29 +0,0 @@
// Generated from M.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link MParser}.
*/
public interface MListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link MParser#s}.
* @param ctx the parse tree
*/
void enterS(MParser.SContext ctx);
/**
* Exit a parse tree produced by {@link MParser#s}.
* @param ctx the parse tree
*/
void exitS(MParser.SContext ctx);
/**
* Enter a parse tree produced by {@link MParser#a}.
* @param ctx the parse tree
*/
void enterA(MParser.AContext ctx);
/**
* Exit a parse tree produced by {@link MParser#a}.
* @param ctx the parse tree
*/
void exitA(MParser.AContext ctx);
}

View File

@ -1,170 +0,0 @@
// Generated from M.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class MParser extends Parser {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
B=1, WS=2;
public static final int
RULE_s = 0, RULE_a = 1;
public static final String[] ruleNames = {
"s", "a"
};
private static final String[] _LITERAL_NAMES = {
null, "'b'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, "B", "WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "M.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public MParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class SContext extends ParserRuleContext {
public AContext a() {
return getRuleContext(AContext.class,0);
}
public SContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_s; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof MListener ) ((MListener)listener).enterS(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof MListener ) ((MListener)listener).exitS(this);
}
}
public final SContext s() throws RecognitionException {
SContext _localctx = new SContext(_ctx, getState());
enterRule(_localctx, 0, RULE_s);
try {
enterOuterAlt(_localctx, 1);
{
setState(4);
a();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class AContext extends ParserRuleContext {
public TerminalNode B() { return getToken(MParser.B, 0); }
public AContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_a; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof MListener ) ((MListener)listener).enterA(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof MListener ) ((MListener)listener).exitA(this);
}
}
public final AContext a() throws RecognitionException {
AContext _localctx = new AContext(_ctx, getState());
enterRule(_localctx, 2, RULE_a);
try {
enterOuterAlt(_localctx, 1);
{
setState(6);
match(B);
}
int x = 0;
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\4\13\4\2\t\2\4\3"+
"\t\3\3\2\3\2\3\3\3\3\3\3\2\2\4\2\4\2\2\b\2\6\3\2\2\2\4\b\3\2\2\2\6\7\5"+
"\4\3\2\7\3\3\2\2\2\b\t\7\3\2\2\t\5\3\2\2\2\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -1,86 +0,0 @@
// Generated from T.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link TListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class TBaseListener implements TListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterProg(TParser.ProgContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitProg(TParser.ProgContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExpr_or_assign(TParser.Expr_or_assignContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExpr_or_assign(TParser.Expr_or_assignContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExpr(TParser.ExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExpr(TParser.ExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExpr_primary(TParser.Expr_primaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExpr_primary(TParser.Expr_primaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

View File

@ -1,105 +0,0 @@
// Generated from T.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class TLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, ID=5;
public static String[] modeNames = {
"DEFAULT_MODE"
};
public static final String[] ruleNames = {
"T__0", "T__1", "T__2", "T__3", "ID"
};
private static final String[] _LITERAL_NAMES = {
null, "'++'", "'<-'", "'('", "')'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, "ID"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public TLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "T.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2\7\34\b\1\4\2\t\2"+
"\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\3\2\3\2\3\2\3\3\3\3\3\3\3\4\3\4\3\5\3"+
"\5\3\6\6\6\31\n\6\r\6\16\6\32\2\2\7\3\3\5\4\7\5\t\6\13\7\3\2\3\3\2c|\34"+
"\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\3\r\3\2"+
"\2\2\5\20\3\2\2\2\7\23\3\2\2\2\t\25\3\2\2\2\13\30\3\2\2\2\r\16\7-\2\2"+
"\16\17\7-\2\2\17\4\3\2\2\2\20\21\7>\2\2\21\22\7/\2\2\22\6\3\2\2\2\23\24"+
"\7*\2\2\24\b\3\2\2\2\25\26\7+\2\2\26\n\3\2\2\2\27\31\t\2\2\2\30\27\3\2"+
"\2\2\31\32\3\2\2\2\32\30\3\2\2\2\32\33\3\2\2\2\33\f\3\2\2\2\4\2\32\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -1,49 +0,0 @@
// Generated from T.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link TParser}.
*/
public interface TListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link TParser#prog}.
* @param ctx the parse tree
*/
void enterProg(TParser.ProgContext ctx);
/**
* Exit a parse tree produced by {@link TParser#prog}.
* @param ctx the parse tree
*/
void exitProg(TParser.ProgContext ctx);
/**
* Enter a parse tree produced by {@link TParser#expr_or_assign}.
* @param ctx the parse tree
*/
void enterExpr_or_assign(TParser.Expr_or_assignContext ctx);
/**
* Exit a parse tree produced by {@link TParser#expr_or_assign}.
* @param ctx the parse tree
*/
void exitExpr_or_assign(TParser.Expr_or_assignContext ctx);
/**
* Enter a parse tree produced by {@link TParser#expr}.
* @param ctx the parse tree
*/
void enterExpr(TParser.ExprContext ctx);
/**
* Exit a parse tree produced by {@link TParser#expr}.
* @param ctx the parse tree
*/
void exitExpr(TParser.ExprContext ctx);
/**
* Enter a parse tree produced by {@link TParser#expr_primary}.
* @param ctx the parse tree
*/
void enterExpr_primary(TParser.Expr_primaryContext ctx);
/**
* Exit a parse tree produced by {@link TParser#expr_primary}.
* @param ctx the parse tree
*/
void exitExpr_primary(TParser.Expr_primaryContext ctx);
}

View File

@ -1,336 +0,0 @@
// Generated from T.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class TParser extends Parser {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, ID=5;
public static final int
RULE_prog = 0, RULE_expr_or_assign = 1, RULE_expr = 2, RULE_expr_primary = 3;
public static final String[] ruleNames = {
"prog", "expr_or_assign", "expr", "expr_primary"
};
private static final String[] _LITERAL_NAMES = {
null, "'++'", "'<-'", "'('", "')'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, "ID"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "T.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public TParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class ProgContext extends ParserRuleContext {
public List<Expr_or_assignContext> expr_or_assign() {
return getRuleContexts(Expr_or_assignContext.class);
}
public Expr_or_assignContext expr_or_assign(int i) {
return getRuleContext(Expr_or_assignContext.class,i);
}
public ProgContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_prog; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).enterProg(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).exitProg(this);
}
}
public final ProgContext prog() throws RecognitionException {
ProgContext _localctx = new ProgContext(_ctx, getState());
enterRule(_localctx, 0, RULE_prog);
_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(11);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==T__2 || _la==ID) {
{
{
setState(8);
expr_or_assign();
}
}
setState(13);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class Expr_or_assignContext extends ParserRuleContext {
public ExprContext expr;
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public Expr_or_assignContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr_or_assign; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).enterExpr_or_assign(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).exitExpr_or_assign(this);
}
}
public final Expr_or_assignContext expr_or_assign() throws RecognitionException {
Expr_or_assignContext _localctx = new Expr_or_assignContext(_ctx, getState());
enterRule(_localctx, 2, RULE_expr_or_assign);
try {
setState(21);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(14);
expr();
setState(15);
match(T__0);
fmt.Println("fail.")
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(18);
((Expr_or_assignContext)_localctx).expr = expr();
fmt.Println("pass: "+(((Expr_or_assignContext)_localctx).expr!=null?_input.getText(((Expr_or_assignContext)_localctx).expr.start,((Expr_or_assignContext)_localctx).expr.stop):null))
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ExprContext extends ParserRuleContext {
public Expr_primaryContext expr_primary() {
return getRuleContext(Expr_primaryContext.class,0);
}
public TerminalNode ID() { return getToken(TParser.ID, 0); }
public ExprContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).enterExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).exitExpr(this);
}
}
public final ExprContext expr() throws RecognitionException {
ExprContext _localctx = new ExprContext(_ctx, getState());
enterRule(_localctx, 4, RULE_expr);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(23);
expr_primary();
setState(26);
_la = _input.LA(1);
if (_la==T__1) {
{
setState(24);
match(T__1);
setState(25);
match(ID);
}
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class Expr_primaryContext extends ParserRuleContext {
public List<TerminalNode> ID() { return getTokens(TParser.ID); }
public TerminalNode ID(int i) {
return getToken(TParser.ID, i);
}
public Expr_primaryContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr_primary; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).enterExpr_primary(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).exitExpr_primary(this);
}
}
public final Expr_primaryContext expr_primary() throws RecognitionException {
Expr_primaryContext _localctx = new Expr_primaryContext(_ctx, getState());
enterRule(_localctx, 6, RULE_expr_primary);
try {
setState(36);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(28);
match(T__2);
setState(29);
match(ID);
setState(30);
match(T__3);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(31);
match(ID);
setState(32);
match(T__2);
setState(33);
match(ID);
setState(34);
match(T__3);
}
break;
case 3:
enterOuterAlt(_localctx, 3);
{
setState(35);
match(ID);
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\7)\4\2\t\2\4\3\t"+
"\3\4\4\t\4\4\5\t\5\3\2\7\2\f\n\2\f\2\16\2\17\13\2\3\3\3\3\3\3\3\3\3\3"+
"\3\3\3\3\5\3\30\n\3\3\4\3\4\3\4\5\4\35\n\4\3\5\3\5\3\5\3\5\3\5\3\5\3\5"+
"\3\5\5\5\'\n\5\3\5\2\2\6\2\4\6\b\2\2)\2\r\3\2\2\2\4\27\3\2\2\2\6\31\3"+
"\2\2\2\b&\3\2\2\2\n\f\5\4\3\2\13\n\3\2\2\2\f\17\3\2\2\2\r\13\3\2\2\2\r"+
"\16\3\2\2\2\16\3\3\2\2\2\17\r\3\2\2\2\20\21\5\6\4\2\21\22\7\3\2\2\22\23"+
"\b\3\1\2\23\30\3\2\2\2\24\25\5\6\4\2\25\26\b\3\1\2\26\30\3\2\2\2\27\20"+
"\3\2\2\2\27\24\3\2\2\2\30\5\3\2\2\2\31\34\5\b\5\2\32\33\7\4\2\2\33\35"+
"\7\7\2\2\34\32\3\2\2\2\34\35\3\2\2\2\35\7\3\2\2\2\36\37\7\5\2\2\37 \7"+
"\7\2\2 \'\7\6\2\2!\"\7\7\2\2\"#\7\5\2\2#$\7\7\2\2$\'\7\6\2\2%\'\7\7\2"+
"\2&\36\3\2\2\2&!\3\2\2\2&%\3\2\2\2\'\t\3\2\2\2\6\r\27\34&";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -1,4 +0,0 @@
{
"ok" : 12,
"this" : false
}

Binary file not shown.

View File

@ -1,41 +0,0 @@
package main
import (
"antlr4"
"parser"
"fmt"
)
type MyListener struct {
*parser.BaseJSONListener
}
func NewMyPrinter() *MyListener {
return new(MyListener)
}
func (s *MyListener) EnterValue(ctx *parser.ValueContext) {
fmt.Println(ctx.GetStart().GetText())
}
func main() {
a := antlr4.NewFileStream("foo.txt")
l := parser.NewJSONLexer(a)
s := antlr4.NewCommonTokenStream(l, 0)
p := parser.NewJSONParser(s)
p.BuildParseTrees = true
tree := p.Json()
var printer = NewMyPrinter()
antlr4.ParseTreeWalkerDefault.Walk(printer, tree);
// fmt.Println( tree.GetChildren()[0].GetChildren()[0].GetChildren()[0].GetChildren()[0].GetChildren()[0].GetChildren()[0].GetChildren()[0] );
}