From 2b36e74ff5e9b7467b36d7df8a5633b688942e5f Mon Sep 17 00:00:00 2001
From: Atreya Bain
Date: Tue, 29 Sep 2020 23:16:42 +0530
Subject: [PATCH] add antlr
---
.gitignore | 5 +-
.vscode/c_cpp_properties.json | 18 +
.vscode/settings.json | 9 +-
CMakeLists.txt | 12 +-
grammar/bf.g4 | 13 +
include/main.hpp | 3 +
lib/antlr4/include/ANTLRErrorListener.h | 167 ++++
lib/antlr4/include/ANTLRErrorStrategy.h | 121 +++
lib/antlr4/include/ANTLRFileStream.h | 27 +
lib/antlr4/include/ANTLRInputStream.h | 69 ++
lib/antlr4/include/BailErrorStrategy.h | 59 ++
lib/antlr4/include/BaseErrorListener.h | 36 +
lib/antlr4/include/BufferedTokenStream.h | 200 ++++
lib/antlr4/include/CharStream.h | 37 +
lib/antlr4/include/CommonToken.h | 158 +++
lib/antlr4/include/CommonTokenFactory.h | 74 ++
lib/antlr4/include/CommonTokenStream.h | 79 ++
lib/antlr4/include/ConsoleErrorListener.h | 35 +
lib/antlr4/include/DefaultErrorStrategy.h | 466 +++++++++
lib/antlr4/include/DiagnosticErrorListener.h | 80 ++
lib/antlr4/include/Exceptions.h | 99 ++
lib/antlr4/include/FailedPredicateException.h | 32 +
lib/antlr4/include/InputMismatchException.h | 24 +
lib/antlr4/include/IntStream.h | 218 +++++
lib/antlr4/include/InterpreterRuleContext.h | 45 +
lib/antlr4/include/Lexer.h | 196 ++++
lib/antlr4/include/LexerInterpreter.h | 52 +
.../include/LexerNoViableAltException.h | 31 +
lib/antlr4/include/ListTokenSource.h | 88 ++
lib/antlr4/include/NoViableAltException.h | 42 +
lib/antlr4/include/Parser.h | 467 +++++++++
lib/antlr4/include/ParserInterpreter.h | 179 ++++
lib/antlr4/include/ParserRuleContext.h | 147 +++
lib/antlr4/include/ProxyErrorListener.h | 38 +
lib/antlr4/include/RecognitionException.h | 98 ++
lib/antlr4/include/Recognizer.h | 164 ++++
lib/antlr4/include/RuleContext.h | 137 +++
lib/antlr4/include/RuleContextWithAltNum.h | 32 +
lib/antlr4/include/RuntimeMetaData.h | 155 +++
lib/antlr4/include/Token.h | 92 ++
lib/antlr4/include/TokenFactory.h | 30 +
lib/antlr4/include/TokenSource.h | 85 ++
lib/antlr4/include/TokenStream.h | 137 +++
lib/antlr4/include/TokenStreamRewriter.h | 293 ++++++
lib/antlr4/include/UnbufferedCharStream.h | 123 +++
lib/antlr4/include/UnbufferedTokenStream.h | 115 +++
lib/antlr4/include/Vocabulary.h | 193 ++++
lib/antlr4/include/WritableToken.h | 23 +
lib/antlr4/include/antlr4-common.h | 137 +++
lib/antlr4/include/antlr4-runtime.h | 167 ++++
lib/antlr4/include/atn/ATN.h | 112 +++
lib/antlr4/include/atn/ATNConfig.h | 148 +++
lib/antlr4/include/atn/ATNConfigSet.h | 110 +++
.../include/atn/ATNDeserializationOptions.h | 50 +
lib/antlr4/include/atn/ATNDeserializer.h | 85 ++
lib/antlr4/include/atn/ATNSerializer.h | 61 ++
lib/antlr4/include/atn/ATNSimulator.h | 87 ++
lib/antlr4/include/atn/ATNState.h | 133 +++
lib/antlr4/include/atn/ATNType.h | 20 +
.../include/atn/AbstractPredicateTransition.h | 24 +
lib/antlr4/include/atn/ActionTransition.h | 33 +
lib/antlr4/include/atn/AmbiguityInfo.h | 68 ++
.../include/atn/ArrayPredictionContext.h | 43 +
lib/antlr4/include/atn/AtomTransition.h | 30 +
lib/antlr4/include/atn/BasicBlockStartState.h | 22 +
lib/antlr4/include/atn/BasicState.h | 21 +
lib/antlr4/include/atn/BlockEndState.h | 24 +
lib/antlr4/include/atn/BlockStartState.h | 21 +
.../include/atn/ContextSensitivityInfo.h | 47 +
lib/antlr4/include/atn/DecisionEventInfo.h | 70 ++
lib/antlr4/include/atn/DecisionInfo.h | 227 +++++
lib/antlr4/include/atn/DecisionState.h | 30 +
.../include/atn/EmptyPredictionContext.h | 27 +
lib/antlr4/include/atn/EpsilonTransition.h | 39 +
lib/antlr4/include/atn/ErrorInfo.h | 43 +
lib/antlr4/include/atn/LL1Analyzer.h | 109 +++
lib/antlr4/include/atn/LexerATNConfig.h | 44 +
lib/antlr4/include/atn/LexerATNSimulator.h | 210 ++++
lib/antlr4/include/atn/LexerAction.h | 66 ++
lib/antlr4/include/atn/LexerActionExecutor.h | 115 +++
lib/antlr4/include/atn/LexerActionType.h | 55 ++
lib/antlr4/include/atn/LexerChannelAction.h | 63 ++
lib/antlr4/include/atn/LexerCustomAction.h | 87 ++
.../include/atn/LexerIndexedCustomAction.h | 82 ++
lib/antlr4/include/atn/LexerModeAction.h | 61 ++
lib/antlr4/include/atn/LexerMoreAction.h | 57 ++
lib/antlr4/include/atn/LexerPopModeAction.h | 57 ++
lib/antlr4/include/atn/LexerPushModeAction.h | 61 ++
lib/antlr4/include/atn/LexerSkipAction.h | 55 ++
lib/antlr4/include/atn/LexerTypeAction.h | 55 ++
lib/antlr4/include/atn/LookaheadEventInfo.h | 42 +
lib/antlr4/include/atn/LoopEndState.h | 22 +
lib/antlr4/include/atn/NotSetTransition.h | 25 +
lib/antlr4/include/atn/OrderedATNConfigSet.h | 20 +
lib/antlr4/include/atn/ParseInfo.h | 102 ++
lib/antlr4/include/atn/ParserATNSimulator.h | 904 ++++++++++++++++++
lib/antlr4/include/atn/PlusBlockStartState.h | 25 +
lib/antlr4/include/atn/PlusLoopbackState.h | 22 +
.../atn/PrecedencePredicateTransition.h | 29 +
lib/antlr4/include/atn/PredicateEvalInfo.h | 62 ++
lib/antlr4/include/atn/PredicateTransition.h | 39 +
lib/antlr4/include/atn/PredictionContext.h | 254 +++++
lib/antlr4/include/atn/PredictionMode.h | 436 +++++++++
.../include/atn/ProfilingATNSimulator.h | 60 ++
lib/antlr4/include/atn/RangeTransition.h | 29 +
lib/antlr4/include/atn/RuleStartState.h | 25 +
lib/antlr4/include/atn/RuleStopState.h | 25 +
lib/antlr4/include/atn/RuleTransition.h | 40 +
lib/antlr4/include/atn/SemanticContext.h | 222 +++++
lib/antlr4/include/atn/SetTransition.h | 30 +
.../include/atn/SingletonPredictionContext.h | 36 +
lib/antlr4/include/atn/StarBlockStartState.h | 21 +
lib/antlr4/include/atn/StarLoopEntryState.h | 35 +
lib/antlr4/include/atn/StarLoopbackState.h | 21 +
lib/antlr4/include/atn/TokensStartState.h | 21 +
lib/antlr4/include/atn/Transition.h | 76 ++
lib/antlr4/include/atn/WildcardTransition.h | 25 +
lib/antlr4/include/dfa/DFA.h | 91 ++
lib/antlr4/include/dfa/DFASerializer.h | 32 +
lib/antlr4/include/dfa/DFAState.h | 144 +++
lib/antlr4/include/dfa/LexerDFASerializer.h | 23 +
.../include/misc/InterpreterDataReader.h | 31 +
lib/antlr4/include/misc/Interval.h | 84 ++
lib/antlr4/include/misc/IntervalSet.h | 198 ++++
lib/antlr4/include/misc/MurmurHash.h | 76 ++
lib/antlr4/include/misc/Predicate.h | 21 +
lib/antlr4/include/support/Any.h | 170 ++++
lib/antlr4/include/support/Arrays.h | 110 +++
lib/antlr4/include/support/BitSet.h | 76 ++
lib/antlr4/include/support/CPPUtils.h | 78 ++
lib/antlr4/include/support/Declarations.h | 163 ++++
lib/antlr4/include/support/StringUtils.h | 54 ++
lib/antlr4/include/support/guid.h | 112 +++
.../include/tree/AbstractParseTreeVisitor.h | 128 +++
lib/antlr4/include/tree/ErrorNode.h | 19 +
lib/antlr4/include/tree/ErrorNodeImpl.h | 33 +
.../include/tree/IterativeParseTreeWalker.h | 53 +
lib/antlr4/include/tree/ParseTree.h | 102 ++
lib/antlr4/include/tree/ParseTreeListener.h | 39 +
lib/antlr4/include/tree/ParseTreeProperty.h | 50 +
lib/antlr4/include/tree/ParseTreeVisitor.h | 57 ++
lib/antlr4/include/tree/ParseTreeWalker.h | 31 +
lib/antlr4/include/tree/TerminalNode.h | 32 +
lib/antlr4/include/tree/TerminalNodeImpl.h | 33 +
lib/antlr4/include/tree/Trees.h | 78 ++
lib/antlr4/include/tree/pattern/Chunk.h | 44 +
.../include/tree/pattern/ParseTreeMatch.h | 132 +++
.../include/tree/pattern/ParseTreePattern.h | 105 ++
.../tree/pattern/ParseTreePatternMatcher.h | 185 ++++
.../include/tree/pattern/RuleTagToken.h | 117 +++
lib/antlr4/include/tree/pattern/TagChunk.h | 86 ++
lib/antlr4/include/tree/pattern/TextChunk.h | 51 +
.../include/tree/pattern/TokenTagToken.h | 80 ++
lib/antlr4/include/tree/xpath/XPath.h | 86 ++
lib/antlr4/include/tree/xpath/XPathElement.h | 40 +
lib/antlr4/include/tree/xpath/XPathLexer.h | 56 ++
.../tree/xpath/XPathLexerErrorListener.h | 22 +
.../tree/xpath/XPathRuleAnywhereElement.h | 27 +
.../include/tree/xpath/XPathRuleElement.h | 26 +
.../tree/xpath/XPathTokenAnywhereElement.h | 25 +
.../include/tree/xpath/XPathTokenElement.h | 26 +
.../tree/xpath/XPathWildcardAnywhereElement.h | 23 +
.../include/tree/xpath/XPathWildcardElement.h | 23 +
lib/antlr4/lib/libantlr4-runtime.so.4.8 | Bin 0 -> 1612832 bytes
lib/generated/bf.tokens | 14 +
lib/generated/bfBaseListener.cpp | 7 +
lib/generated/bfBaseListener.h | 32 +
lib/generated/bfBaseVisitor.cpp | 7 +
lib/generated/bfBaseVisitor.h | 28 +
lib/generated/bfLexer.cpp | 139 +++
lib/generated/bfLexer.h | 56 ++
lib/generated/bfLexer.tokens | 14 +
lib/generated/bfListener.cpp | 7 +
lib/generated/bfListener.h | 25 +
lib/generated/bfParser.cpp | 231 +++++
lib/generated/bfParser.h | 87 ++
lib/generated/bfVisitor.cpp | 7 +
lib/generated/bfVisitor.h | 28 +
sample.txt | 1 +
src/main.cpp | 34 +-
thirdparty/antlr/antlr-4.8-complete.jar | Bin 0 -> 2089101 bytes
181 files changed, 14689 insertions(+), 7 deletions(-)
create mode 100644 .vscode/c_cpp_properties.json
create mode 100644 grammar/bf.g4
create mode 100644 include/main.hpp
create mode 100644 lib/antlr4/include/ANTLRErrorListener.h
create mode 100644 lib/antlr4/include/ANTLRErrorStrategy.h
create mode 100644 lib/antlr4/include/ANTLRFileStream.h
create mode 100644 lib/antlr4/include/ANTLRInputStream.h
create mode 100644 lib/antlr4/include/BailErrorStrategy.h
create mode 100644 lib/antlr4/include/BaseErrorListener.h
create mode 100644 lib/antlr4/include/BufferedTokenStream.h
create mode 100644 lib/antlr4/include/CharStream.h
create mode 100644 lib/antlr4/include/CommonToken.h
create mode 100644 lib/antlr4/include/CommonTokenFactory.h
create mode 100644 lib/antlr4/include/CommonTokenStream.h
create mode 100644 lib/antlr4/include/ConsoleErrorListener.h
create mode 100644 lib/antlr4/include/DefaultErrorStrategy.h
create mode 100644 lib/antlr4/include/DiagnosticErrorListener.h
create mode 100644 lib/antlr4/include/Exceptions.h
create mode 100644 lib/antlr4/include/FailedPredicateException.h
create mode 100644 lib/antlr4/include/InputMismatchException.h
create mode 100644 lib/antlr4/include/IntStream.h
create mode 100644 lib/antlr4/include/InterpreterRuleContext.h
create mode 100644 lib/antlr4/include/Lexer.h
create mode 100644 lib/antlr4/include/LexerInterpreter.h
create mode 100644 lib/antlr4/include/LexerNoViableAltException.h
create mode 100644 lib/antlr4/include/ListTokenSource.h
create mode 100644 lib/antlr4/include/NoViableAltException.h
create mode 100644 lib/antlr4/include/Parser.h
create mode 100644 lib/antlr4/include/ParserInterpreter.h
create mode 100644 lib/antlr4/include/ParserRuleContext.h
create mode 100644 lib/antlr4/include/ProxyErrorListener.h
create mode 100644 lib/antlr4/include/RecognitionException.h
create mode 100644 lib/antlr4/include/Recognizer.h
create mode 100644 lib/antlr4/include/RuleContext.h
create mode 100644 lib/antlr4/include/RuleContextWithAltNum.h
create mode 100644 lib/antlr4/include/RuntimeMetaData.h
create mode 100644 lib/antlr4/include/Token.h
create mode 100644 lib/antlr4/include/TokenFactory.h
create mode 100644 lib/antlr4/include/TokenSource.h
create mode 100644 lib/antlr4/include/TokenStream.h
create mode 100644 lib/antlr4/include/TokenStreamRewriter.h
create mode 100644 lib/antlr4/include/UnbufferedCharStream.h
create mode 100644 lib/antlr4/include/UnbufferedTokenStream.h
create mode 100644 lib/antlr4/include/Vocabulary.h
create mode 100644 lib/antlr4/include/WritableToken.h
create mode 100644 lib/antlr4/include/antlr4-common.h
create mode 100644 lib/antlr4/include/antlr4-runtime.h
create mode 100644 lib/antlr4/include/atn/ATN.h
create mode 100644 lib/antlr4/include/atn/ATNConfig.h
create mode 100644 lib/antlr4/include/atn/ATNConfigSet.h
create mode 100644 lib/antlr4/include/atn/ATNDeserializationOptions.h
create mode 100644 lib/antlr4/include/atn/ATNDeserializer.h
create mode 100644 lib/antlr4/include/atn/ATNSerializer.h
create mode 100644 lib/antlr4/include/atn/ATNSimulator.h
create mode 100644 lib/antlr4/include/atn/ATNState.h
create mode 100644 lib/antlr4/include/atn/ATNType.h
create mode 100644 lib/antlr4/include/atn/AbstractPredicateTransition.h
create mode 100644 lib/antlr4/include/atn/ActionTransition.h
create mode 100644 lib/antlr4/include/atn/AmbiguityInfo.h
create mode 100644 lib/antlr4/include/atn/ArrayPredictionContext.h
create mode 100644 lib/antlr4/include/atn/AtomTransition.h
create mode 100644 lib/antlr4/include/atn/BasicBlockStartState.h
create mode 100644 lib/antlr4/include/atn/BasicState.h
create mode 100644 lib/antlr4/include/atn/BlockEndState.h
create mode 100644 lib/antlr4/include/atn/BlockStartState.h
create mode 100644 lib/antlr4/include/atn/ContextSensitivityInfo.h
create mode 100644 lib/antlr4/include/atn/DecisionEventInfo.h
create mode 100644 lib/antlr4/include/atn/DecisionInfo.h
create mode 100644 lib/antlr4/include/atn/DecisionState.h
create mode 100644 lib/antlr4/include/atn/EmptyPredictionContext.h
create mode 100644 lib/antlr4/include/atn/EpsilonTransition.h
create mode 100644 lib/antlr4/include/atn/ErrorInfo.h
create mode 100644 lib/antlr4/include/atn/LL1Analyzer.h
create mode 100644 lib/antlr4/include/atn/LexerATNConfig.h
create mode 100644 lib/antlr4/include/atn/LexerATNSimulator.h
create mode 100644 lib/antlr4/include/atn/LexerAction.h
create mode 100644 lib/antlr4/include/atn/LexerActionExecutor.h
create mode 100644 lib/antlr4/include/atn/LexerActionType.h
create mode 100644 lib/antlr4/include/atn/LexerChannelAction.h
create mode 100644 lib/antlr4/include/atn/LexerCustomAction.h
create mode 100644 lib/antlr4/include/atn/LexerIndexedCustomAction.h
create mode 100644 lib/antlr4/include/atn/LexerModeAction.h
create mode 100644 lib/antlr4/include/atn/LexerMoreAction.h
create mode 100644 lib/antlr4/include/atn/LexerPopModeAction.h
create mode 100644 lib/antlr4/include/atn/LexerPushModeAction.h
create mode 100644 lib/antlr4/include/atn/LexerSkipAction.h
create mode 100644 lib/antlr4/include/atn/LexerTypeAction.h
create mode 100644 lib/antlr4/include/atn/LookaheadEventInfo.h
create mode 100644 lib/antlr4/include/atn/LoopEndState.h
create mode 100644 lib/antlr4/include/atn/NotSetTransition.h
create mode 100644 lib/antlr4/include/atn/OrderedATNConfigSet.h
create mode 100644 lib/antlr4/include/atn/ParseInfo.h
create mode 100644 lib/antlr4/include/atn/ParserATNSimulator.h
create mode 100644 lib/antlr4/include/atn/PlusBlockStartState.h
create mode 100644 lib/antlr4/include/atn/PlusLoopbackState.h
create mode 100644 lib/antlr4/include/atn/PrecedencePredicateTransition.h
create mode 100644 lib/antlr4/include/atn/PredicateEvalInfo.h
create mode 100644 lib/antlr4/include/atn/PredicateTransition.h
create mode 100644 lib/antlr4/include/atn/PredictionContext.h
create mode 100644 lib/antlr4/include/atn/PredictionMode.h
create mode 100644 lib/antlr4/include/atn/ProfilingATNSimulator.h
create mode 100644 lib/antlr4/include/atn/RangeTransition.h
create mode 100644 lib/antlr4/include/atn/RuleStartState.h
create mode 100644 lib/antlr4/include/atn/RuleStopState.h
create mode 100644 lib/antlr4/include/atn/RuleTransition.h
create mode 100644 lib/antlr4/include/atn/SemanticContext.h
create mode 100644 lib/antlr4/include/atn/SetTransition.h
create mode 100644 lib/antlr4/include/atn/SingletonPredictionContext.h
create mode 100644 lib/antlr4/include/atn/StarBlockStartState.h
create mode 100644 lib/antlr4/include/atn/StarLoopEntryState.h
create mode 100644 lib/antlr4/include/atn/StarLoopbackState.h
create mode 100644 lib/antlr4/include/atn/TokensStartState.h
create mode 100644 lib/antlr4/include/atn/Transition.h
create mode 100644 lib/antlr4/include/atn/WildcardTransition.h
create mode 100644 lib/antlr4/include/dfa/DFA.h
create mode 100644 lib/antlr4/include/dfa/DFASerializer.h
create mode 100644 lib/antlr4/include/dfa/DFAState.h
create mode 100644 lib/antlr4/include/dfa/LexerDFASerializer.h
create mode 100644 lib/antlr4/include/misc/InterpreterDataReader.h
create mode 100644 lib/antlr4/include/misc/Interval.h
create mode 100644 lib/antlr4/include/misc/IntervalSet.h
create mode 100644 lib/antlr4/include/misc/MurmurHash.h
create mode 100644 lib/antlr4/include/misc/Predicate.h
create mode 100644 lib/antlr4/include/support/Any.h
create mode 100644 lib/antlr4/include/support/Arrays.h
create mode 100644 lib/antlr4/include/support/BitSet.h
create mode 100644 lib/antlr4/include/support/CPPUtils.h
create mode 100644 lib/antlr4/include/support/Declarations.h
create mode 100644 lib/antlr4/include/support/StringUtils.h
create mode 100644 lib/antlr4/include/support/guid.h
create mode 100644 lib/antlr4/include/tree/AbstractParseTreeVisitor.h
create mode 100644 lib/antlr4/include/tree/ErrorNode.h
create mode 100644 lib/antlr4/include/tree/ErrorNodeImpl.h
create mode 100644 lib/antlr4/include/tree/IterativeParseTreeWalker.h
create mode 100644 lib/antlr4/include/tree/ParseTree.h
create mode 100644 lib/antlr4/include/tree/ParseTreeListener.h
create mode 100644 lib/antlr4/include/tree/ParseTreeProperty.h
create mode 100644 lib/antlr4/include/tree/ParseTreeVisitor.h
create mode 100644 lib/antlr4/include/tree/ParseTreeWalker.h
create mode 100644 lib/antlr4/include/tree/TerminalNode.h
create mode 100644 lib/antlr4/include/tree/TerminalNodeImpl.h
create mode 100644 lib/antlr4/include/tree/Trees.h
create mode 100644 lib/antlr4/include/tree/pattern/Chunk.h
create mode 100644 lib/antlr4/include/tree/pattern/ParseTreeMatch.h
create mode 100644 lib/antlr4/include/tree/pattern/ParseTreePattern.h
create mode 100644 lib/antlr4/include/tree/pattern/ParseTreePatternMatcher.h
create mode 100644 lib/antlr4/include/tree/pattern/RuleTagToken.h
create mode 100644 lib/antlr4/include/tree/pattern/TagChunk.h
create mode 100644 lib/antlr4/include/tree/pattern/TextChunk.h
create mode 100644 lib/antlr4/include/tree/pattern/TokenTagToken.h
create mode 100644 lib/antlr4/include/tree/xpath/XPath.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathElement.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathLexer.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathLexerErrorListener.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathRuleAnywhereElement.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathRuleElement.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathTokenAnywhereElement.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathTokenElement.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathWildcardAnywhereElement.h
create mode 100644 lib/antlr4/include/tree/xpath/XPathWildcardElement.h
create mode 100755 lib/antlr4/lib/libantlr4-runtime.so.4.8
create mode 100644 lib/generated/bf.tokens
create mode 100644 lib/generated/bfBaseListener.cpp
create mode 100644 lib/generated/bfBaseListener.h
create mode 100644 lib/generated/bfBaseVisitor.cpp
create mode 100644 lib/generated/bfBaseVisitor.h
create mode 100644 lib/generated/bfLexer.cpp
create mode 100644 lib/generated/bfLexer.h
create mode 100644 lib/generated/bfLexer.tokens
create mode 100644 lib/generated/bfListener.cpp
create mode 100644 lib/generated/bfListener.h
create mode 100644 lib/generated/bfParser.cpp
create mode 100644 lib/generated/bfParser.h
create mode 100644 lib/generated/bfVisitor.cpp
create mode 100644 lib/generated/bfVisitor.h
create mode 100644 sample.txt
create mode 100644 thirdparty/antlr/antlr-4.8-complete.jar
diff --git a/.gitignore b/.gitignore
index 307433c..4a785b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+.antlr/
+build/
+
# Prerequisites
*.d
@@ -31,8 +34,6 @@
*.out
*.app
-build/
-
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..612616b
--- /dev/null
+++ b/.vscode/c_cpp_properties.json
@@ -0,0 +1,18 @@
+{
+ "configurations": [
+ {
+ "name": "Linux",
+ "includePath": [
+ "${workspaceFolder}/include",
+ "${workspaceFolder}/**"
+ ],
+ "defines": [],
+ "compilerPath": "/usr/lib64/ccache/clang",
+ "cStandard": "c11",
+ "cppStandard": "c++14",
+ "intelliSenseMode": "clang-x64",
+ "configurationProvider": "ms-vscode.cmake-tools"
+ }
+ ],
+ "version": 4
+}
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0db5873..4544474 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,3 +1,10 @@
{
- "cmake.configureOnOpen": true
+ "cmake.configureOnOpen": true,
+ "antlr4.generation": {
+ "mode": "external",
+ "language": "Cpp",
+ "listeners": true,
+ "visitors": true,
+ "outputDir": "../lib/generated"
+ }
}
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 057fe38..b53171f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,11 +9,21 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
set(SOURCES
src/main.cpp
+ lib/generated/bfLexer.cpp
+ lib/generated/bfParser.cpp
+ lib/generated/bfBaseVisitor.cpp
+ lib/generated/bfVisitor.cpp
+ lib/generated/bfBaseListener.cpp
+ lib/generated/bfListener.cpp
)
-
add_executable(main.out ${SOURCES})
+target_link_libraries(main.out ${PROJECT_SOURCE_DIR}/lib/antlr4/lib/libantlr4-runtime.a)
+
target_include_directories(main.out
PRIVATE
${PROJECT_SOURCE_DIR}/include
+ ${PROJECT_SOURCE_DIR}/lib/antlr4/include
+ ${PROJECT_SOURCE_DIR}/lib/generated
+
)
diff --git a/grammar/bf.g4 b/grammar/bf.g4
new file mode 100644
index 0000000..fc91c00
--- /dev/null
+++ b/grammar/bf.g4
@@ -0,0 +1,13 @@
+grammar bf;
+
+program: statements;
+
+statements: INC | DEC | INPUT|OUTPUT;
+
+COMMENT: '\\\\.*?\\\\' -> skip;
+INPUT: '?';
+OUTPUT: '.';
+DEC: '-';
+INC: '+';
+LEFT: '>';
+RIGHT: '<';
diff --git a/include/main.hpp b/include/main.hpp
new file mode 100644
index 0000000..b4243fa
--- /dev/null
+++ b/include/main.hpp
@@ -0,0 +1,3 @@
+#ifndef __MAIN_HPP
+#define FIVE 5
+#endif
\ No newline at end of file
diff --git a/lib/antlr4/include/ANTLRErrorListener.h b/lib/antlr4/include/ANTLRErrorListener.h
new file mode 100644
index 0000000..d6efad1
--- /dev/null
+++ b/lib/antlr4/include/ANTLRErrorListener.h
@@ -0,0 +1,167 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "RecognitionException.h"
+
+namespace antlrcpp {
+ class BitSet;
+}
+
+namespace antlr4 {
+
+ /// How to emit recognition errors (an interface in Java).
+ class ANTLR4CPP_PUBLIC ANTLRErrorListener {
+ public:
+ virtual ~ANTLRErrorListener();
+
+ ///
+ /// Upon syntax error, notify any interested parties. This is not how to
+ /// recover from errors or compute error messages.
+ /// specifies how to recover from syntax errors and how to compute error
+ /// messages. This listener's job is simply to emit a computed message,
+ /// though it has enough information to create its own message in many cases.
+ ///
+ /// The is non-null for all syntax errors except
+ /// when we discover mismatched token errors that we can recover from
+ /// in-line, without returning from the surrounding rule (via the single
+ /// token insertion and deletion mechanism).
+ ///
+ ///
+ /// What parser got the error. From this
+ /// object, you can access the context as well
+ /// as the input stream.
+ ///
+ /// The offending token in the input token
+ /// stream, unless recognizer is a lexer (then it's null). If
+ /// no viable alternative error, {@code e} has token at which we
+ /// started production for the decision.
+ ///
+ /// The line number in the input where the error occurred.
+ ///
+ /// The character position within that line where the error occurred.
+ ///
+ /// The message to emit.
+ ///
+ /// The exception generated by the parser that led to
+ /// the reporting of an error. It is null in the case where
+ /// the parser was able to recover in line without exiting the
+ /// surrounding rule.
+ virtual void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line,
+ size_t charPositionInLine, const std::string &msg, std::exception_ptr e) = 0;
+
+ /**
+ * This method is called by the parser when a full-context prediction
+ * results in an ambiguity.
+ *
+ * Each full-context prediction which does not result in a syntax error
+ * will call either {@link #reportContextSensitivity} or
+ * {@link #reportAmbiguity}.
+ *
+ * When {@code ambigAlts} is not null, it contains the set of potentially
+ * viable alternatives identified by the prediction algorithm. When
+ * {@code ambigAlts} is null, use {@link ATNConfigSet#getAlts} to obtain the
+ * represented alternatives from the {@code configs} argument.
+ *
+ * When {@code exact} is {@code true}, all of the potentially
+ * viable alternatives are truly viable, i.e. this is reporting an exact
+ * ambiguity. When {@code exact} is {@code false}, at least two of
+ * the potentially viable alternatives are viable for the current input, but
+ * the prediction algorithm terminated as soon as it determined that at
+ * least the minimum potentially viable alternative is truly
+ * viable.
+ *
+ * When the {@link PredictionMode#LL_EXACT_AMBIG_DETECTION} prediction
+ * mode is used, the parser is required to identify exact ambiguities so
+ * {@code exact} will always be {@code true}.
+ *
+ * This method is not used by lexers.
+ *
+ * @param recognizer the parser instance
+ * @param dfa the DFA for the current decision
+ * @param startIndex the input index where the decision started
+ * @param stopIndex the input input where the ambiguity was identified
+ * @param exact {@code true} if the ambiguity is exactly known, otherwise
+ * {@code false}. This is always {@code true} when
+ * {@link PredictionMode#LL_EXACT_AMBIG_DETECTION} is used.
+ * @param ambigAlts the potentially ambiguous alternatives, or {@code null}
+ * to indicate that the potentially ambiguous alternatives are the complete
+ * set of represented alternatives in {@code configs}
+ * @param configs the ATN configuration set where the ambiguity was
+ * identified
+ */
+ virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
+ const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) = 0;
+
+ /**
+ * This method is called when an SLL conflict occurs and the parser is about
+ * to use the full context information to make an LL decision.
+ *
+ * If one or more configurations in {@code configs} contains a semantic
+ * predicate, the predicates are evaluated before this method is called. The
+ * subset of alternatives which are still viable after predicates are
+ * evaluated is reported in {@code conflictingAlts}.
+ *
+ * This method is not used by lexers.
+ *
+ * @param recognizer the parser instance
+ * @param dfa the DFA for the current decision
+ * @param startIndex the input index where the decision started
+ * @param stopIndex the input index where the SLL conflict occurred
+ * @param conflictingAlts The specific conflicting alternatives. If this is
+ * {@code null}, the conflicting alternatives are all alternatives
+ * represented in {@code configs}. At the moment, conflictingAlts is non-null
+ * (for the reference implementation, but Sam's optimized version can see this
+ * as null).
+ * @param configs the ATN configuration set where the SLL conflict was
+ * detected
+ */
+ virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
+ const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) = 0;
+
+ /**
+ * This method is called by the parser when a full-context prediction has a
+ * unique result.
+ *
+ * Each full-context prediction which does not result in a syntax error
+ * will call either {@link #reportContextSensitivity} or
+ * {@link #reportAmbiguity}.
+ *
+ * For prediction implementations that only evaluate full-context
+ * predictions when an SLL conflict is found (including the default
+ * {@link ParserATNSimulator} implementation), this method reports cases
+ * where SLL conflicts were resolved to unique full-context predictions,
+ * i.e. the decision was context-sensitive. This report does not necessarily
+ * indicate a problem, and it may appear even in completely unambiguous
+ * grammars.
+ *
+ * {@code configs} may have more than one represented alternative if the
+ * full-context prediction algorithm does not evaluate predicates before
+ * beginning the full-context prediction. In all cases, the final prediction
+ * is passed as the {@code prediction} argument.
+ *
+ * Note that the definition of "context sensitivity" in this method
+ * differs from the concept in {@link DecisionInfo#contextSensitivities}.
+ * This method reports all instances where an SLL conflict occurred but LL
+ * parsing produced a unique result, whether or not that unique result
+ * matches the minimum alternative in the SLL conflicting set.
+ *
+ * This method is not used by lexers.
+ *
+ * @param recognizer the parser instance
+ * @param dfa the DFA for the current decision
+ * @param startIndex the input index where the decision started
+ * @param stopIndex the input index where the context sensitivity was
+ * finally determined
+ * @param prediction the unambiguous result of the full-context prediction
+ * @param configs the ATN configuration set where the unambiguous prediction
+ * was determined
+ */
+ virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
+ size_t prediction, atn::ATNConfigSet *configs) = 0;
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/ANTLRErrorStrategy.h b/lib/antlr4/include/ANTLRErrorStrategy.h
new file mode 100644
index 0000000..a3eecd1
--- /dev/null
+++ b/lib/antlr4/include/ANTLRErrorStrategy.h
@@ -0,0 +1,121 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "Token.h"
+
+namespace antlr4 {
+
+ ///
+ /// The interface for defining strategies to deal with syntax errors encountered
+ /// during a parse by ANTLR-generated parsers. We distinguish between three
+ /// different kinds of errors:
+ ///
+ ///
+ /// - The parser could not figure out which path to take in the ATN (none of
+ /// the available alternatives could possibly match)
+ /// - The current input does not match what we were looking for
+ /// - A predicate evaluated to false
+ ///
+ ///
+ /// Implementations of this interface report syntax errors by calling
+ /// .
+ ///
+ /// TODO: what to do about lexers
+ ///
+ class ANTLR4CPP_PUBLIC ANTLRErrorStrategy {
+ public:
+
+ ///
+ /// Reset the error handler state for the specified {@code recognizer}.
+ /// the parser instance
+ virtual ~ANTLRErrorStrategy();
+
+ virtual void reset(Parser *recognizer) = 0;
+
+ /**
+ * This method is called when an unexpected symbol is encountered during an
+ * inline match operation, such as {@link Parser#match}. If the error
+ * strategy successfully recovers from the match failure, this method
+ * returns the {@link Token} instance which should be treated as the
+ * successful result of the match.
+ *
+ * This method handles the consumption of any tokens - the caller should
+ * not call {@link Parser#consume} after a successful recovery.
+ *
+ * Note that the calling code will not report an error if this method
+ * returns successfully. The error strategy implementation is responsible
+ * for calling {@link Parser#notifyErrorListeners} as appropriate.
+ *
+ * @param recognizer the parser instance
+ * @throws RecognitionException if the error strategy was not able to
+ * recover from the unexpected input symbol
+ */
+ virtual Token* recoverInline(Parser *recognizer) = 0;
+
+ ///
+ /// This method is called to recover from exception {@code e}. This method is
+ /// called after by the default exception handler
+ /// generated for a rule method.
+ ///
+ ///
+ /// the parser instance
+ /// the recognition exception to recover from
+ /// if the error strategy could not recover from
+ /// the recognition exception
+ virtual void recover(Parser *recognizer, std::exception_ptr e) = 0;
+
+ ///
+ /// This method provides the error handler with an opportunity to handle
+ /// syntactic or semantic errors in the input stream before they result in a
+ /// .
+ ///
+ /// The generated code currently contains calls to after
+ /// entering the decision state of a closure block ({@code (...)*} or
+ /// {@code (...)+}).
+ ///
+ /// For an implementation based on Jim Idle's "magic sync" mechanism, see
+ /// .
+ ///
+ ///
+ /// the parser instance
+ /// if an error is detected by the error
+ /// strategy but cannot be automatically recovered at the current state in
+ /// the parsing process
+ virtual void sync(Parser *recognizer) = 0;
+
+ ///
+ /// Tests whether or not {@code recognizer} is in the process of recovering
+ /// from an error. In error recovery mode, adds
+ /// symbols to the parse tree by calling
+ /// {@link Parser#createErrorNode(ParserRuleContext, Token)} then
+ /// {@link ParserRuleContext#addErrorNode(ErrorNode)} instead of
+ /// {@link Parser#createTerminalNode(ParserRuleContext, Token)}.
+ ///
+ /// the parser instance
+ /// {@code true} if the parser is currently recovering from a parse
+ /// error, otherwise {@code false}
+ virtual bool inErrorRecoveryMode(Parser *recognizer) = 0;
+
+ ///
+ /// This method is called by when the parser successfully matches an input
+ /// symbol.
+ ///
+ /// the parser instance
+ virtual void reportMatch(Parser *recognizer) = 0;
+
+ ///
+ /// Report any kind of . This method is called by
+ /// the default exception handler generated for a rule method.
+ ///
+ /// the parser instance
+ /// the recognition exception to report
+ virtual void reportError(Parser *recognizer, const RecognitionException &e) = 0;
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/ANTLRFileStream.h b/lib/antlr4/include/ANTLRFileStream.h
new file mode 100644
index 0000000..10c8550
--- /dev/null
+++ b/lib/antlr4/include/ANTLRFileStream.h
@@ -0,0 +1,27 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "ANTLRInputStream.h"
+
+namespace antlr4 {
+
+ /// This is an ANTLRInputStream that is loaded from a file all at once
+ /// when you construct the object (or call load()).
+ // TODO: this class needs testing.
+ class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream {
+ protected:
+ std::string _fileName; // UTF-8 encoded file name.
+
+ public:
+ // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM).
+ ANTLRFileStream(const std::string &fileName);
+
+ virtual void loadFromFile(const std::string &fileName);
+ virtual std::string getSourceName() const override;
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/ANTLRInputStream.h b/lib/antlr4/include/ANTLRInputStream.h
new file mode 100644
index 0000000..e985050
--- /dev/null
+++ b/lib/antlr4/include/ANTLRInputStream.h
@@ -0,0 +1,69 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "CharStream.h"
+
+namespace antlr4 {
+
+ // Vacuum all input from a stream and then treat it
+ // like a string. Can also pass in a string or char[] to use.
+ // Input is expected to be encoded in UTF-8 and converted to UTF-32 internally.
+ class ANTLR4CPP_PUBLIC ANTLRInputStream : public CharStream {
+ protected:
+ /// The data being scanned.
+ // UTF-32
+ UTF32String _data;
+
+ /// 0..n-1 index into string of next char
+ size_t p;
+
+ public:
+ /// What is name or source of this char stream?
+ std::string name;
+
+ ANTLRInputStream(const std::string &input = "");
+ ANTLRInputStream(const char data_[], size_t numberOfActualCharsInArray);
+ ANTLRInputStream(std::istream &stream);
+
+ virtual void load(const std::string &input);
+ virtual void load(std::istream &stream);
+
+ /// Reset the stream so that it's in the same state it was
+ /// when the object was created *except* the data array is not
+ /// touched.
+ virtual void reset();
+ virtual void consume() override;
+ virtual size_t LA(ssize_t i) override;
+ virtual size_t LT(ssize_t i);
+
+ ///
+ /// Return the current input symbol index 0..n where n indicates the
+ /// last symbol has been read. The index is the index of char to
+ /// be returned from LA(1).
+ ///
+ virtual size_t index() override;
+ virtual size_t size() override;
+
+ ///
+ /// mark/release do nothing; we have entire buffer
+ virtual ssize_t mark() override;
+ virtual void release(ssize_t marker) override;
+
+ ///
+ /// consume() ahead until p==index; can't just set p=index as we must
+ /// update line and charPositionInLine. If we seek backwards, just set p
+ ///
+ virtual void seek(size_t index) override;
+ virtual std::string getText(const misc::Interval &interval) override;
+ virtual std::string getSourceName() const override;
+ virtual std::string toString() const override;
+
+ private:
+ void InitializeInstanceFields();
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/BailErrorStrategy.h b/lib/antlr4/include/BailErrorStrategy.h
new file mode 100644
index 0000000..2a8c36f
--- /dev/null
+++ b/lib/antlr4/include/BailErrorStrategy.h
@@ -0,0 +1,59 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "DefaultErrorStrategy.h"
+
+namespace antlr4 {
+
+ /**
+ * This implementation of {@link ANTLRErrorStrategy} responds to syntax errors
+ * by immediately canceling the parse operation with a
+ * {@link ParseCancellationException}. The implementation ensures that the
+ * {@link ParserRuleContext#exception} field is set for all parse tree nodes
+ * that were not completed prior to encountering the error.
+ *
+ *
+ * This error strategy is useful in the following scenarios.
+ *
+ *
+ * - Two-stage parsing: This error strategy allows the first
+ * stage of two-stage parsing to immediately terminate if an error is
+ * encountered, and immediately fall back to the second stage. In addition to
+ * avoiding wasted work by attempting to recover from errors here, the empty
+ * implementation of {@link BailErrorStrategy#sync} improves the performance of
+ * the first stage.
+ * - Silent validation: When syntax errors are not being
+ * reported or logged, and the parse result is simply ignored if errors occur,
+ * the {@link BailErrorStrategy} avoids wasting work on recovering from errors
+ * when the result will be ignored either way.
+ *
+ *
+ *
+ * {@code myparser.setErrorHandler(new BailErrorStrategy());}
+ *
+ * @see Parser#setErrorHandler(ANTLRErrorStrategy)
+ */
+ class ANTLR4CPP_PUBLIC BailErrorStrategy : public DefaultErrorStrategy {
+ ///
+ /// Instead of recovering from exception {@code e}, re-throw it wrapped
+ /// in a so it is not caught by the
+ /// rule function catches. Use to get the
+ /// original .
+ ///
+ public:
+ virtual void recover(Parser *recognizer, std::exception_ptr e) override;
+
+ /// Make sure we don't attempt to recover inline; if the parser
+ /// successfully recovers, it won't throw an exception.
+ virtual Token* recoverInline(Parser *recognizer) override;
+
+ ///
+ /// Make sure we don't attempt to recover from problems in subrules.
+ virtual void sync(Parser *recognizer) override;
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/BaseErrorListener.h b/lib/antlr4/include/BaseErrorListener.h
new file mode 100644
index 0000000..aad2e5d
--- /dev/null
+++ b/lib/antlr4/include/BaseErrorListener.h
@@ -0,0 +1,36 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "ANTLRErrorListener.h"
+
+namespace antlrcpp {
+ class BitSet;
+}
+
+namespace antlr4 {
+
+ /**
+ * Provides an empty default implementation of {@link ANTLRErrorListener}. The
+ * default implementation of each method does nothing, but can be overridden as
+ * necessary.
+ */
+ class ANTLR4CPP_PUBLIC BaseErrorListener : public ANTLRErrorListener {
+
+ virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine,
+ const std::string &msg, std::exception_ptr e) override;
+
+ virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
+ const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override;
+
+ virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
+ const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override;
+
+ virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
+ size_t prediction, atn::ATNConfigSet *configs) override;
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/BufferedTokenStream.h b/lib/antlr4/include/BufferedTokenStream.h
new file mode 100644
index 0000000..fab74d2
--- /dev/null
+++ b/lib/antlr4/include/BufferedTokenStream.h
@@ -0,0 +1,200 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "TokenStream.h"
+
+namespace antlr4 {
+
+ /**
+ * This implementation of {@link TokenStream} loads tokens from a
+ * {@link TokenSource} on-demand, and places the tokens in a buffer to provide
+ * access to any previous token by index.
+ *
+ *
+ * This token stream ignores the value of {@link Token#getChannel}. If your
+ * parser requires the token stream filter tokens to only those on a particular
+ * channel, such as {@link Token#DEFAULT_CHANNEL} or
+ * {@link Token#HIDDEN_CHANNEL}, use a filtering token stream such a
+ * {@link CommonTokenStream}.
+ */
+ class ANTLR4CPP_PUBLIC BufferedTokenStream : public TokenStream {
+ public:
+ BufferedTokenStream(TokenSource *tokenSource);
+ BufferedTokenStream(const BufferedTokenStream& other) = delete;
+
+ BufferedTokenStream& operator = (const BufferedTokenStream& other) = delete;
+
+ virtual TokenSource* getTokenSource() const override;
+ virtual size_t index() override;
+ virtual ssize_t mark() override;
+
+ virtual void release(ssize_t marker) override;
+ virtual void reset();
+ virtual void seek(size_t index) override;
+
+ virtual size_t size() override;
+ virtual void consume() override;
+
+ virtual Token* get(size_t i) const override;
+
+ /// Get all tokens from start..stop inclusively.
+ virtual std::vector get(size_t start, size_t stop);
+
+ virtual size_t LA(ssize_t i) override;
+ virtual Token* LT(ssize_t k) override;
+
+ /// Reset this token stream by setting its token source.
+ virtual void setTokenSource(TokenSource *tokenSource);
+ virtual std::vector getTokens();
+ virtual std::vector getTokens(size_t start, size_t stop);
+
+ ///
+ /// Given a start and stop index, return a List of all tokens in
+ /// the token type BitSet. Return null if no tokens were found. This
+ /// method looks at both on and off channel tokens.
+ ///
+ virtual std::vector getTokens(size_t start, size_t stop, const std::vector &types);
+ virtual std::vector getTokens(size_t start, size_t stop, size_t ttype);
+
+ /// Collect all tokens on specified channel to the right of
+ /// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL or
+ /// EOF. If channel is -1, find any non default channel token.
+ virtual std::vector getHiddenTokensToRight(size_t tokenIndex, ssize_t channel);
+
+ ///
+ /// Collect all hidden tokens (any off-default channel) to the right of
+ /// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL
+ /// or EOF.
+ ///
+ virtual std::vector getHiddenTokensToRight(size_t tokenIndex);
+
+ ///
+ /// Collect all tokens on specified channel to the left of
+ /// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
+ /// If channel is -1, find any non default channel token.
+ ///
+ virtual std::vector getHiddenTokensToLeft(size_t tokenIndex, ssize_t channel);
+
+ ///
+ /// Collect all hidden tokens (any off-default channel) to the left of
+ /// the current token up until we see a token on DEFAULT_TOKEN_CHANNEL.
+ ///
+ virtual std::vector getHiddenTokensToLeft(size_t tokenIndex);
+
+ virtual std::string getSourceName() const override;
+ virtual std::string getText() override;
+ virtual std::string getText(const misc::Interval &interval) override;
+ virtual std::string getText(RuleContext *ctx) override;
+ virtual std::string getText(Token *start, Token *stop) override;
+
+ /// Get all tokens from lexer until EOF.
+ virtual void fill();
+
+ protected:
+ /**
+ * The {@link TokenSource} from which tokens for this stream are fetched.
+ */
+ TokenSource *_tokenSource;
+
+ /**
+ * A collection of all tokens fetched from the token source. The list is
+ * considered a complete view of the input once {@link #fetchedEOF} is set
+ * to {@code true}.
+ */
+ std::vector> _tokens;
+
+ /**
+ * The index into {@link #tokens} of the current token (next token to
+ * {@link #consume}). {@link #tokens}{@code [}{@link #p}{@code ]} should be
+ * {@link #LT LT(1)}.
+ *
+ * This field is set to -1 when the stream is first constructed or when
+ * {@link #setTokenSource} is called, indicating that the first token has
+ * not yet been fetched from the token source. For additional information,
+ * see the documentation of {@link IntStream} for a description of
+ * Initializing Methods.
+ */
+ // ml: since -1 requires to make this member signed for just this single aspect we use a member _needSetup instead.
+ // Use bool isInitialized() to find out if this stream has started reading.
+ size_t _p;
+
+ /**
+ * Indicates whether the {@link Token#EOF} token has been fetched from
+ * {@link #tokenSource} and added to {@link #tokens}. This field improves
+ * performance for the following cases:
+ *
+ *
+ * - {@link #consume}: The lookahead check in {@link #consume} to prevent
+ * consuming the EOF symbol is optimized by checking the values of
+ * {@link #fetchedEOF} and {@link #p} instead of calling {@link #LA}.
+ * - {@link #fetch}: The check to prevent adding multiple EOF symbols into
+ * {@link #tokens} is trivial with this field.
+ *
+ /// If {@code ctx.getSourceInterval()} does not return a valid interval of
+ /// tokens provided by this stream, the behavior is unspecified.
+ ///
+ ///
+ /// TokenStream stream = ...;
+ /// String text = stream.getText(ctx.getSourceInterval());
+ ///
+ ///
+ /// The context providing the source interval of tokens to get
+ /// text for.
+ /// The text of all tokens within the source interval of {@code ctx}.
+ virtual std::string getText(RuleContext *ctx) = 0;
+
+ ///
+ /// Return the text of all tokens in this stream between {@code start} and
+ /// {@code stop} (inclusive).
+ ///
+ /// If the specified {@code start} or {@code stop} token was not provided by
+ /// this stream, or if the {@code stop} occurred before the {@code start}
+ /// token, the behavior is unspecified.
+ ///
+ /// For streams which ensure that the method is
+ /// accurate for all of its provided tokens, this method behaves like the
+ /// following code. Other streams may implement this method in other ways
+ /// provided the behavior is consistent with this at a high level.
+ ///
+ ///
+ /// TokenStream stream = ...;
+ /// String text = "";
+ /// for (int i = start.getTokenIndex(); i <= stop.getTokenIndex(); i++) {
+ /// text += stream.get(i).getText();
+ /// }
+ ///
+ ///
+ /// The first token in the interval to get text for.
+ /// The last token in the interval to get text for (inclusive).
+ /// The text of all tokens lying between the specified {@code start}
+ /// and {@code stop} tokens.
+ ///
+ /// if this stream does not support
+ /// this method for the specified tokens
+ virtual std::string getText(Token *start, Token *stop) = 0;
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/TokenStreamRewriter.h b/lib/antlr4/include/TokenStreamRewriter.h
new file mode 100644
index 0000000..102a9e9
--- /dev/null
+++ b/lib/antlr4/include/TokenStreamRewriter.h
@@ -0,0 +1,293 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+namespace antlr4 {
+
+ /**
+ * Useful for rewriting out a buffered input token stream after doing some
+ * augmentation or other manipulations on it.
+ *
+ *
+ * You can insert stuff, replace, and delete chunks. Note that the operations
+ * are done lazily--only if you convert the buffer to a {@link String} with
+ * {@link TokenStream#getText()}. This is very efficient because you are not
+ * moving data around all the time. As the buffer of tokens is converted to
+ * strings, the {@link #getText()} method(s) scan the input token stream and
+ * check to see if there is an operation at the current index. If so, the
+ * operation is done and then normal {@link String} rendering continues on the
+ * buffer. This is like having multiple Turing machine instruction streams
+ * (programs) operating on a single input tape. :)
+ *
+ *
+ * This rewriter makes no modifications to the token stream. It does not ask the
+ * stream to fill itself up nor does it advance the input cursor. The token
+ * stream {@link TokenStream#index()} will return the same value before and
+ * after any {@link #getText()} call.
+ *
+ *
+ * The rewriter only works on tokens that you have in the buffer and ignores the
+ * current input cursor. If you are buffering tokens on-demand, calling
+ * {@link #getText()} halfway through the input will only do rewrites for those
+ * tokens in the first half of the file.
+ *
+ *
+ * Since the operations are done lazily at {@link #getText}-time, operations do
+ * not screw up the token index values. That is, an insert operation at token
+ * index {@code i} does not change the index values for tokens
+ * {@code i}+1..n-1.
+ *
+ *
+ * Because operations never actually alter the buffer, you may always get the
+ * original token stream back without undoing anything. Since the instructions
+ * are queued up, you can easily simulate transactions and roll back any changes
+ * if there is an error just by removing instructions. For example,
+ *
+ *
+ * CharStream input = new ANTLRFileStream("input");
+ * TLexer lex = new TLexer(input);
+ * CommonTokenStream tokens = new CommonTokenStream(lex);
+ * T parser = new T(tokens);
+ * TokenStreamRewriter rewriter = new TokenStreamRewriter(tokens);
+ * parser.startRule();
+ *
+ *
+ *
+ * Then in the rules, you can execute (assuming rewriter is visible):
+ *
+ *
+ * Token t,u;
+ * ...
+ * rewriter.insertAfter(t, "text to put after t");}
+ * rewriter.insertAfter(u, "text after u");}
+ * System.out.println(rewriter.getText());
+ *
+ *
+ *
+ * You can also have multiple "instruction streams" and get multiple rewrites
+ * from a single pass over the input. Just name the instruction streams and use
+ * that name again when printing the buffer. This could be useful for generating
+ * a C file and also its header file--all from the same buffer:
+ *
+ *
+ * rewriter.insertAfter("pass1", t, "text to put after t");}
+ * rewriter.insertAfter("pass2", u, "text after u");}
+ * System.out.println(rewriter.getText("pass1"));
+ * System.out.println(rewriter.getText("pass2"));
+ *
+ *
+ *
+ * If you don't use named rewrite streams, a "default" stream is used as the
+ * first example shows.
+ */
+ class ANTLR4CPP_PUBLIC TokenStreamRewriter {
+ public:
+ static const std::string DEFAULT_PROGRAM_NAME;
+ static const size_t PROGRAM_INIT_SIZE = 100;
+ static const size_t MIN_TOKEN_INDEX = 0;
+
+ TokenStreamRewriter(TokenStream *tokens);
+ virtual ~TokenStreamRewriter();
+
+ TokenStream *getTokenStream();
+
+ virtual void rollback(size_t instructionIndex);
+
+ /// Rollback the instruction stream for a program so that
+ /// the indicated instruction (via instructionIndex) is no
+ /// longer in the stream. UNTESTED!
+ virtual void rollback(const std::string &programName, size_t instructionIndex);
+
+ virtual void deleteProgram();
+
+ /// Reset the program so that no instructions exist.
+ virtual void deleteProgram(const std::string &programName);
+ virtual void insertAfter(Token *t, const std::string& text);
+ virtual void insertAfter(size_t index, const std::string& text);
+ virtual void insertAfter(const std::string &programName, Token *t, const std::string& text);
+ virtual void insertAfter(const std::string &programName, size_t index, const std::string& text);
+
+ virtual void insertBefore(Token *t, const std::string& text);
+ virtual void insertBefore(size_t index, const std::string& text);
+ virtual void insertBefore(const std::string &programName, Token *t, const std::string& text);
+ virtual void insertBefore(const std::string &programName, size_t index, const std::string& text);
+
+ virtual void replace(size_t index, const std::string& text);
+ virtual void replace(size_t from, size_t to, const std::string& text);
+ virtual void replace(Token *indexT, const std::string& text);
+ virtual void replace(Token *from, Token *to, const std::string& text);
+ virtual void replace(const std::string &programName, size_t from, size_t to, const std::string& text);
+ virtual void replace(const std::string &programName, Token *from, Token *to, const std::string& text);
+
+ virtual void Delete(size_t index);
+ virtual void Delete(size_t from, size_t to);
+ virtual void Delete(Token *indexT);
+ virtual void Delete(Token *from, Token *to);
+ virtual void Delete(const std::string &programName, size_t from, size_t to);
+ virtual void Delete(const std::string &programName, Token *from, Token *to);
+
+ virtual size_t getLastRewriteTokenIndex();
+
+ /// Return the text from the original tokens altered per the
+ /// instructions given to this rewriter.
+ virtual std::string getText();
+
+ /** Return the text from the original tokens altered per the
+ * instructions given to this rewriter in programName.
+ */
+ std::string getText(std::string programName);
+
+ /// Return the text associated with the tokens in the interval from the
+ /// original token stream but with the alterations given to this rewriter.
+ /// The interval refers to the indexes in the original token stream.
+ /// We do not alter the token stream in any way, so the indexes
+ /// and intervals are still consistent. Includes any operations done
+ /// to the first and last token in the interval. So, if you did an
+ /// insertBefore on the first token, you would get that insertion.
+ /// The same is true if you do an insertAfter the stop token.
+ virtual std::string getText(const misc::Interval &interval);
+
+ virtual std::string getText(const std::string &programName, const misc::Interval &interval);
+
+ protected:
+ class RewriteOperation {
+ public:
+ /// What index into rewrites List are we?
+ size_t index;
+ std::string text;
+
+ /// Token buffer index.
+ size_t instructionIndex;
+
+ RewriteOperation(TokenStreamRewriter *outerInstance, size_t index);
+ RewriteOperation(TokenStreamRewriter *outerInstance, size_t index, const std::string& text);
+ virtual ~RewriteOperation();
+
+ /// Execute the rewrite operation by possibly adding to the buffer.
+ /// Return the index of the next token to operate on.
+
+ virtual size_t execute(std::string *buf);
+ virtual std::string toString();
+
+ private:
+ TokenStreamRewriter *const outerInstance;
+ void InitializeInstanceFields();
+ };
+
+ class InsertBeforeOp : public RewriteOperation {
+ private:
+ TokenStreamRewriter *const outerInstance;
+
+ public:
+ InsertBeforeOp(TokenStreamRewriter *outerInstance, size_t index, const std::string& text);
+
+ virtual size_t execute(std::string *buf) override;
+ };
+
+ class ReplaceOp : public RewriteOperation {
+ private:
+ TokenStreamRewriter *const outerInstance;
+
+ public:
+ size_t lastIndex;
+
+ ReplaceOp(TokenStreamRewriter *outerInstance, size_t from, size_t to, const std::string& text);
+ virtual size_t execute(std::string *buf) override;
+ virtual std::string toString() override;
+
+ private:
+ void InitializeInstanceFields();
+ };
+
+ /// Our source stream
+ TokenStream *const tokens;
+
+ /// You may have multiple, named streams of rewrite operations.
+ /// I'm calling these things "programs."
+ /// Maps String (name) -> rewrite (List)
+ std::map> _programs;
+
+ ///
+ /// Map String (program name) -> Integer index
+ std::map _lastRewriteTokenIndexes;
+ virtual size_t getLastRewriteTokenIndex(const std::string &programName);
+ virtual void setLastRewriteTokenIndex(const std::string &programName, size_t i);
+ virtual std::vector& getProgram(const std::string &name);
+
+ ///
+ /// We need to combine operations and report invalid operations (like
+ /// overlapping replaces that are not completed nested). Inserts to
+ /// same index need to be combined etc... Here are the cases:
+ ///
+ /// I.i.u I.j.v leave alone, nonoverlapping
+ /// I.i.u I.i.v combine: Iivu
+ ///
+ /// R.i-j.u R.x-y.v | i-j in x-y delete first R
+ /// R.i-j.u R.i-j.v delete first R
+ /// R.i-j.u R.x-y.v | x-y in i-j ERROR
+ /// R.i-j.u R.x-y.v | boundaries overlap ERROR
+ ///
+ /// Delete special case of replace (text==null):
+ /// D.i-j.u D.x-y.v | boundaries overlap combine to max(min)..max(right)
+ ///
+ /// I.i.u R.x-y.v | i in (x+1)-y delete I (since insert before
+ /// we're not deleting i)
+ /// I.i.u R.x-y.v | i not in (x+1)-y leave alone, nonoverlapping
+ /// R.x-y.v I.i.u | i in x-y ERROR
+ /// R.x-y.v I.x.u R.x-y.uv (combine, delete I)
+ /// R.x-y.v I.i.u | i not in x-y leave alone, nonoverlapping
+ ///
+ /// I.i.u = insert u before op @ index i
+ /// R.x-y.u = replace x-y indexed tokens with u
+ ///
+ /// First we need to examine replaces. For any replace op:
+ ///
+ /// 1. wipe out any insertions before op within that range.
+ /// 2. Drop any replace op before that is contained completely within
+ /// that range.
+ /// 3. Throw exception upon boundary overlap with any previous replace.
+ ///
+ /// Then we can deal with inserts:
+ ///
+ /// 1. for any inserts to same index, combine even if not adjacent.
+ /// 2. for any prior replace with same left boundary, combine this
+ /// insert with replace and delete this replace.
+ /// 3. throw exception if index in same range as previous replace
+ ///
+ /// Don't actually delete; make op null in list. Easier to walk list.
+ /// Later we can throw as we add to index -> op map.
+ ///
+ /// Note that I.2 R.2-2 will wipe out I.2 even though, technically, the
+ /// inserted stuff would be before the replace range. But, if you
+ /// add tokens in front of a method body '{' and then delete the method
+ /// body, I think the stuff before the '{' you added should disappear too.
+ ///
+ /// Return a map from token index to operation.
+ ///
+ virtual std::unordered_map reduceToSingleOperationPerIndex(std::vector &rewrites);
+
+ virtual std::string catOpText(std::string *a, std::string *b);
+
+ /// Get all operations before an index of a particular kind.
+ template
+ std::vector getKindOfOps(std::vector rewrites, size_t before) {
+ std::vector ops;
+ for (size_t i = 0; i < before && i < rewrites.size(); i++) {
+ T *op = dynamic_cast(rewrites[i]);
+ if (op == nullptr) { // ignore deleted or non matching entries
+ continue;
+ }
+ ops.push_back(op);
+ }
+ return ops;
+ }
+
+ private:
+ std::vector& initializeProgram(const std::string &name);
+
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/UnbufferedCharStream.h b/lib/antlr4/include/UnbufferedCharStream.h
new file mode 100644
index 0000000..98cdcc6
--- /dev/null
+++ b/lib/antlr4/include/UnbufferedCharStream.h
@@ -0,0 +1,123 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "CharStream.h"
+
+namespace antlr4 {
+
+ /// Do not buffer up the entire char stream. It does keep a small buffer
+ /// for efficiency and also buffers while a mark exists (set by the
+ /// lookahead prediction in parser). "Unbuffered" here refers to fact
+ /// that it doesn't buffer all data, not that's it's on demand loading of char.
+ class ANTLR4CPP_PUBLIC UnbufferedCharStream : public CharStream {
+ public:
+ /// The name or source of this char stream.
+ std::string name;
+
+ UnbufferedCharStream(std::wistream &input);
+
+ virtual void consume() override;
+ virtual size_t LA(ssize_t i) override;
+
+ ///
+ /// Return a marker that we can release later.
+ ///
+ /// The specific marker value used for this class allows for some level of
+ /// protection against misuse where {@code seek()} is called on a mark or
+ /// {@code release()} is called in the wrong order.
+ ///
+ virtual ssize_t mark() override;
+
+ ///
+ /// Decrement number of markers, resetting buffer if we hit 0.
+ ///
+ virtual void release(ssize_t marker) override;
+ virtual size_t index() override;
+
+ ///
+ /// Seek to absolute character index, which might not be in the current
+ /// sliding window. Move {@code p} to {@code index-bufferStartIndex}.
+ ///
+ virtual void seek(size_t index) override;
+ virtual size_t size() override;
+ virtual std::string getSourceName() const override;
+ virtual std::string getText(const misc::Interval &interval) override;
+
+ protected:
+ /// A moving window buffer of the data being scanned. While there's a marker,
+ /// we keep adding to buffer. Otherwise, resets so
+ /// we start filling at index 0 again.
+ // UTF-32 encoded.
+#if defined(_MSC_VER) && _MSC_VER == 1900
+ i32string _data; // Custom type for VS 2015.
+ typedef __int32 storage_type;
+#else
+ std::u32string _data;
+ typedef char32_t storage_type;
+#endif
+
+ ///
+ /// 0..n-1 index into of next character.
+ ///
+ /// The {@code LA(1)} character is {@code data[p]}. If {@code p == n}, we are
+ /// out of buffered characters.
+ ///
+ size_t _p;
+
+ ///
+ /// Count up with and down with
+ /// . When we {@code release()} the last mark,
+ /// {@code numMarkers} reaches 0 and we reset the buffer. Copy
+ /// {@code data[p]..data[n-1]} to {@code data[0]..data[(n-1)-p]}.
+ ///
+ size_t _numMarkers;
+
+ /// This is the {@code LA(-1)} character for the current position.
+ size_t _lastChar; // UTF-32
+
+ ///
+ /// When {@code numMarkers > 0}, this is the {@code LA(-1)} character for the
+ /// first character in . Otherwise, this is unspecified.
+ ///
+ size_t _lastCharBufferStart; // UTF-32
+
+ ///
+ /// Absolute character index. It's the index of the character about to be
+ /// read via {@code LA(1)}. Goes from 0 to the number of characters in the
+ /// entire stream, although the stream size is unknown before the end is
+ /// reached.
+ ///
+ size_t _currentCharIndex;
+
+ std::wistream &_input;
+
+ ///
+ /// Make sure we have 'want' elements from current position .
+ /// Last valid {@code p} index is {@code data.length-1}. {@code p+need-1} is
+ /// the char index 'need' elements ahead. If we need 1 element,
+ /// {@code (p+1-1)==p} must be less than {@code data.length}.
+ ///
+ virtual void sync(size_t want);
+
+ ///
+ /// Add {@code n} characters to the buffer. Returns the number of characters
+ /// actually added to the buffer. If the return value is less than {@code n},
+ /// then EOF was reached before {@code n} characters could be added.
+ ///
+ virtual size_t fill(size_t n);
+
+ /// Override to provide different source of characters than
+ /// .
+ virtual char32_t nextChar();
+ virtual void add(char32_t c);
+ size_t getBufferStartIndex() const;
+
+ private:
+ void InitializeInstanceFields();
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/UnbufferedTokenStream.h b/lib/antlr4/include/UnbufferedTokenStream.h
new file mode 100644
index 0000000..244cc8d
--- /dev/null
+++ b/lib/antlr4/include/UnbufferedTokenStream.h
@@ -0,0 +1,115 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "TokenStream.h"
+
+namespace antlr4 {
+
+ class ANTLR4CPP_PUBLIC UnbufferedTokenStream : public TokenStream {
+ public:
+ UnbufferedTokenStream(TokenSource *tokenSource);
+ UnbufferedTokenStream(TokenSource *tokenSource, int bufferSize);
+ UnbufferedTokenStream(const UnbufferedTokenStream& other) = delete;
+ virtual ~UnbufferedTokenStream();
+
+ UnbufferedTokenStream& operator = (const UnbufferedTokenStream& other) = delete;
+
+ virtual Token* get(size_t i) const override;
+ virtual Token* LT(ssize_t i) override;
+ virtual size_t LA(ssize_t i) override;
+
+ virtual TokenSource* getTokenSource() const override;
+
+ virtual std::string getText(const misc::Interval &interval) override;
+ virtual std::string getText() override;
+ virtual std::string getText(RuleContext *ctx) override;
+ virtual std::string getText(Token *start, Token *stop) override;
+
+ virtual void consume() override;
+
+ ///
+ /// Return a marker that we can release later.
+ ///
+ /// The specific marker value used for this class allows for some level of
+ /// protection against misuse where {@code seek()} is called on a mark or
+ /// {@code release()} is called in the wrong order.
+ ///
+ virtual ssize_t mark() override;
+ virtual void release(ssize_t marker) override;
+ virtual size_t index() override;
+ virtual void seek(size_t index) override;
+ virtual size_t size() override;
+ virtual std::string getSourceName() const override;
+
+ protected:
+ /// Make sure we have 'need' elements from current position p. Last valid
+ /// p index is tokens.length - 1. p + need - 1 is the tokens index 'need' elements
+ /// ahead. If we need 1 element, (p+1-1)==p must be less than tokens.length.
+ TokenSource *_tokenSource;
+
+ ///
+ /// A moving window buffer of the data being scanned. While there's a marker,
+ /// we keep adding to buffer. Otherwise, resets so
+ /// we start filling at index 0 again.
+ ///
+
+ std::vector> _tokens;
+
+ ///
+ /// 0..n-1 index into of next token.
+ ///
+ /// The {@code LT(1)} token is {@code tokens[p]}. If {@code p == n}, we are
+ /// out of buffered tokens.
+ ///
+ size_t _p;
+
+ ///
+ /// Count up with and down with
+ /// . When we {@code release()} the last mark,
+ /// {@code numMarkers} reaches 0 and we reset the buffer. Copy
+ /// {@code tokens[p]..tokens[n-1]} to {@code tokens[0]..tokens[(n-1)-p]}.
+ ///
+ int _numMarkers;
+
+ ///
+ /// This is the {@code LT(-1)} token for the current position.
+ ///
+ Token *_lastToken;
+
+ ///
+ /// When {@code numMarkers > 0}, this is the {@code LT(-1)} token for the
+ /// first token in . Otherwise, this is {@code null}.
+ ///
+ Token *_lastTokenBufferStart;
+
+ ///
+ /// Absolute token index. It's the index of the token about to be read via
+ /// {@code LT(1)}. Goes from 0 to the number of tokens in the entire stream,
+ /// although the stream size is unknown before the end is reached.
+ ///
+ /// This value is used to set the token indexes if the stream provides tokens
+ /// that implement .
+ ///
+ size_t _currentTokenIndex;
+
+ virtual void sync(ssize_t want);
+
+ ///
+ /// Add {@code n} elements to the buffer. Returns the number of tokens
+ /// actually added to the buffer. If the return value is less than {@code n},
+ /// then EOF was reached before {@code n} tokens could be added.
+ ///
+ virtual size_t fill(size_t n);
+ virtual void add(std::unique_ptr t);
+
+ size_t getBufferStartIndex() const;
+
+ private:
+ void InitializeInstanceFields();
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/Vocabulary.h b/lib/antlr4/include/Vocabulary.h
new file mode 100644
index 0000000..7dbf85c
--- /dev/null
+++ b/lib/antlr4/include/Vocabulary.h
@@ -0,0 +1,193 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "antlr4-common.h"
+
+namespace antlr4 {
+namespace dfa {
+
+ /// This class provides a default implementation of the
+ /// interface.
+ class ANTLR4CPP_PUBLIC Vocabulary {
+ public:
+ Vocabulary(Vocabulary const&) = default;
+ virtual ~Vocabulary();
+
+ /// Gets an empty instance.
+ ///
+ ///
+ /// No literal or symbol names are assigned to token types, so
+ /// returns the numeric value for all tokens
+ /// except .
+ static const Vocabulary EMPTY_VOCABULARY;
+
+ Vocabulary() {}
+
+ ///
+ /// Constructs a new instance of from the specified
+ /// literal and symbolic token names.
+ ///
+ /// The literal names assigned to tokens, or {@code null}
+ /// if no literal names are assigned.
+ /// The symbolic names assigned to tokens, or
+ /// {@code null} if no symbolic names are assigned.
+ ///
+ ///
+ ///
+ Vocabulary(const std::vector &literalNames, const std::vector &symbolicNames);
+
+ ///
+ /// Constructs a new instance of from the specified
+ /// literal, symbolic, and display token names.
+ ///
+ /// The literal names assigned to tokens, or {@code null}
+ /// if no literal names are assigned.
+ /// The symbolic names assigned to tokens, or
+ /// {@code null} if no symbolic names are assigned.
+ /// The display names assigned to tokens, or {@code null}
+ /// to use the values in {@code literalNames} and {@code symbolicNames} as
+ /// the source of display names, as described in
+ /// .
+ ///
+ ///
+ ///
+ ///
+ Vocabulary(const std::vector &literalNames, const std::vector &symbolicNames,
+ const std::vector &displayNames);
+
+ ///
+ /// Returns a instance from the specified set of token
+ /// names. This method acts as a compatibility layer for the single
+ /// {@code tokenNames} array generated by previous releases of ANTLR.
+ ///
+ /// The resulting vocabulary instance returns {@code null} for
+ /// and , and the
+ /// value from {@code tokenNames} for the display names.
+ ///
+ /// The token names, or {@code null} if no token names are
+ /// available.
+ /// A instance which uses {@code tokenNames} for
+ /// the display names of tokens.
+ static Vocabulary fromTokenNames(const std::vector &tokenNames);
+
+ ///
+ /// Returns the highest token type value. It can be used to iterate from
+ /// zero to that number, inclusively, thus querying all stored entries.
+ /// the highest token type value
+ virtual size_t getMaxTokenType() const;
+
+ ///
+ /// Gets the string literal associated with a token type. The string returned
+ /// by this method, when not {@code null}, can be used unaltered in a parser
+ /// grammar to represent this token type.
+ ///
+ /// The following table shows examples of lexer rules and the literal
+ /// names assigned to the corresponding token types.
+ ///
+ ///
+ ///
+ /// Rule |
+ /// Literal Name |
+ /// Java String Literal |
+ ///
+ ///
+ /// {@code THIS : 'this';} |
+ /// {@code 'this'} |
+ /// {@code "'this'"} |
+ ///
+ ///
+ /// {@code SQUOTE : '\'';} |
+ /// {@code '\''} |
+ /// {@code "'\\''"} |
+ ///
+ ///
+ /// {@code ID : [A-Z]+;} |
+ /// n/a |
+ /// {@code null} |
+ ///
+ ///
+ ///
+ /// The token type.
+ ///
+ /// The string literal associated with the specified token type, or
+ /// {@code null} if no string literal is associated with the type.
+ virtual std::string getLiteralName(size_t tokenType) const;
+
+ ///
+ /// Gets the symbolic name associated with a token type. The string returned
+ /// by this method, when not {@code null}, can be used unaltered in a parser
+ /// grammar to represent this token type.
+ ///
+ /// This method supports token types defined by any of the following
+ /// methods:
+ ///
+ ///
+ /// - Tokens created by lexer rules.
+ /// - Tokens defined in a
tokens{}
block in a lexer or parser
+ /// grammar.
+ /// - The implicitly defined {@code EOF} token, which has the token type
+ /// .
+ ///
+ ///
+ /// The following table shows examples of lexer rules and the literal
+ /// names assigned to the corresponding token types.
+ ///
+ ///
+ ///
+ /// Rule |
+ /// Symbolic Name |
+ ///
+ ///
+ /// {@code THIS : 'this';} |
+ /// {@code THIS} |
+ ///
+ ///
+ /// {@code SQUOTE : '\'';} |
+ /// {@code SQUOTE} |
+ ///
+ ///
+ /// {@code ID : [A-Z]+;} |
+ /// {@code ID} |
+ ///
+ ///
+ ///
+ /// The token type.
+ ///
+ /// The symbolic name associated with the specified token type, or
+ /// {@code null} if no symbolic name is associated with the type.
+ virtual std::string getSymbolicName(size_t tokenType) const;
+
+ ///
+ /// Gets the display name of a token type.
+ ///
+ /// ANTLR provides a default implementation of this method, but
+ /// applications are free to override the behavior in any manner which makes
+ /// sense for the application. The default implementation returns the first
+ /// result from the following list which produces a non-{@code null}
+ /// result.
+ ///
+ ///
+ /// - The result of
+ /// - The result of
+ /// - The result of
+ ///
+ ///
+ /// The token type.
+ ///
+ /// The display name of the token type, for use in error reporting or
+ /// other user-visible messages which reference specific token types.
+ virtual std::string getDisplayName(size_t tokenType) const;
+
+ private:
+ std::vector const _literalNames;
+ std::vector const _symbolicNames;
+ std::vector const _displayNames;
+ const size_t _maxTokenType = 0;
+ };
+
+} // namespace atn
+} // namespace antlr4
diff --git a/lib/antlr4/include/WritableToken.h b/lib/antlr4/include/WritableToken.h
new file mode 100644
index 0000000..56bc9d0
--- /dev/null
+++ b/lib/antlr4/include/WritableToken.h
@@ -0,0 +1,23 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include "Token.h"
+
+namespace antlr4 {
+
+ class ANTLR4CPP_PUBLIC WritableToken : public Token {
+ public:
+ virtual ~WritableToken();
+ virtual void setText(const std::string &text) = 0;
+ virtual void setType(size_t ttype) = 0;
+ virtual void setLine(size_t line) = 0;
+ virtual void setCharPositionInLine(size_t pos) = 0;
+ virtual void setChannel(size_t channel) = 0;
+ virtual void setTokenIndex(size_t index) = 0;
+ };
+
+} // namespace antlr4
diff --git a/lib/antlr4/include/antlr4-common.h b/lib/antlr4/include/antlr4-common.h
new file mode 100644
index 0000000..25d890b
--- /dev/null
+++ b/lib/antlr4/include/antlr4-common.h
@@ -0,0 +1,137 @@
+/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
+ * Use of this file is governed by the BSD 3-clause license that
+ * can be found in the LICENSE.txt file in the project root.
+ */
+
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include