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: + /// + /// + /// + /// 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: + * + *