Add ANTLR grammar for greetings and farewells with corresponding parser and listener implementations

This commit is contained in:
bobbert committed 2026-03-26 15:32:19 +00:00
1 parent 2027302cf1
commit 6205020013
30 files changed
+1109 -37

No files matched your search

View File
Whitespace-only changes.
+5
View File
@@ -0,0 +1,5 @@
grammar week3;
start : 'minimal' ID ;
ID : [a-zA-Z]+ ;
WS : [ \t\r\n]+ -> skip ;
+18
View File
@@ -0,0 +1,18 @@
token literal names:
null
'minimal'
null
null
token symbolic names:
null
null
ID
WS
rule names:
start
atn:
[4, 1, 3, 6, 2, 0, 7, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 0, 2, 1, 0, 0, 0, 2, 3, 5, 1, 0, 0, 3, 4, 5, 2, 0, 0, 4, 1, 1, 0, 0, 0, 0]
+4
View File
@@ -0,0 +1,4 @@
T__0=1
ID=2
WS=3
'minimal'=1
+26
View File
@@ -0,0 +1,26 @@
token literal names:
null
'minimal'
null
null
token symbolic names:
null
null
ID
WS
rule names:
T__0
ID
WS
channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN
mode names:
DEFAULT_MODE
atn:
[4, 0, 3, 27, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 4, 1, 17, 8, 1, 11, 1, 12, 1, 18, 1, 2, 4, 2, 22, 8, 2, 11, 2, 12, 2, 23, 1, 2, 1, 2, 0, 0, 3, 1, 1, 3, 2, 5, 3, 1, 0, 2, 2, 0, 65, 90, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 28, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 1, 7, 1, 0, 0, 0, 3, 16, 1, 0, 0, 0, 5, 21, 1, 0, 0, 0, 7, 8, 5, 109, 0, 0, 8, 9, 5, 105, 0, 0, 9, 10, 5, 110, 0, 0, 10, 11, 5, 105, 0, 0, 11, 12, 5, 109, 0, 0, 12, 13, 5, 97, 0, 0, 13, 14, 5, 108, 0, 0, 14, 2, 1, 0, 0, 0, 15, 17, 7, 0, 0, 0, 16, 15, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 16, 1, 0, 0, 0, 18, 19, 1, 0, 0, 0, 19, 4, 1, 0, 0, 0, 20, 22, 7, 1, 0, 0, 21, 20, 1, 0, 0, 0, 22, 23, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 23, 24, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 26, 6, 2, 0, 0, 26, 6, 1, 0, 0, 0, 3, 0, 18, 23, 1, 6, 0, 0]
+56
View File
@@ -0,0 +1,56 @@
# Generated from ./week3.g4 by ANTLR 4.13.2
from antlr4 import *
from io import StringIO
import sys
if sys.version_info[1] > 5:
from typing import TextIO
else:
from typing.io import TextIO
def serializedATN():
return [
4,0,3,27,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,1,4,1,17,8,1,11,1,12,1,18,1,2,4,2,22,8,2,11,2,12,2,23,1,
2,1,2,0,0,3,1,1,3,2,5,3,1,0,2,2,0,65,90,97,122,3,0,9,10,13,13,32,
32,28,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,1,7,1,0,0,0,3,16,1,0,0,
0,5,21,1,0,0,0,7,8,5,109,0,0,8,9,5,105,0,0,9,10,5,110,0,0,10,11,
5,105,0,0,11,12,5,109,0,0,12,13,5,97,0,0,13,14,5,108,0,0,14,2,1,
0,0,0,15,17,7,0,0,0,16,15,1,0,0,0,17,18,1,0,0,0,18,16,1,0,0,0,18,
19,1,0,0,0,19,4,1,0,0,0,20,22,7,1,0,0,21,20,1,0,0,0,22,23,1,0,0,
0,23,21,1,0,0,0,23,24,1,0,0,0,24,25,1,0,0,0,25,26,6,2,0,0,26,6,1,
0,0,0,3,0,18,23,1,6,0,0
]
class week3Lexer(Lexer):
atn = ATNDeserializer().deserialize(serializedATN())
decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
T__0 = 1
ID = 2
WS = 3
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
modeNames = [ "DEFAULT_MODE" ]
literalNames = [ "<INVALID>",
"'minimal'" ]
symbolicNames = [ "<INVALID>",
"ID", "WS" ]
ruleNames = [ "T__0", "ID", "WS" ]
grammarFileName = "week3.g4"
def __init__(self, input=None, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.13.2")
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
self._actions = None
self._predicates = None
+4
View File
@@ -0,0 +1,4 @@
T__0=1
ID=2
WS=3
'minimal'=1
+21
View File
@@ -0,0 +1,21 @@
# Generated from ./week3.g4 by ANTLR 4.13.2
from antlr4 import *
if "." in __name__:
from .week3Parser import week3Parser
else:
from week3Parser import week3Parser
# This class defines a complete listener for a parse tree produced by week3Parser.
class week3Listener(ParseTreeListener):
# Enter a parse tree produced by week3Parser#start.
def enterStart(self, ctx:week3Parser.StartContext):
pass
# Exit a parse tree produced by week3Parser#start.
def exitStart(self, ctx:week3Parser.StartContext):
pass
del week3Parser
+94
View File
@@ -0,0 +1,94 @@
# Generated from ./week3.g4 by ANTLR 4.13.2
# encoding: utf-8
from antlr4 import *
from io import StringIO
import sys
if sys.version_info[1] > 5:
from typing import TextIO
else:
from typing.io import TextIO
def serializedATN():
return [
4,1,3,6,2,0,7,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,4,0,2,1,0,0,0,2,3,5,
1,0,0,3,4,5,2,0,0,4,1,1,0,0,0,0
]
class week3Parser ( Parser ):
grammarFileName = "week3.g4"
atn = ATNDeserializer().deserialize(serializedATN())
decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
sharedContextCache = PredictionContextCache()
literalNames = [ "<INVALID>", "'minimal'" ]
symbolicNames = [ "<INVALID>", "<INVALID>", "ID", "WS" ]
RULE_start = 0
ruleNames = [ "start" ]
EOF = Token.EOF
T__0=1
ID=2
WS=3
def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.13.2")
self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
self._predicates = None
class StartContext(ParserRuleContext):
__slots__ = 'parser'
def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1):
super().__init__(parent, invokingState)
self.parser = parser
def ID(self):
return self.getToken(week3Parser.ID, 0)
def getRuleIndex(self):
return week3Parser.RULE_start
def enterRule(self, listener:ParseTreeListener):
if hasattr( listener, "enterStart" ):
listener.enterStart(self)
def exitRule(self, listener:ParseTreeListener):
if hasattr( listener, "exitStart" ):
listener.exitStart(self)
def start(self):
localctx = week3Parser.StartContext(self, self._ctx, self.state)
self.enterRule(localctx, 0, self.RULE_start)
try:
self.enterOuterAlt(localctx, 1)
self.state = 2
self.match(week3Parser.T__0)
self.state = 3
self.match(week3Parser.ID)
except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.exitRule()
return localctx