diff --git a/runtime/Swift/Tests/Antlr4Tests/SwiftTest.tokens b/runtime/Swift/Tests/Antlr4Tests/SwiftTest.tokens
deleted file mode 100644
index e91685d6e..000000000
--- a/runtime/Swift/Tests/Antlr4Tests/SwiftTest.tokens
+++ /dev/null
@@ -1,2 +0,0 @@
-T__0=1
-'A'=1
diff --git a/runtime/Swift/Tests/Antlr4Tests/SwiftTestBaseListener.swift b/runtime/Swift/Tests/Antlr4Tests/SwiftTestBaseListener.swift
deleted file mode 100644
index 35d518c6a..000000000
--- a/runtime/Swift/Tests/Antlr4Tests/SwiftTestBaseListener.swift
+++ /dev/null
@@ -1,50 +0,0 @@
-// Generated from SwiftTest.g4 by ANTLR 4.6
-
-import Antlr4
-
-
-/**
- * This class provides an empty implementation of {@link SwiftTestListener},
- * which can be extended to create a listener which only needs to handle a subset
- * of the available methods.
- */
-open class SwiftTestBaseListener: SwiftTestListener {
- public init() { }
- /**
- * {@inheritDoc}
- *
- *
The default implementation does nothing.
- */
- open func enterS(_ ctx: SwiftTestParser.SContext) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- open func exitS(_ ctx: SwiftTestParser.SContext) { }
-
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- open func enterEveryRule(_ ctx: ParserRuleContext) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- open func exitEveryRule(_ ctx: ParserRuleContext) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- open func visitTerminal(_ node: TerminalNode) { }
- /**
- * {@inheritDoc}
- *
- * The default implementation does nothing.
- */
- open func visitErrorNode(_ node: ErrorNode) { }
-}
\ No newline at end of file
diff --git a/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexer.swift b/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexer.swift
deleted file mode 100644
index d722fc187..000000000
--- a/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexer.swift
+++ /dev/null
@@ -1,90 +0,0 @@
-// Generated from SwiftTest.g4 by ANTLR 4.6
-import Antlr4
-
-open class SwiftTestLexer: Lexer {
- internal static var _decisionToDFA: [DFA] = {
- var decisionToDFA = [DFA]()
- let length = SwiftTestLexer._ATN.getNumberOfDecisions()
- for i in 0.. [String?]? {
- return tokenNames
- }
-
- open override func getVocabulary() -> Vocabulary {
- return SwiftTestLexer.VOCABULARY
- }
-
- public override init(_ input: CharStream) {
- RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION)
- super.init(input)
- _interp = LexerATNSimulator(self, SwiftTestLexer._ATN, SwiftTestLexer._decisionToDFA, SwiftTestLexer._sharedContextCache)
- }
-
- override
- open func getGrammarFileName() -> String { return "SwiftTest.g4" }
-
- override
- open func getRuleNames() -> [String] { return SwiftTestLexer.ruleNames }
-
- override
- open func getSerializedATN() -> String { return SwiftTestLexer._serializedATN }
-
- override
- open func getChannelNames() -> [String] { return HelloLexer.channelNames }
-
- override
- open func getModeNames() -> [String] { return SwiftTestLexer.modeNames }
-
- override
- open func getATN() -> ATN { return SwiftTestLexer._ATN }
-
- public static let _serializedATN: String = SwiftTestLexerATN().jsonString
- public static let _ATN: ATN = ATNDeserializer().deserializeFromJson(_serializedATN)
-}
diff --git a/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexer.tokens b/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexer.tokens
deleted file mode 100644
index e91685d6e..000000000
--- a/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexer.tokens
+++ /dev/null
@@ -1,2 +0,0 @@
-T__0=1
-'A'=1
diff --git a/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexerATN.swift b/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexerATN.swift
deleted file mode 100644
index 978753511..000000000
--- a/runtime/Swift/Tests/Antlr4Tests/SwiftTestLexerATN.swift
+++ /dev/null
@@ -1,3 +0,0 @@
-class SwiftTestLexerATN {
- let jsonString: String = "{\"version\":3,\"uuid\":\"aadb8d7e-aeef-4415-ad2b-8204d6cf042e\",\"grammarType\":0,\"maxTokenType\":1,\"states\":[{\"stateType\":6,\"ruleIndex\":-1},{\"stateType\":2,\"ruleIndex\":0},{\"stateType\":7,\"ruleIndex\":0},{\"stateType\":1,\"ruleIndex\":0},{\"stateType\":1,\"ruleIndex\":0}],\"nonGreedyStates\":[],\"precedenceStates\":[],\"ruleToStartState\":[{\"stateNumber\":1,\"ruleToTokenType\":1}],\"modeToStartState\":[0],\"nsets\":0,\"IntervalSet\":[],\"allTransitionsBuilder\":[[{\"src\":0,\"trg\":1,\"edgeType\":1,\"arg1\":0,\"arg2\":0,\"arg3\":0}],[{\"src\":1,\"trg\":3,\"edgeType\":1,\"arg1\":0,\"arg2\":0,\"arg3\":0}],[{\"src\":3,\"trg\":4,\"edgeType\":5,\"arg1\":65,\"arg2\":0,\"arg3\":0}],[{\"src\":4,\"trg\":2,\"edgeType\":1,\"arg1\":0,\"arg2\":0,\"arg3\":0}]],\"decisionToState\":[0],\"lexerActions\":[]}"
-}
\ No newline at end of file
diff --git a/runtime/Swift/Tests/Antlr4Tests/SwiftTestListener.swift b/runtime/Swift/Tests/Antlr4Tests/SwiftTestListener.swift
deleted file mode 100644
index fbcbc17bf..000000000
--- a/runtime/Swift/Tests/Antlr4Tests/SwiftTestListener.swift
+++ /dev/null
@@ -1,21 +0,0 @@
-// Generated from SwiftTest.g4 by ANTLR 4.6
-import Antlr4
-
-/**
- * This interface defines a complete listener for a parse tree produced by
- * {@link SwiftTestParser}.
- */
-public protocol SwiftTestListener: ParseTreeListener {
- /**
- * Enter a parse tree produced by {@link SwiftTestParser#s}.
- - Parameters:
- - ctx: the parse tree
- */
- func enterS(_ ctx: SwiftTestParser.SContext)
- /**
- * Exit a parse tree produced by {@link SwiftTestParser#s}.
- - Parameters:
- - ctx: the parse tree
- */
- func exitS(_ ctx: SwiftTestParser.SContext)
-}
\ No newline at end of file
diff --git a/runtime/Swift/Tests/Antlr4Tests/SwiftTestParser.swift b/runtime/Swift/Tests/Antlr4Tests/SwiftTestParser.swift
deleted file mode 100644
index e1ef5ee9c..000000000
--- a/runtime/Swift/Tests/Antlr4Tests/SwiftTestParser.swift
+++ /dev/null
@@ -1,118 +0,0 @@
-// Generated from SwiftTest.g4 by ANTLR 4.6
-import Antlr4
-
-open class SwiftTestParser: Parser {
-
- internal static var _decisionToDFA: [DFA] = {
- var decisionToDFA = [DFA]()
- let length = SwiftTestParser._ATN.getNumberOfDecisions()
- for i in 0.. [String?]? {
- return tokenNames
- }
-
- override
- open func getGrammarFileName() -> String { return "SwiftTest.g4" }
-
- override
- open func getRuleNames() -> [String] { return SwiftTestParser.ruleNames }
-
- override
- open func getSerializedATN() -> String { return SwiftTestParser._serializedATN }
-
- override
- open func getATN() -> ATN { return SwiftTestParser._ATN }
-
- open override func getVocabulary() -> Vocabulary {
- return SwiftTestParser.VOCABULARY
- }
-
- public override init(_ input:TokenStream)throws {
- RuntimeMetaData.checkVersion("4.6", RuntimeMetaData.VERSION)
- try super.init(input)
- _interp = ParserATNSimulator(self,SwiftTestParser._ATN,SwiftTestParser._decisionToDFA, SwiftTestParser._sharedContextCache)
- }
- open class SContext:ParserRuleContext {
- open func EOF() -> TerminalNode? { return getToken(SwiftTestParser.Tokens.EOF.rawValue, 0) }
- open override func getRuleIndex() -> Int { return SwiftTestParser.RULE_s }
- override
- open func enterRule(_ listener: ParseTreeListener) {
- if listener is SwiftTestListener {
- (listener as! SwiftTestListener).enterS(self)
- }
- }
- override
- open func exitRule(_ listener: ParseTreeListener) {
- if listener is SwiftTestListener {
- (listener as! SwiftTestListener).exitS(self)
- }
- }
- }
- @discardableResult
- open func s() throws -> SContext {
- var _localctx: SContext = SContext(_ctx, getState())
- try enterRule(_localctx, 0, SwiftTestParser.RULE_s)
- defer {
- try! exitRule()
- }
- do {
- try enterOuterAlt(_localctx, 1)
- setState(2)
- try match(SwiftTestParser.Tokens.T__0.rawValue)
- setState(3)
- try match(SwiftTestParser.Tokens.EOF.rawValue)
-
- }
- catch ANTLRException.recognition(let re) {
- _localctx.exception = re
- _errHandler.reportError(self, re)
- try _errHandler.recover(self, re)
- }
-
- return _localctx
- }
-
- public static let _serializedATN : String = SwiftTestParserATN().jsonString
- public static let _ATN: ATN = ATNDeserializer().deserializeFromJson(_serializedATN)
-}
\ No newline at end of file
diff --git a/runtime/Swift/Tests/Antlr4Tests/SwiftTestParserATN.swift b/runtime/Swift/Tests/Antlr4Tests/SwiftTestParserATN.swift
deleted file mode 100644
index 0cb68b385..000000000
--- a/runtime/Swift/Tests/Antlr4Tests/SwiftTestParserATN.swift
+++ /dev/null
@@ -1,3 +0,0 @@
-class SwiftTestParserATN {
- let jsonString: String = "{\"version\":3,\"uuid\":\"aadb8d7e-aeef-4415-ad2b-8204d6cf042e\",\"grammarType\":1,\"maxTokenType\":1,\"states\":[{\"stateType\":2,\"ruleIndex\":0},{\"stateType\":7,\"ruleIndex\":0},{\"stateType\":1,\"ruleIndex\":0},{\"stateType\":1,\"ruleIndex\":0},{\"stateType\":1,\"ruleIndex\":0},{\"stateType\":1,\"ruleIndex\":0}],\"nonGreedyStates\":[],\"precedenceStates\":[],\"ruleToStartState\":[{\"stateNumber\":0}],\"modeToStartState\":[],\"nsets\":0,\"IntervalSet\":[],\"allTransitionsBuilder\":[[{\"src\":0,\"trg\":2,\"edgeType\":1,\"arg1\":0,\"arg2\":0,\"arg3\":0}],[{\"src\":2,\"trg\":3,\"edgeType\":5,\"arg1\":1,\"arg2\":0,\"arg3\":0}],[{\"src\":3,\"trg\":4,\"edgeType\":5,\"arg1\":0,\"arg2\":0,\"arg3\":1}],[{\"src\":4,\"trg\":1,\"edgeType\":1,\"arg1\":0,\"arg2\":0,\"arg3\":0}],[]],\"decisionToState\":[],\"lexerActions\":[]}"
-}
\ No newline at end of file
diff --git a/runtime/Swift/test.py b/runtime/Swift/test.py
new file mode 100755
index 000000000..19e6f0be1
--- /dev/null
+++ b/runtime/Swift/test.py
@@ -0,0 +1,66 @@
+#! /usr/bin/python
+
+"""
+Find all .g4 files and generate parsers in the same directory.
+the antlr used should be the one located at user's mvn directory
+the filename is antlr4-ANTLR_VERSION-SNAPSHOT.jar. You can get it
+by running: "mvn install"
+
+NOTE: In case of customized location of .m2 folder, you can change the
+USER_M2 constant below.
+
+the java version is used according to environment variable $JAVA_HOME.
+"""
+
+import fnmatch
+import os.path
+from subprocess import call
+
+ANTLR_VERSION = '4.7'
+USER_M2 = os.path.expanduser('~') + '/.m2/'
+ANTLR4_FOLDER = USER_M2 + 'repository/org/antlr/antlr4/' + ANTLR_VERSION + '-SNAPSHOT/'
+ANTLR4_JAR = ANTLR4_FOLDER + 'antlr4-' + ANTLR_VERSION + '-SNAPSHOT-complete.jar'
+
+
+def jar_exists():
+ """
+ Finds the antlr4 jar.
+ """
+ return os.path.exists(ANTLR4_JAR)
+
+
+def find_g4():
+ """
+ Find all g4 files and return a list of them.
+ The recursive search starts from the directory containing
+ this python file.
+ """
+ file_path = os.path.realpath(__file__)
+ parent_folder = file_path[0:file_path.rindex('/')+1]
+ res = []
+ for cur, _, filenames in os.walk(parent_folder):
+ cur_files = fnmatch.filter(filenames, "*.g4")
+ res += [cur+'/'+cur_file for cur_file in cur_files]
+ return res
+
+
+def gen_parser(grammar):
+ """
+ Generate parser for the input g4 file.
+ """
+ java_home = os.environ['JAVA_HOME']
+ java = java_home + '/bin/java'
+ if not os.path.exists(java):
+ print 'Cannot find java. Check your JAVA_HOME setting.'
+ return
+
+ call([java, '-jar', ANTLR4_JAR, '-Dlanguage=Swift', grammar])
+
+
+if __name__ == '__main__':
+ if not jar_exists():
+ print 'Run "mvn install" in antlr4 project root' + \
+ 'first or check mvn settings'
+ exit()
+
+ _ = [gen_parser(f) for f in find_g4()]