├── .gitignore ├── .gitmodules ├── README.md ├── SConscript.py ├── SConstruct ├── antlr4-runtime ├── ANTLRErrorListener.cpp ├── ANTLRErrorListener.h ├── ANTLRErrorStrategy.cpp ├── ANTLRErrorStrategy.h ├── ANTLRFileStream.cpp ├── ANTLRFileStream.h ├── ANTLRInputStream.cpp ├── ANTLRInputStream.h ├── BailErrorStrategy.cpp ├── BailErrorStrategy.h ├── BaseErrorListener.cpp ├── BaseErrorListener.h ├── BufferedTokenStream.cpp ├── BufferedTokenStream.h ├── CharStream.cpp ├── CharStream.h ├── CommonToken.cpp ├── CommonToken.h ├── CommonTokenFactory.cpp ├── CommonTokenFactory.h ├── CommonTokenStream.cpp ├── CommonTokenStream.h ├── ConsoleErrorListener.cpp ├── ConsoleErrorListener.h ├── DefaultErrorStrategy.cpp ├── DefaultErrorStrategy.h ├── DiagnosticErrorListener.cpp ├── DiagnosticErrorListener.h ├── Exceptions.cpp ├── Exceptions.h ├── FailedPredicateException.cpp ├── FailedPredicateException.h ├── InputMismatchException.cpp ├── InputMismatchException.h ├── IntStream.cpp ├── IntStream.h ├── InterpreterRuleContext.cpp ├── InterpreterRuleContext.h ├── Lexer.cpp ├── Lexer.h ├── LexerInterpreter.cpp ├── LexerInterpreter.h ├── LexerNoViableAltException.cpp ├── LexerNoViableAltException.h ├── ListTokenSource.cpp ├── ListTokenSource.h ├── NoViableAltException.cpp ├── NoViableAltException.h ├── Parser.cpp ├── Parser.h ├── ParserInterpreter.cpp ├── ParserInterpreter.h ├── ParserRuleContext.cpp ├── ParserRuleContext.h ├── ProxyErrorListener.cpp ├── ProxyErrorListener.h ├── RecognitionException.cpp ├── RecognitionException.h ├── Recognizer.cpp ├── Recognizer.h ├── RuleContext.cpp ├── RuleContext.h ├── RuleContextWithAltNum.cpp ├── RuleContextWithAltNum.h ├── RuntimeMetaData.cpp ├── RuntimeMetaData.h ├── Token.cpp ├── Token.h ├── TokenFactory.h ├── TokenSource.cpp ├── TokenSource.h ├── TokenStream.cpp ├── TokenStream.h ├── TokenStreamRewriter.cpp ├── TokenStreamRewriter.h ├── UnbufferedCharStream.cpp ├── UnbufferedCharStream.h ├── UnbufferedTokenStream.cpp ├── UnbufferedTokenStream.h ├── Vocabulary.cpp ├── Vocabulary.h ├── WritableToken.cpp ├── WritableToken.h ├── antlr4-common.h ├── antlr4-runtime.h ├── atn │ ├── ATN.cpp │ ├── ATN.h │ ├── ATNConfig.cpp │ ├── ATNConfig.h │ ├── ATNConfigSet.cpp │ ├── ATNConfigSet.h │ ├── ATNDeserializationOptions.cpp │ ├── ATNDeserializationOptions.h │ ├── ATNDeserializer.cpp │ ├── ATNDeserializer.h │ ├── ATNSerializer.cpp │ ├── ATNSerializer.h │ ├── ATNSimulator.cpp │ ├── ATNSimulator.h │ ├── ATNState.cpp │ ├── ATNState.h │ ├── ATNType.h │ ├── AbstractPredicateTransition.cpp │ ├── AbstractPredicateTransition.h │ ├── ActionTransition.cpp │ ├── ActionTransition.h │ ├── AmbiguityInfo.cpp │ ├── AmbiguityInfo.h │ ├── ArrayPredictionContext.cpp │ ├── ArrayPredictionContext.h │ ├── AtomTransition.cpp │ ├── AtomTransition.h │ ├── BasicBlockStartState.cpp │ ├── BasicBlockStartState.h │ ├── BasicState.cpp │ ├── BasicState.h │ ├── BlockEndState.cpp │ ├── BlockEndState.h │ ├── BlockStartState.cpp │ ├── BlockStartState.h │ ├── ContextSensitivityInfo.cpp │ ├── ContextSensitivityInfo.h │ ├── DecisionEventInfo.cpp │ ├── DecisionEventInfo.h │ ├── DecisionInfo.cpp │ ├── DecisionInfo.h │ ├── DecisionState.cpp │ ├── DecisionState.h │ ├── EmptyPredictionContext.cpp │ ├── EmptyPredictionContext.h │ ├── EpsilonTransition.cpp │ ├── EpsilonTransition.h │ ├── ErrorInfo.cpp │ ├── ErrorInfo.h │ ├── LL1Analyzer.cpp │ ├── LL1Analyzer.h │ ├── LexerATNConfig.cpp │ ├── LexerATNConfig.h │ ├── LexerATNSimulator.cpp │ ├── LexerATNSimulator.h │ ├── LexerAction.cpp │ ├── LexerAction.h │ ├── LexerActionExecutor.cpp │ ├── LexerActionExecutor.h │ ├── LexerActionType.h │ ├── LexerChannelAction.cpp │ ├── LexerChannelAction.h │ ├── LexerCustomAction.cpp │ ├── LexerCustomAction.h │ ├── LexerIndexedCustomAction.cpp │ ├── LexerIndexedCustomAction.h │ ├── LexerModeAction.cpp │ ├── LexerModeAction.h │ ├── LexerMoreAction.cpp │ ├── LexerMoreAction.h │ ├── LexerPopModeAction.cpp │ ├── LexerPopModeAction.h │ ├── LexerPushModeAction.cpp │ ├── LexerPushModeAction.h │ ├── LexerSkipAction.cpp │ ├── LexerSkipAction.h │ ├── LexerTypeAction.cpp │ ├── LexerTypeAction.h │ ├── LookaheadEventInfo.cpp │ ├── LookaheadEventInfo.h │ ├── LoopEndState.cpp │ ├── LoopEndState.h │ ├── Makefile │ ├── NotSetTransition.cpp │ ├── NotSetTransition.h │ ├── OrderedATNConfigSet.cpp │ ├── OrderedATNConfigSet.h │ ├── ParseInfo.cpp │ ├── ParseInfo.h │ ├── ParserATNSimulator.cpp │ ├── ParserATNSimulator.h │ ├── PlusBlockStartState.cpp │ ├── PlusBlockStartState.h │ ├── PlusLoopbackState.cpp │ ├── PlusLoopbackState.h │ ├── PrecedencePredicateTransition.cpp │ ├── PrecedencePredicateTransition.h │ ├── PredicateEvalInfo.cpp │ ├── PredicateEvalInfo.h │ ├── PredicateTransition.cpp │ ├── PredicateTransition.h │ ├── PredictionContext.cpp │ ├── PredictionContext.h │ ├── PredictionMode.cpp │ ├── PredictionMode.h │ ├── ProfilingATNSimulator.cpp │ ├── ProfilingATNSimulator.h │ ├── RangeTransition.cpp │ ├── RangeTransition.h │ ├── RuleStartState.cpp │ ├── RuleStartState.h │ ├── RuleStopState.cpp │ ├── RuleStopState.h │ ├── RuleTransition.cpp │ ├── RuleTransition.h │ ├── SemanticContext.cpp │ ├── SemanticContext.h │ ├── SetTransition.cpp │ ├── SetTransition.h │ ├── SingletonPredictionContext.cpp │ ├── SingletonPredictionContext.h │ ├── StarBlockStartState.cpp │ ├── StarBlockStartState.h │ ├── StarLoopEntryState.cpp │ ├── StarLoopEntryState.h │ ├── StarLoopbackState.cpp │ ├── StarLoopbackState.h │ ├── TokensStartState.cpp │ ├── TokensStartState.h │ ├── Transition.cpp │ ├── Transition.h │ ├── WildcardTransition.cpp │ └── WildcardTransition.h ├── dfa │ ├── DFA.cpp │ ├── DFA.h │ ├── DFASerializer.cpp │ ├── DFASerializer.h │ ├── DFAState.cpp │ ├── DFAState.h │ ├── LexerDFASerializer.cpp │ └── LexerDFASerializer.h ├── misc │ ├── InterpreterDataReader.cpp │ ├── InterpreterDataReader.h │ ├── Interval.cpp │ ├── Interval.h │ ├── IntervalSet.cpp │ ├── IntervalSet.h │ ├── MurmurHash.cpp │ ├── MurmurHash.h │ ├── Predicate.cpp │ └── Predicate.h ├── support │ ├── Any.cpp │ ├── Any.h │ ├── Arrays.cpp │ ├── Arrays.h │ ├── BitSet.h │ ├── CPPUtils.cpp │ ├── CPPUtils.h │ ├── Declarations.h │ ├── StringUtils.cpp │ ├── StringUtils.h │ ├── guid.cpp │ └── guid.h └── tree │ ├── AbstractParseTreeVisitor.h │ ├── ErrorNode.cpp │ ├── ErrorNode.h │ ├── ErrorNodeImpl.cpp │ ├── ErrorNodeImpl.h │ ├── IterativeParseTreeWalker.cpp │ ├── IterativeParseTreeWalker.h │ ├── ParseTree.cpp │ ├── ParseTree.h │ ├── ParseTreeListener.cpp │ ├── ParseTreeListener.h │ ├── ParseTreeProperty.h │ ├── ParseTreeVisitor.cpp │ ├── ParseTreeVisitor.h │ ├── ParseTreeWalker.cpp │ ├── ParseTreeWalker.h │ ├── TerminalNode.cpp │ ├── TerminalNode.h │ ├── TerminalNodeImpl.cpp │ ├── TerminalNodeImpl.h │ ├── Trees.cpp │ ├── Trees.h │ ├── pattern │ ├── Chunk.cpp │ ├── Chunk.h │ ├── ParseTreeMatch.cpp │ ├── ParseTreeMatch.h │ ├── ParseTreePattern.cpp │ ├── ParseTreePattern.h │ ├── ParseTreePatternMatcher.cpp │ ├── ParseTreePatternMatcher.h │ ├── RuleTagToken.cpp │ ├── RuleTagToken.h │ ├── TagChunk.cpp │ ├── TagChunk.h │ ├── TextChunk.cpp │ ├── TextChunk.h │ ├── TokenTagToken.cpp │ └── TokenTagToken.h │ └── xpath │ ├── XPath.cpp │ ├── XPath.h │ ├── XPathElement.cpp │ ├── XPathElement.h │ ├── XPathLexer.cpp │ ├── XPathLexer.g4 │ ├── XPathLexer.h │ ├── XPathLexer.tokens │ ├── XPathLexerErrorListener.cpp │ ├── XPathLexerErrorListener.h │ ├── XPathRuleAnywhereElement.cpp │ ├── XPathRuleAnywhereElement.h │ ├── XPathRuleElement.cpp │ ├── XPathRuleElement.h │ ├── XPathTokenAnywhereElement.cpp │ ├── XPathTokenAnywhereElement.h │ ├── XPathTokenElement.cpp │ ├── XPathTokenElement.h │ ├── XPathWildcardAnywhereElement.cpp │ ├── XPathWildcardAnywhereElement.h │ ├── XPathWildcardElement.cpp │ └── XPathWildcardElement.h ├── grammars └── Cmm.g4 ├── libs ├── PascalRTL.jar ├── antlr-4.7-complete.jar └── libantlr-runtime.a ├── outputs ├── correct_100.PNG ├── s.class └── s.j ├── samples └── s.c ├── scripts ├── assemble.sh ├── build.sh ├── compile.sh └── recompile_runtime.sh ├── src ├── backend │ ├── common │ │ ├── JasminEmitter.cpp │ │ ├── JasminEmitter.hpp │ │ ├── PassVisitor.cpp │ │ ├── PassVisitor.hpp │ │ ├── TypeSpecifier.cpp │ │ └── TypeSpecifier.hpp │ ├── pass1 │ │ ├── Pass1Visitor.cpp │ │ ├── Pass1Visitor.hpp │ │ ├── pass1_visitor_common.cpp │ │ ├── pass1_visitor_declarations.cpp │ │ ├── pass1_visitor_expressions.cpp │ │ ├── pass1_visitor_functions.cpp │ │ └── pass1_visitor_statements.cpp │ └── pass2 │ │ ├── Pass2Visitor.cpp │ │ ├── Pass2Visitor.hpp │ │ ├── pass2_visitor_common.cpp │ │ ├── pass2_visitor_declarations.cpp │ │ ├── pass2_visitor_expressions.cpp │ │ ├── pass2_visitor_functions.cpp │ │ └── pass2_visitor_statements.cpp ├── common │ ├── CustomException.hpp │ └── common.hpp ├── intermediate │ ├── Symbol.hpp │ ├── SymbolStore.hpp │ ├── SymbolTable.hpp │ ├── SymbolTableStack.hpp │ └── src │ │ ├── SymbolTable.cpp │ │ └── SymbolTableStack.cpp ├── main.cpp └── utils │ ├── ConstObject.hpp │ ├── FormatStringParser.hpp │ ├── TypeResolver.cpp │ ├── TypeResolver.hpp │ └── logger.hpp ├── tools └── jasmin-assembler │ ├── build.bat │ ├── build.sh │ ├── build.xml │ ├── jasmin.jar │ ├── lib │ ├── ant-launcher.jar │ ├── ant.jar │ ├── jas │ │ ├── JASMIN_NOTES.txt │ │ ├── README.txt │ │ ├── examples │ │ │ ├── README │ │ │ ├── exprcomp.jas │ │ │ ├── exprcomp.java │ │ │ ├── hworld.jas │ │ │ ├── hworld.java │ │ │ ├── simple.jas │ │ │ ├── simple.java │ │ │ └── test.inp │ │ └── tests │ │ │ ├── README │ │ │ ├── all.jas │ │ │ ├── all.java │ │ │ ├── regress.class │ │ │ └── scmregress.class │ ├── java_cup.jar │ └── java_cup │ │ ├── INSTALL │ │ ├── JASMIN_NOTES.txt │ │ ├── README.txt │ │ ├── Thumbs.db │ │ ├── java_cup.logo.new.gif │ │ ├── manual.html │ │ └── simple_calc │ │ ├── Main.java │ │ ├── parser.cup │ │ ├── parser.java │ │ ├── scanner.java │ │ └── sym.java │ ├── makefile │ └── src │ ├── Jasmin.java │ ├── jas │ ├── AnnotDefAttr.java │ ├── AnnotParamAttr.java │ ├── Annotation.java │ ├── AnnotationAttr.java │ ├── AnnotationElement.java │ ├── AsciiCP.java │ ├── CP.java │ ├── CatchEntry.java │ ├── Catchtable.java │ ├── ClassCP.java │ ├── ClassEnv.java │ ├── CodeAttr.java │ ├── ConstAttr.java │ ├── DeprecatedAttr.java │ ├── DoubleCP.java │ ├── EnclosingMethodAttr.java │ ├── ExceptAttr.java │ ├── FieldCP.java │ ├── FloatCP.java │ ├── GenericAttr.java │ ├── IincInsn.java │ ├── InnerClass.java │ ├── InnerClassesAttr.java │ ├── Insn.java │ ├── InsnOperand.java │ ├── IntegerCP.java │ ├── InterfaceCP.java │ ├── InvokeinterfaceInsn.java │ ├── Label.java │ ├── LabelOrOffset.java │ ├── LineTableAttr.java │ ├── LocalVarEntry.java │ ├── LocalVarTableAttr.java │ ├── LocalVarTypeTableAttr.java │ ├── LongCP.java │ ├── LookupswitchInsn.java │ ├── Method.java │ ├── MethodCP.java │ ├── MultiarrayInsn.java │ ├── NameTypeCP.java │ ├── RuntimeConstants.java │ ├── SignatureAttr.java │ ├── SourceAttr.java │ ├── SourceDebugExtensionAttr.java │ ├── StackMap.java │ ├── StringCP.java │ ├── TableswitchInsn.java │ ├── Var.java │ ├── VerificationTypeInfo.java │ ├── VerifyFrame.java │ └── jasError.java │ ├── jasmin.mf │ ├── jasmin │ ├── ClassFile.java │ ├── InsnInfo.java │ ├── Main.java │ ├── ReservedWords.java │ ├── Scanner.java │ ├── ScannerUtils.java │ ├── num_token.java │ ├── parser.cup │ ├── parser.java │ ├── relative_num_token.java │ ├── sym.java │ └── var_token.java │ ├── java_cup.mf │ └── java_cup │ ├── Main.java │ ├── action_part.java │ ├── action_production.java │ ├── emit.java │ ├── internal_error.java │ ├── lalr_item.java │ ├── lalr_item_set.java │ ├── lalr_state.java │ ├── lalr_transition.java │ ├── lexer.java │ ├── lr_item_core.java │ ├── non_terminal.java │ ├── parse_action.java │ ├── parse_action_row.java │ ├── parse_action_table.java │ ├── parse_reduce_row.java │ ├── parse_reduce_table.java │ ├── parser.cup │ ├── parser.java │ ├── production.java │ ├── production_part.java │ ├── reduce_action.java │ ├── runtime │ ├── char_token.java │ ├── double_token.java │ ├── float_token.java │ ├── int_token.java │ ├── long_token.java │ ├── lr_parser.java │ ├── str_token.java │ ├── symbol.java │ ├── token.java │ └── virtual_parse_stack.java │ ├── shift_action.java │ ├── sym.java │ ├── symbol.java │ ├── symbol_part.java │ ├── symbol_set.java │ ├── terminal.java │ ├── terminal_set.java │ └── version.java └── unused ├── CrossReferencer.cpp ├── CrossReferencer.h ├── Logger.cpp ├── ParseTreePrinter.cpp ├── ParseTreePrinter.h ├── TypeChecker.cpp ├── TypeChecker.h └── wci ├── DataValue.h └── intermediate ├── ICode.h ├── ICodeFactory.cpp ├── ICodeFactory.h ├── ICodeNode.h ├── SymTab.h ├── SymTabEntry.h ├── SymTabFactory.cpp ├── SymTabFactory.h ├── SymTabStack.h ├── TypeFactory.cpp ├── TypeFactory.h ├── TypeSpec.cpp ├── TypeSpec.h ├── icodeimpl ├── ICodeImpl.cpp ├── ICodeImpl.h ├── ICodeNodeImpl.cpp └── ICodeNodeImpl.h ├── symtabimpl ├── Predefined.cpp ├── Predefined.h ├── SymTabEntryImpl.cpp ├── SymTabEntryImpl.h ├── SymTabImpl.cpp ├── SymTabImpl.h ├── SymTabStackImpl.cpp └── SymTabStackImpl.h └── typeimpl ├── TypeSpecImpl.cpp └── TypeSpecImpl.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | 3 | *.dblite 4 | 5 | *.exe 6 | 7 | generated/* 8 | 9 | build/* 10 | 11 | pickle/antlr4-runtime/temp/* 12 | 13 | pickle/generated/* 14 | 15 | .sconsign.dblite 16 | 17 | # Jasmin files in root directory 18 | /*.j -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tools/Krakatau"] 2 | path = tools/Krakatau 3 | url = https://github.com/Storyyeller/Krakatau.git 4 | [submodule "src/modules/spdlog"] 5 | path = src/modules/spdlog 6 | url = https://github.com/gabime/spdlog.git 7 | -------------------------------------------------------------------------------- /antlr4-runtime/ANTLRErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorListener.h" 7 | 8 | antlr4::ANTLRErrorListener::~ANTLRErrorListener() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /antlr4-runtime/ANTLRErrorStrategy.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ANTLRErrorStrategy.h" 7 | 8 | antlr4::ANTLRErrorStrategy::~ANTLRErrorStrategy() 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /antlr4-runtime/ANTLRFileStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | #include "ANTLRFileStream.h" 9 | 10 | using namespace antlr4; 11 | 12 | ANTLRFileStream::ANTLRFileStream(const std::string &fileName) { 13 | _fileName = fileName; 14 | loadFromFile(fileName); 15 | } 16 | 17 | void ANTLRFileStream::loadFromFile(const std::string &fileName) { 18 | _fileName = fileName; 19 | if (_fileName.empty()) { 20 | return; 21 | } 22 | 23 | #ifdef _MSC_VER 24 | std::ifstream stream(antlrcpp::s2ws(fileName), std::ios::binary); 25 | #else 26 | std::ifstream stream(fileName, std::ios::binary); 27 | #endif 28 | 29 | ANTLRInputStream::load(stream); 30 | } 31 | 32 | std::string ANTLRFileStream::getSourceName() const { 33 | return _fileName; 34 | } 35 | -------------------------------------------------------------------------------- /antlr4-runtime/ANTLRFileStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRInputStream.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// This is an ANTLRInputStream that is loaded from a file all at once 13 | /// when you construct the object (or call load()). 14 | // TODO: this class needs testing. 15 | class ANTLR4CPP_PUBLIC ANTLRFileStream : public ANTLRInputStream { 16 | protected: 17 | std::string _fileName; // UTF-8 encoded file name. 18 | 19 | public: 20 | // Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM). 21 | ANTLRFileStream(const std::string &fileName); 22 | 23 | virtual void loadFromFile(const std::string &fileName); 24 | virtual std::string getSourceName() const override; 25 | }; 26 | 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /antlr4-runtime/BaseErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BaseErrorListener.h" 7 | #include "RecognitionException.h" 8 | 9 | using namespace antlr4; 10 | 11 | void BaseErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, size_t /*line*/, 12 | size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | 15 | void BaseErrorListener::reportAmbiguity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 16 | size_t /*stopIndex*/, bool /*exact*/, const antlrcpp::BitSet &/*ambigAlts*/, atn::ATNConfigSet * /*configs*/) { 17 | } 18 | 19 | void BaseErrorListener::reportAttemptingFullContext(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 20 | size_t /*stopIndex*/, const antlrcpp::BitSet &/*conflictingAlts*/, atn::ATNConfigSet * /*configs*/) { 21 | } 22 | 23 | void BaseErrorListener::reportContextSensitivity(Parser * /*recognizer*/, const dfa::DFA &/*dfa*/, size_t /*startIndex*/, 24 | size_t /*stopIndex*/, size_t /*prediction*/, atn::ATNConfigSet * /*configs*/) { 25 | } 26 | -------------------------------------------------------------------------------- /antlr4-runtime/BaseErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ANTLRErrorListener.h" 9 | 10 | namespace antlrcpp { 11 | class BitSet; 12 | } 13 | 14 | namespace antlr4 { 15 | 16 | /** 17 | * Provides an empty default implementation of {@link ANTLRErrorListener}. The 18 | * default implementation of each method does nothing, but can be overridden as 19 | * necessary. 20 | */ 21 | class ANTLR4CPP_PUBLIC BaseErrorListener : public ANTLRErrorListener { 22 | 23 | virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine, 24 | const std::string &msg, std::exception_ptr e) override; 25 | 26 | virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact, 27 | const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override; 28 | 29 | virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 30 | const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override; 31 | 32 | virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, 33 | size_t prediction, atn::ATNConfigSet *configs) override; 34 | }; 35 | 36 | } // namespace antlr4 37 | -------------------------------------------------------------------------------- /antlr4-runtime/CharStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "CharStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | CharStream::~CharStream() { 11 | } 12 | -------------------------------------------------------------------------------- /antlr4-runtime/CharStream.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "IntStream.h" 9 | #include "misc/Interval.h" 10 | 11 | namespace antlr4 { 12 | 13 | /// A source of characters for an ANTLR lexer. 14 | class ANTLR4CPP_PUBLIC CharStream : public IntStream { 15 | public: 16 | virtual ~CharStream(); 17 | 18 | /// This method returns the text for a range of characters within this input 19 | /// stream. This method is guaranteed to not throw an exception if the 20 | /// specified interval lies entirely within a marked range. For more 21 | /// information about marked ranges, see IntStream::mark. 22 | /// 23 | /// an interval within the stream 24 | /// the text of the specified interval 25 | /// 26 | /// if {@code interval} is {@code null} 27 | /// if {@code interval.a < 0}, or if 28 | /// {@code interval.b < interval.a - 1}, or if {@code interval.b} lies at or 29 | /// past the end of the stream 30 | /// if the stream does not support 31 | /// getting the text of the specified interval 32 | virtual std::string getText(const misc::Interval &interval) = 0; 33 | 34 | virtual std::string toString() const = 0; 35 | }; 36 | 37 | } // namespace antlr4 38 | -------------------------------------------------------------------------------- /antlr4-runtime/CommonTokenFactory.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "CommonToken.h" 8 | #include "CharStream.h" 9 | 10 | #include "CommonTokenFactory.h" 11 | 12 | using namespace antlr4; 13 | 14 | const Ref> CommonTokenFactory::DEFAULT = std::make_shared(); 15 | 16 | CommonTokenFactory::CommonTokenFactory(bool copyText_) : copyText(copyText_) { 17 | } 18 | 19 | CommonTokenFactory::CommonTokenFactory() : CommonTokenFactory(false) { 20 | } 21 | 22 | std::unique_ptr CommonTokenFactory::create(std::pair source, size_t type, 23 | const std::string &text, size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) { 24 | 25 | std::unique_ptr t(new CommonToken(source, type, channel, start, stop)); 26 | t->setLine(line); 27 | t->setCharPositionInLine(charPositionInLine); 28 | if (text != "") { 29 | t->setText(text); 30 | } else if (copyText && source.second != nullptr) { 31 | t->setText(source.second->getText(misc::Interval(start, stop))); 32 | } 33 | 34 | return t; 35 | } 36 | 37 | std::unique_ptr CommonTokenFactory::create(size_t type, const std::string &text) { 38 | return std::unique_ptr(new CommonToken(type, text)); 39 | } 40 | -------------------------------------------------------------------------------- /antlr4-runtime/ConsoleErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ConsoleErrorListener.h" 7 | 8 | using namespace antlr4; 9 | 10 | ConsoleErrorListener ConsoleErrorListener::INSTANCE; 11 | 12 | void ConsoleErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 13 | size_t line, size_t charPositionInLine, const std::string &msg, std::exception_ptr /*e*/) { 14 | std::cerr << "line " << line << ":" << charPositionInLine << " " << msg << std::endl; 15 | } 16 | -------------------------------------------------------------------------------- /antlr4-runtime/ConsoleErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC ConsoleErrorListener : public BaseErrorListener { 13 | public: 14 | /** 15 | * Provides a default instance of {@link ConsoleErrorListener}. 16 | */ 17 | static ConsoleErrorListener INSTANCE; 18 | 19 | /** 20 | * {@inheritDoc} 21 | * 22 | *

23 | * This implementation prints messages to {@link System#err} containing the 24 | * values of {@code line}, {@code charPositionInLine}, and {@code msg} using 25 | * the following format.

26 | * 27 | *
28 |      * line line:charPositionInLine msg
29 |      * 
30 | */ 31 | virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine, 32 | const std::string &msg, std::exception_ptr e) override; 33 | }; 34 | 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /antlr4-runtime/FailedPredicateException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A semantic predicate failed during validation. Validation of predicates 13 | /// occurs when normally parsing the alternative just like matching a token. 14 | /// Disambiguating predicate evaluation occurs when we test a predicate during 15 | /// prediction. 16 | class ANTLR4CPP_PUBLIC FailedPredicateException : public RecognitionException { 17 | public: 18 | FailedPredicateException(Parser *recognizer); 19 | FailedPredicateException(Parser *recognizer, const std::string &predicate); 20 | FailedPredicateException(Parser *recognizer, const std::string &predicate, const std::string &message); 21 | 22 | virtual size_t getRuleIndex(); 23 | virtual size_t getPredIndex(); 24 | virtual std::string getPredicate(); 25 | 26 | private: 27 | size_t _ruleIndex; 28 | size_t _predicateIndex; 29 | std::string _predicate; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /antlr4-runtime/InputMismatchException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "InputMismatchException.h" 9 | 10 | using namespace antlr4; 11 | 12 | InputMismatchException::InputMismatchException(Parser *recognizer) 13 | : RecognitionException(recognizer, recognizer->getInputStream(), recognizer->getContext(), 14 | recognizer->getCurrentToken()) { 15 | } 16 | 17 | InputMismatchException::~InputMismatchException() { 18 | } 19 | -------------------------------------------------------------------------------- /antlr4-runtime/InputMismatchException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// 13 | /// This signifies any kind of mismatched input exceptions such as 14 | /// when the current input does not match the expected token. 15 | /// 16 | class ANTLR4CPP_PUBLIC InputMismatchException : public RecognitionException { 17 | public: 18 | InputMismatchException(Parser *recognizer); 19 | InputMismatchException(InputMismatchException const&) = default; 20 | ~InputMismatchException(); 21 | InputMismatchException& operator=(InputMismatchException const&) = default; 22 | }; 23 | 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /antlr4-runtime/IntStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "IntStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | const std::string IntStream::UNKNOWN_SOURCE_NAME = ""; 11 | 12 | IntStream::~IntStream() = default; 13 | -------------------------------------------------------------------------------- /antlr4-runtime/InterpreterRuleContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "InterpreterRuleContext.h" 7 | 8 | using namespace antlr4; 9 | 10 | InterpreterRuleContext::InterpreterRuleContext() : ParserRuleContext() { 11 | } 12 | 13 | InterpreterRuleContext::InterpreterRuleContext(ParserRuleContext *parent, size_t invokingStateNumber, size_t ruleIndex) 14 | : ParserRuleContext(parent, invokingStateNumber), _ruleIndex(ruleIndex) { 15 | } 16 | 17 | size_t InterpreterRuleContext::getRuleIndex() const { 18 | return _ruleIndex; 19 | } 20 | -------------------------------------------------------------------------------- /antlr4-runtime/LexerNoViableAltException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "support/CPPUtils.h" 8 | #include "CharStream.h" 9 | #include "Lexer.h" 10 | 11 | #include "LexerNoViableAltException.h" 12 | 13 | using namespace antlr4; 14 | 15 | LexerNoViableAltException::LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs) 17 | : RecognitionException(lexer, input, nullptr, nullptr), _startIndex(startIndex), _deadEndConfigs(deadEndConfigs) { 18 | } 19 | 20 | size_t LexerNoViableAltException::getStartIndex() { 21 | return _startIndex; 22 | } 23 | 24 | atn::ATNConfigSet* LexerNoViableAltException::getDeadEndConfigs() { 25 | return _deadEndConfigs; 26 | } 27 | 28 | std::string LexerNoViableAltException::toString() { 29 | std::string symbol; 30 | if (_startIndex < getInputStream()->size()) { 31 | symbol = static_cast(getInputStream())->getText(misc::Interval(_startIndex, _startIndex)); 32 | symbol = antlrcpp::escapeWhitespace(symbol, false); 33 | } 34 | std::string format = "LexerNoViableAltException('" + symbol + "')"; 35 | return format; 36 | } 37 | -------------------------------------------------------------------------------- /antlr4-runtime/LexerNoViableAltException.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "RecognitionException.h" 9 | #include "atn/ATNConfigSet.h" 10 | 11 | namespace antlr4 { 12 | 13 | class ANTLR4CPP_PUBLIC LexerNoViableAltException : public RecognitionException { 14 | public: 15 | LexerNoViableAltException(Lexer *lexer, CharStream *input, size_t startIndex, 16 | atn::ATNConfigSet *deadEndConfigs); 17 | 18 | virtual size_t getStartIndex(); 19 | virtual atn::ATNConfigSet* getDeadEndConfigs(); 20 | virtual std::string toString(); 21 | 22 | private: 23 | /// Matching attempted at what input index? 24 | const size_t _startIndex; 25 | 26 | /// Which configurations did we try at input.index() that couldn't match input.LA(1)? 27 | atn::ATNConfigSet *_deadEndConfigs; 28 | 29 | }; 30 | 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /antlr4-runtime/NoViableAltException.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Parser.h" 7 | 8 | #include "NoViableAltException.h" 9 | 10 | using namespace antlr4; 11 | 12 | NoViableAltException::NoViableAltException(Parser *recognizer) 13 | : NoViableAltException(recognizer, recognizer->getTokenStream(), recognizer->getCurrentToken(), 14 | recognizer->getCurrentToken(), nullptr, recognizer->getContext()) { 15 | } 16 | 17 | NoViableAltException::NoViableAltException(Parser *recognizer, TokenStream *input,Token *startToken, 18 | Token *offendingToken, atn::ATNConfigSet *deadEndConfigs, ParserRuleContext *ctx) 19 | : RecognitionException("No viable alternative", recognizer, input, ctx, offendingToken), _deadEndConfigs(deadEndConfigs), _startToken(startToken) { 20 | } 21 | 22 | Token* NoViableAltException::getStartToken() const { 23 | return _startToken; 24 | } 25 | 26 | atn::ATNConfigSet* NoViableAltException::getDeadEndConfigs() const { 27 | return _deadEndConfigs; 28 | } 29 | -------------------------------------------------------------------------------- /antlr4-runtime/RuleContextWithAltNum.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATN.h" 7 | 8 | #include "RuleContextWithAltNum.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RuleContextWithAltNum::RuleContextWithAltNum() : ParserRuleContext() { 14 | altNum = ATN::INVALID_ALT_NUMBER; 15 | } 16 | 17 | RuleContextWithAltNum::RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber) 18 | : ParserRuleContext(parent, invokingStateNumber) { 19 | } 20 | 21 | size_t RuleContextWithAltNum::getAltNumber() const { 22 | return altNum; 23 | } 24 | 25 | void RuleContextWithAltNum::setAltNumber(size_t number) { 26 | altNum = number; 27 | } 28 | -------------------------------------------------------------------------------- /antlr4-runtime/RuleContextWithAltNum.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "ParserRuleContext.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// A handy class for use with 13 | /// 14 | /// options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;} 15 | /// 16 | /// that provides a backing field / impl for the outer alternative number 17 | /// matched for an internal parse tree node. 18 | /// 19 | /// I'm only putting into Java runtime as I'm certain I'm the only one that 20 | /// will really every use this. 21 | class ANTLR4CPP_PUBLIC RuleContextWithAltNum : public ParserRuleContext { 22 | public: 23 | size_t altNum = 0; 24 | 25 | RuleContextWithAltNum(); 26 | RuleContextWithAltNum(ParserRuleContext *parent, int invokingStateNumber); 27 | 28 | virtual size_t getAltNumber() const override; 29 | virtual void setAltNumber(size_t altNum) override; 30 | }; 31 | 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /antlr4-runtime/Token.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | 8 | antlr4::Token::~Token() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/TokenFactory.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | 12 | /// The default mechanism for creating tokens. It's used by default in Lexer and 13 | /// the error handling strategy (to create missing tokens). Notifying the parser 14 | /// of a new factory means that it notifies it's token source and error strategy. 15 | template 16 | class ANTLR4CPP_PUBLIC TokenFactory { 17 | public: 18 | virtual ~TokenFactory() {} 19 | 20 | /// This is the method used to create tokens in the lexer and in the 21 | /// error handling strategy. If text!=null, than the start and stop positions 22 | /// are wiped to -1 in the text override is set in the CommonToken. 23 | virtual std::unique_ptr create(std::pair source, size_t type, const std::string &text, 24 | size_t channel, size_t start, size_t stop, size_t line, size_t charPositionInLine) = 0; 25 | 26 | /// Generically useful 27 | virtual std::unique_ptr create(size_t type, const std::string &text) = 0; 28 | }; 29 | 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /antlr4-runtime/TokenSource.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenSource.h" 7 | 8 | antlr4::TokenSource::~TokenSource() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/TokenStream.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "TokenStream.h" 7 | 8 | using namespace antlr4; 9 | 10 | TokenStream::~TokenStream() { 11 | } 12 | -------------------------------------------------------------------------------- /antlr4-runtime/WritableToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "WritableToken.h" 7 | 8 | antlr4::WritableToken::~WritableToken() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/WritableToken.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Token.h" 9 | 10 | namespace antlr4 { 11 | 12 | class ANTLR4CPP_PUBLIC WritableToken : public Token { 13 | public: 14 | virtual ~WritableToken(); 15 | virtual void setText(const std::string &text) = 0; 16 | virtual void setType(size_t ttype) = 0; 17 | virtual void setLine(size_t line) = 0; 18 | virtual void setCharPositionInLine(size_t pos) = 0; 19 | virtual void setChannel(size_t channel) = 0; 20 | virtual void setTokenIndex(size_t index) = 0; 21 | }; 22 | 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/ATNDeserializationOptions.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ATNDeserializationOptions { 14 | private: 15 | static ATNDeserializationOptions defaultOptions; 16 | 17 | bool readOnly; 18 | bool verifyATN; 19 | bool generateRuleBypassTransitions; 20 | 21 | public: 22 | ATNDeserializationOptions(); 23 | ATNDeserializationOptions(ATNDeserializationOptions *options); 24 | ATNDeserializationOptions(ATNDeserializationOptions const&) = default; 25 | virtual ~ATNDeserializationOptions(); 26 | ATNDeserializationOptions& operator=(ATNDeserializationOptions const&) = default; 27 | 28 | static const ATNDeserializationOptions& getDefaultOptions(); 29 | 30 | bool isReadOnly(); 31 | 32 | void makeReadOnly(); 33 | 34 | bool isVerifyATN(); 35 | 36 | void setVerifyATN(bool verify); 37 | 38 | bool isGenerateRuleBypassTransitions(); 39 | 40 | void setGenerateRuleBypassTransitions(bool generate); 41 | 42 | protected: 43 | virtual void throwIfReadOnly(); 44 | 45 | private: 46 | void InitializeInstanceFields(); 47 | }; 48 | 49 | } // namespace atn 50 | } // namespace antlr4 51 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/ATNType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Represents the type of recognizer an ATN applies to. 14 | enum class ATNType { 15 | LEXER = 0, 16 | PARSER = 1, 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/AbstractPredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AbstractPredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | AbstractPredicateTransition::AbstractPredicateTransition(ATNState *target) : Transition(target) { 11 | } 12 | 13 | AbstractPredicateTransition::~AbstractPredicateTransition() { 14 | } 15 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/AbstractPredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTState; 14 | 15 | class ANTLR4CPP_PUBLIC AbstractPredicateTransition : public Transition { 16 | 17 | public: 18 | AbstractPredicateTransition(ATNState *target); 19 | ~AbstractPredicateTransition(); 20 | 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/ActionTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ActionTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex) 11 | : Transition(target), ruleIndex(ruleIndex), actionIndex(INVALID_INDEX), isCtxDependent(false) { 12 | } 13 | 14 | ActionTransition::ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent) 15 | : Transition(target), ruleIndex(ruleIndex), actionIndex(actionIndex), isCtxDependent(isCtxDependent) { 16 | } 17 | 18 | Transition::SerializationType ActionTransition::getSerializationType() const { 19 | return ACTION; 20 | } 21 | 22 | bool ActionTransition::isEpsilon() const { 23 | return true; // we are to be ignored by analysis 'cept for predicates 24 | } 25 | 26 | bool ActionTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return false; 28 | } 29 | 30 | std::string ActionTransition::toString() const { 31 | return " ACTION " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + ", actionIndex: " + 32 | std::to_string(actionIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 33 | } 34 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/ActionTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC ActionTransition final : public Transition { 14 | public: 15 | const size_t ruleIndex; 16 | const size_t actionIndex; 17 | const bool isCtxDependent; // e.g., $i ref in action 18 | 19 | ActionTransition(ATNState *target, size_t ruleIndex); 20 | 21 | ActionTransition(ATNState *target, size_t ruleIndex, size_t actionIndex, bool isCtxDependent); 22 | 23 | virtual SerializationType getSerializationType() const override; 24 | 25 | virtual bool isEpsilon() const override; 26 | 27 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 28 | 29 | virtual std::string toString() const override; 30 | }; 31 | 32 | } // namespace atn 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/AmbiguityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/AmbiguityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | AmbiguityInfo::AmbiguityInfo(size_t decision, ATNConfigSet *configs, const antlrcpp::BitSet &ambigAlts, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->ambigAlts = ambigAlts; 16 | } 17 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/AtomTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/AtomTransition.h" 10 | 11 | using namespace antlr4::misc; 12 | using namespace antlr4::atn; 13 | 14 | AtomTransition::AtomTransition(ATNState *target, size_t label) : Transition(target), _label(label) { 15 | } 16 | 17 | Transition::SerializationType AtomTransition::getSerializationType() const { 18 | return ATOM; 19 | } 20 | 21 | IntervalSet AtomTransition::label() const { 22 | return IntervalSet::of((int)_label); 23 | } 24 | 25 | bool AtomTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 26 | return _label == symbol; 27 | } 28 | 29 | std::string AtomTransition::toString() const { 30 | return "ATOM " + Transition::toString() + " { label: " + std::to_string(_label) + " }"; 31 | } 32 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/AtomTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// TO_DO: make all transitions sets? no, should remove set edges. 14 | class ANTLR4CPP_PUBLIC AtomTransition final : public Transition { 15 | public: 16 | /// The token type or character value; or, signifies special label. 17 | const size_t _label; 18 | 19 | AtomTransition(ATNState *target, size_t label); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/BasicBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicBlockStartState::getStateType() { 11 | return BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/BasicBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | #include "atn/BlockStartState.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC BasicBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/BasicState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BasicState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t BasicState::getStateType() { 11 | return BASIC; 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/BasicState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC BasicState final : public ATNState { 14 | 15 | public: 16 | virtual size_t getStateType() override; 17 | 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/BlockEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/BlockEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | BlockEndState::BlockEndState() : startState(nullptr) { 11 | } 12 | 13 | size_t BlockEndState::getStateType() { 14 | return BLOCK_END; 15 | } 16 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/BlockEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Terminal node of a simple {@code (a|b|c)} block. 14 | class ANTLR4CPP_PUBLIC BlockEndState final : public ATNState { 15 | public: 16 | BlockStartState *startState = nullptr; 17 | 18 | BlockEndState(); 19 | 20 | virtual size_t getStateType() override; 21 | }; 22 | 23 | } // namespace atn 24 | } // namespace antlr4 25 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/BlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "BlockStartState.h" 7 | 8 | antlr4::atn::BlockStartState::~BlockStartState() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/BlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The start of a regular {@code (...)} block. 14 | class ANTLR4CPP_PUBLIC BlockStartState : public DecisionState { 15 | public: 16 | ~BlockStartState(); 17 | BlockEndState *endState = nullptr; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/ContextSensitivityInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ContextSensitivityInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | ContextSensitivityInfo::ContextSensitivityInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, 12 | size_t startIndex, size_t stopIndex) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, true) { 14 | } 15 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/DecisionEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | DecisionEventInfo::DecisionEventInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, 12 | size_t stopIndex, bool fullCtx) 13 | : decision(decision), configs(configs), input(input), startIndex(startIndex), stopIndex(stopIndex), fullCtx(fullCtx) { 14 | } 15 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/DecisionInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ErrorInfo.h" 7 | #include "atn/LookaheadEventInfo.h" 8 | 9 | #include "atn/DecisionInfo.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | DecisionInfo::DecisionInfo(size_t decision) : decision(decision) { 14 | } 15 | 16 | std::string DecisionInfo::toString() const { 17 | std::stringstream ss; 18 | 19 | ss << "{decision=" << decision << ", contextSensitivities=" << contextSensitivities.size() << ", errors="; 20 | ss << errors.size() << ", ambiguities=" << ambiguities.size() << ", SLL_lookahead=" << SLL_TotalLook; 21 | ss << ", SLL_ATNTransitions=" << SLL_ATNTransitions << ", SLL_DFATransitions=" << SLL_DFATransitions; 22 | ss << ", LL_Fallback=" << LL_Fallback << ", LL_lookahead=" << LL_TotalLook << ", LL_ATNTransitions=" << LL_ATNTransitions << '}'; 23 | 24 | return ss.str(); 25 | } 26 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/DecisionState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/DecisionState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | void DecisionState::InitializeInstanceFields() { 11 | decision = -1; 12 | nonGreedy = false; 13 | } 14 | 15 | std::string DecisionState::toString() const { 16 | return "DECISION " + ATNState::toString(); 17 | } 18 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/DecisionState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC DecisionState : public ATNState { 14 | public: 15 | int decision; 16 | bool nonGreedy; 17 | 18 | private: 19 | void InitializeInstanceFields(); 20 | 21 | public: 22 | DecisionState() { 23 | InitializeInstanceFields(); 24 | } 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/EmptyPredictionContext.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EmptyPredictionContext.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EmptyPredictionContext::EmptyPredictionContext() : SingletonPredictionContext(nullptr, EMPTY_RETURN_STATE) { 11 | } 12 | 13 | bool EmptyPredictionContext::isEmpty() const { 14 | return true; 15 | } 16 | 17 | size_t EmptyPredictionContext::size() const { 18 | return 1; 19 | } 20 | 21 | Ref EmptyPredictionContext::getParent(size_t /*index*/) const { 22 | return nullptr; 23 | } 24 | 25 | size_t EmptyPredictionContext::getReturnState(size_t /*index*/) const { 26 | return returnState; 27 | } 28 | 29 | bool EmptyPredictionContext::operator == (const PredictionContext &o) const { 30 | return this == &o; 31 | } 32 | 33 | std::string EmptyPredictionContext::toString() const { 34 | return "$"; 35 | } 36 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/EmptyPredictionContext.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SingletonPredictionContext.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EmptyPredictionContext : public SingletonPredictionContext { 14 | public: 15 | EmptyPredictionContext(); 16 | 17 | virtual bool isEmpty() const override; 18 | virtual size_t size() const override; 19 | virtual Ref getParent(size_t index) const override; 20 | virtual size_t getReturnState(size_t index) const override; 21 | virtual std::string toString() const override; 22 | 23 | virtual bool operator == (const PredictionContext &o) const override; 24 | }; 25 | 26 | } // namespace atn 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/EpsilonTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/EpsilonTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | EpsilonTransition::EpsilonTransition(ATNState *target) : EpsilonTransition(target, INVALID_INDEX) { 11 | } 12 | 13 | EpsilonTransition::EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn) 14 | : Transition(target), _outermostPrecedenceReturn(outermostPrecedenceReturn) { 15 | } 16 | 17 | size_t EpsilonTransition::outermostPrecedenceReturn() { 18 | return _outermostPrecedenceReturn; 19 | } 20 | 21 | Transition::SerializationType EpsilonTransition::getSerializationType() const { 22 | return EPSILON; 23 | } 24 | 25 | bool EpsilonTransition::isEpsilon() const { 26 | return true; 27 | } 28 | 29 | bool EpsilonTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 30 | return false; 31 | } 32 | 33 | std::string EpsilonTransition::toString() const { 34 | return "EPSILON " + Transition::toString() + " {}"; 35 | } 36 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/EpsilonTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC EpsilonTransition final : public Transition { 14 | public: 15 | EpsilonTransition(ATNState *target); 16 | EpsilonTransition(ATNState *target, size_t outermostPrecedenceReturn); 17 | 18 | /** 19 | * @return the rule index of a precedence rule for which this transition is 20 | * returning from, where the precedence value is 0; otherwise, INVALID_INDEX. 21 | * 22 | * @see ATNConfig#isPrecedenceFilterSuppressed() 23 | * @see ParserATNSimulator#applyPrecedenceFilter(ATNConfigSet) 24 | * @since 4.4.1 25 | */ 26 | size_t outermostPrecedenceReturn(); 27 | virtual SerializationType getSerializationType() const override; 28 | 29 | virtual bool isEpsilon() const override; 30 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 31 | 32 | virtual std::string toString() const override; 33 | 34 | private: 35 | const size_t _outermostPrecedenceReturn; // A rule index. 36 | }; 37 | 38 | } // namespace atn 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/ErrorInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNConfigSet.h" 7 | 8 | #include "atn/ErrorInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | ErrorInfo::ErrorInfo(size_t decision, ATNConfigSet *configs, TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 14 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 15 | } 16 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "LexerAction.h" 7 | 8 | antlr4::atn::LexerAction::~LexerAction() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerActionType.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// Represents the serialization type of a . 15 | /// 16 | /// @author Sam Harwell 17 | /// @since 4.2 18 | /// 19 | enum class LexerActionType : size_t { 20 | /// 21 | /// The type of a action. 22 | /// 23 | CHANNEL, 24 | /// 25 | /// The type of a action. 26 | /// 27 | CUSTOM, 28 | /// 29 | /// The type of a action. 30 | /// 31 | MODE, 32 | /// 33 | /// The type of a action. 34 | /// 35 | MORE, 36 | /// 37 | /// The type of a action. 38 | /// 39 | POP_MODE, 40 | /// 41 | /// The type of a action. 42 | /// 43 | PUSH_MODE, 44 | /// 45 | /// The type of a action. 46 | /// 47 | SKIP, 48 | /// 49 | /// The type of a action. 50 | /// 51 | TYPE, 52 | }; 53 | 54 | } // namespace atn 55 | } // namespace antlr4 56 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerChannelAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerChannelAction.h" 10 | 11 | using namespace antlr4::atn; 12 | using namespace antlr4::misc; 13 | 14 | LexerChannelAction::LexerChannelAction(int channel) : _channel(channel) { 15 | } 16 | 17 | int LexerChannelAction::getChannel() const { 18 | return _channel; 19 | } 20 | 21 | LexerActionType LexerChannelAction::getActionType() const { 22 | return LexerActionType::CHANNEL; 23 | } 24 | 25 | bool LexerChannelAction::isPositionDependent() const { 26 | return false; 27 | } 28 | 29 | void LexerChannelAction::execute(Lexer *lexer) { 30 | lexer->setChannel(_channel); 31 | } 32 | 33 | size_t LexerChannelAction::hashCode() const { 34 | size_t hash = MurmurHash::initialize(); 35 | hash = MurmurHash::update(hash, static_cast(getActionType())); 36 | hash = MurmurHash::update(hash, _channel); 37 | return MurmurHash::finish(hash, 2); 38 | } 39 | 40 | bool LexerChannelAction::operator == (const LexerAction &obj) const { 41 | if (&obj == this) { 42 | return true; 43 | } 44 | 45 | const LexerChannelAction *action = dynamic_cast(&obj); 46 | if (action == nullptr) { 47 | return false; 48 | } 49 | 50 | return _channel == action->_channel; 51 | } 52 | 53 | std::string LexerChannelAction::toString() const { 54 | return "channel(" + std::to_string(_channel) + ")"; 55 | } 56 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerModeAction::LexerModeAction(int mode) : _mode(mode) { 16 | } 17 | 18 | int LexerModeAction::getMode() { 19 | return _mode; 20 | } 21 | 22 | LexerActionType LexerModeAction::getActionType() const { 23 | return LexerActionType::MODE; 24 | } 25 | 26 | bool LexerModeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerModeAction::execute(Lexer *lexer) { 31 | lexer->setMode(_mode); 32 | } 33 | 34 | size_t LexerModeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _mode); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerModeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerModeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _mode == action->_mode; 52 | } 53 | 54 | std::string LexerModeAction::toString() const { 55 | return "mode(" + std::to_string(_mode) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerMoreAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerMoreAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerMoreAction::getInstance() { 16 | static Ref instance(new LexerMoreAction()); 17 | return instance; 18 | } 19 | 20 | LexerMoreAction::LexerMoreAction() { 21 | } 22 | 23 | LexerActionType LexerMoreAction::getActionType() const { 24 | return LexerActionType::MORE; 25 | } 26 | 27 | bool LexerMoreAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerMoreAction::execute(Lexer *lexer) { 32 | lexer->more(); 33 | } 34 | 35 | size_t LexerMoreAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerMoreAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerMoreAction::toString() const { 46 | return "more"; 47 | } 48 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerPopModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerPopModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerPopModeAction::getInstance() { 16 | static Ref instance(new LexerPopModeAction()); 17 | return instance; 18 | } 19 | 20 | LexerPopModeAction::LexerPopModeAction() { 21 | } 22 | 23 | LexerActionType LexerPopModeAction::getActionType() const { 24 | return LexerActionType::POP_MODE; 25 | } 26 | 27 | bool LexerPopModeAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerPopModeAction::execute(Lexer *lexer) { 32 | lexer->popMode(); 33 | } 34 | 35 | size_t LexerPopModeAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerPopModeAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerPopModeAction::toString() const { 46 | return "popMode"; 47 | } 48 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerPushModeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerPushModeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerPushModeAction::LexerPushModeAction(int mode) : _mode(mode) { 16 | } 17 | 18 | int LexerPushModeAction::getMode() const { 19 | return _mode; 20 | } 21 | 22 | LexerActionType LexerPushModeAction::getActionType() const { 23 | return LexerActionType::PUSH_MODE; 24 | } 25 | 26 | bool LexerPushModeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerPushModeAction::execute(Lexer *lexer) { 31 | lexer->pushMode(_mode); 32 | } 33 | 34 | size_t LexerPushModeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _mode); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerPushModeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerPushModeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _mode == action->_mode; 52 | } 53 | 54 | std::string LexerPushModeAction::toString() const { 55 | return "pushMode(" + std::to_string(_mode) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerSkipAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerSkipAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | const Ref LexerSkipAction::getInstance() { 16 | static Ref instance(new LexerSkipAction()); 17 | return instance; 18 | } 19 | 20 | LexerSkipAction::LexerSkipAction() { 21 | } 22 | 23 | LexerActionType LexerSkipAction::getActionType() const { 24 | return LexerActionType::SKIP; 25 | } 26 | 27 | bool LexerSkipAction::isPositionDependent() const { 28 | return false; 29 | } 30 | 31 | void LexerSkipAction::execute(Lexer *lexer) { 32 | lexer->skip(); 33 | } 34 | 35 | size_t LexerSkipAction::hashCode() const { 36 | size_t hash = MurmurHash::initialize(); 37 | hash = MurmurHash::update(hash, static_cast(getActionType())); 38 | return MurmurHash::finish(hash, 1); 39 | } 40 | 41 | bool LexerSkipAction::operator == (const LexerAction &obj) const { 42 | return &obj == this; 43 | } 44 | 45 | std::string LexerSkipAction::toString() const { 46 | return "skip"; 47 | } 48 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LexerTypeAction.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/MurmurHash.h" 7 | #include "Lexer.h" 8 | 9 | #include "atn/LexerTypeAction.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | using namespace antlr4::misc; 14 | 15 | LexerTypeAction::LexerTypeAction(int type) : _type(type) { 16 | } 17 | 18 | int LexerTypeAction::getType() const { 19 | return _type; 20 | } 21 | 22 | LexerActionType LexerTypeAction::getActionType() const { 23 | return LexerActionType::TYPE; 24 | } 25 | 26 | bool LexerTypeAction::isPositionDependent() const { 27 | return false; 28 | } 29 | 30 | void LexerTypeAction::execute(Lexer *lexer) { 31 | lexer->setType(_type); 32 | } 33 | 34 | size_t LexerTypeAction::hashCode() const { 35 | size_t hash = MurmurHash::initialize(); 36 | hash = MurmurHash::update(hash, static_cast(getActionType())); 37 | hash = MurmurHash::update(hash, _type); 38 | return MurmurHash::finish(hash, 2); 39 | } 40 | 41 | bool LexerTypeAction::operator == (const LexerAction &obj) const { 42 | if (&obj == this) { 43 | return true; 44 | } 45 | 46 | const LexerTypeAction *action = dynamic_cast(&obj); 47 | if (action == nullptr) { 48 | return false; 49 | } 50 | 51 | return _type == action->_type; 52 | } 53 | 54 | std::string LexerTypeAction::toString() const { 55 | return "type(" + std::to_string(_type) + ")"; 56 | } 57 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LookaheadEventInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LookaheadEventInfo.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::atn; 10 | 11 | LookaheadEventInfo::LookaheadEventInfo(size_t decision, ATNConfigSet *configs, size_t predictedAlt, 12 | TokenStream *input, size_t startIndex, size_t stopIndex, bool fullCtx) 13 | : DecisionEventInfo(decision, configs, input, startIndex, stopIndex, fullCtx) { 14 | 15 | this->predictedAlt = predictedAlt; 16 | } 17 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LoopEndState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/LoopEndState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t LoopEndState::getStateType() { 11 | return LOOP_END; 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/LoopEndState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Mark the end of a * or + loop. 14 | class ANTLR4CPP_PUBLIC LoopEndState final : public ATNState { 15 | public: 16 | ATNState *loopBackState = nullptr; 17 | 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/NotSetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/NotSetTransition.h" 7 | #include "atn/ATNState.h" 8 | #include "misc/IntervalSet.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | NotSetTransition::NotSetTransition(ATNState *target, const misc::IntervalSet &set) : SetTransition(target, set) { 14 | } 15 | 16 | Transition::SerializationType NotSetTransition::getSerializationType() const { 17 | return NOT_SET; 18 | } 19 | 20 | bool NotSetTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 21 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol 22 | && !SetTransition::matches(symbol, minVocabSymbol, maxVocabSymbol); 23 | } 24 | 25 | std::string NotSetTransition::toString() const { 26 | return "NOT_SET " + Transition::toString() + " { " + SetTransition::toString() + " }"; 27 | } 28 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/NotSetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/SetTransition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC NotSetTransition final : public SetTransition { 14 | public: 15 | NotSetTransition(ATNState *target, const misc::IntervalSet &set); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/OrderedATNConfigSet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/OrderedATNConfigSet.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t OrderedATNConfigSet::getHash(ATNConfig *c) { 11 | return c->hashCode(); 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/OrderedATNConfigSet.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNConfigSet.h" 9 | #include "atn/ATNConfig.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC OrderedATNConfigSet : public ATNConfigSet { 15 | protected: 16 | virtual size_t getHash(ATNConfig *c) override; 17 | }; 18 | 19 | } // namespace atn 20 | } // namespace antlr4 21 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PlusBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusBlockStartState::getStateType() { 11 | return PLUS_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PlusBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Start of {@code (A|B|...)+} loop. Technically a decision state, but 14 | /// we don't use for code generation; somebody might need it, so I'm defining 15 | /// it for completeness. In reality, the node is the 16 | /// real decision-making note for {@code A+}. 17 | class ANTLR4CPP_PUBLIC PlusBlockStartState final : public BlockStartState { 18 | public: 19 | PlusLoopbackState *loopBackState = nullptr; 20 | 21 | virtual size_t getStateType() override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PlusLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PlusLoopbackState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t PlusLoopbackState::getStateType() { 11 | return PLUS_LOOP_BACK; 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PlusLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// Decision state for {@code A+} and {@code (A|B)+}. It has two transitions: 14 | /// one to the loop back to start of the block and one to exit. 15 | class ANTLR4CPP_PUBLIC PlusLoopbackState final : public DecisionState { 16 | 17 | public: 18 | virtual size_t getStateType() override; 19 | }; 20 | 21 | } // namespace atn 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PrecedencePredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PrecedencePredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | PrecedencePredicateTransition::PrecedencePredicateTransition(ATNState *target, int precedence) 11 | : AbstractPredicateTransition(target), precedence(precedence) { 12 | } 13 | 14 | Transition::SerializationType PrecedencePredicateTransition::getSerializationType() const { 15 | return PRECEDENCE; 16 | } 17 | 18 | bool PrecedencePredicateTransition::isEpsilon() const { 19 | return true; 20 | } 21 | 22 | bool PrecedencePredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 23 | return false; 24 | } 25 | 26 | Ref PrecedencePredicateTransition::getPredicate() const { 27 | return std::make_shared(precedence); 28 | } 29 | 30 | std::string PrecedencePredicateTransition::toString() const { 31 | return "PRECEDENCE " + Transition::toString() + " { precedence: " + std::to_string(precedence) + " }"; 32 | } 33 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PrecedencePredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | class ANTLR4CPP_PUBLIC PrecedencePredicateTransition final : public AbstractPredicateTransition { 15 | public: 16 | const int precedence; 17 | 18 | PrecedencePredicateTransition(ATNState *target, int precedence); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | virtual bool isEpsilon() const override; 22 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 23 | Ref getPredicate() const; 24 | virtual std::string toString() const override; 25 | 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PredicateEvalInfo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "SemanticContext.h" 7 | 8 | #include "atn/PredicateEvalInfo.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | PredicateEvalInfo::PredicateEvalInfo(size_t decision, TokenStream *input, size_t startIndex, size_t stopIndex, 14 | Ref const& semctx, bool evalResult, size_t predictedAlt, bool fullCtx) 15 | : DecisionEventInfo(decision, nullptr, input, startIndex, stopIndex, fullCtx), 16 | semctx(semctx), predictedAlt(predictedAlt), evalResult(evalResult) { 17 | } 18 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PredicateTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/PredicateTransition.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | PredicateTransition::PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent) : AbstractPredicateTransition(target), ruleIndex(ruleIndex), predIndex(predIndex), isCtxDependent(isCtxDependent) { 11 | } 12 | 13 | Transition::SerializationType PredicateTransition::getSerializationType() const { 14 | return PREDICATE; 15 | } 16 | 17 | bool PredicateTransition::isEpsilon() const { 18 | return true; 19 | } 20 | 21 | bool PredicateTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 22 | return false; 23 | } 24 | 25 | Ref PredicateTransition::getPredicate() const { 26 | return std::make_shared(ruleIndex, predIndex, isCtxDependent); 27 | } 28 | 29 | std::string PredicateTransition::toString() const { 30 | return "PREDICATE " + Transition::toString() + " { ruleIndex: " + std::to_string(ruleIndex) + 31 | ", predIndex: " + std::to_string(predIndex) + ", isCtxDependent: " + std::to_string(isCtxDependent) + " }"; 32 | 33 | // Generate and add a predicate context here? 34 | } 35 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/PredicateTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/AbstractPredicateTransition.h" 9 | #include "SemanticContext.h" 10 | 11 | namespace antlr4 { 12 | namespace atn { 13 | 14 | /// TO_DO: this is old comment: 15 | /// A tree of semantic predicates from the grammar AST if label==SEMPRED. 16 | /// In the ATN, labels will always be exactly one predicate, but the DFA 17 | /// may have to combine a bunch of them as it collects predicates from 18 | /// multiple ATN configurations into a single DFA state. 19 | class ANTLR4CPP_PUBLIC PredicateTransition final : public AbstractPredicateTransition { 20 | public: 21 | const size_t ruleIndex; 22 | const size_t predIndex; 23 | const bool isCtxDependent; // e.g., $i ref in pred 24 | 25 | PredicateTransition(ATNState *target, size_t ruleIndex, size_t predIndex, bool isCtxDependent); 26 | 27 | virtual SerializationType getSerializationType() const override; 28 | 29 | virtual bool isEpsilon() const override; 30 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 31 | 32 | Ref getPredicate() const; 33 | 34 | virtual std::string toString() const override; 35 | 36 | }; 37 | 38 | } // namespace atn 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/RangeTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/IntervalSet.h" 7 | 8 | #include "atn/RangeTransition.h" 9 | 10 | using namespace antlr4; 11 | using namespace antlr4::atn; 12 | 13 | RangeTransition::RangeTransition(ATNState *target, size_t from, size_t to) : Transition(target), from(from), to(to) { 14 | } 15 | 16 | Transition::SerializationType RangeTransition::getSerializationType() const { 17 | return RANGE; 18 | } 19 | 20 | misc::IntervalSet RangeTransition::label() const { 21 | return misc::IntervalSet::of((int)from, (int)to); 22 | } 23 | 24 | bool RangeTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 25 | return symbol >= from && symbol <= to; 26 | } 27 | 28 | std::string RangeTransition::toString() const { 29 | return "RANGE " + Transition::toString() + " { from: " + std::to_string(from) + ", to: " + std::to_string(to) + " }"; 30 | } 31 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/RangeTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RangeTransition final : public Transition { 14 | public: 15 | const size_t from; 16 | const size_t to; 17 | 18 | RangeTransition(ATNState *target, size_t from, size_t to); 19 | 20 | virtual SerializationType getSerializationType() const override; 21 | 22 | virtual misc::IntervalSet label() const override; 23 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 24 | 25 | virtual std::string toString() const override; 26 | }; 27 | 28 | } // namespace atn 29 | } // namespace antlr4 30 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/RuleStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | RuleStartState::RuleStartState() { 11 | isLeftRecursiveRule = false; 12 | } 13 | 14 | size_t RuleStartState::getStateType() { 15 | return RULE_START; 16 | } 17 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/RuleStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleStartState final : public ATNState { 14 | public: 15 | RuleStartState(); 16 | 17 | RuleStopState *stopState = nullptr; 18 | bool isLeftRecursiveRule = false; 19 | 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/RuleStopState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStopState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t RuleStopState::getStateType() { 11 | return RULE_STOP; 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/RuleStopState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The last node in the ATN for a rule, unless that rule is the start symbol. 14 | /// In that case, there is one transition to EOF. Later, we might encode 15 | /// references to all calls to this rule to compute FOLLOW sets for 16 | /// error handling. 17 | class ANTLR4CPP_PUBLIC RuleStopState final : public ATNState { 18 | 19 | public: 20 | virtual size_t getStateType() override; 21 | 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/RuleTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/RuleStartState.h" 7 | #include "atn/RuleTransition.h" 8 | 9 | using namespace antlr4::atn; 10 | 11 | RuleTransition::RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState) 12 | : RuleTransition(ruleStart, ruleIndex, 0, followState) { 13 | } 14 | 15 | RuleTransition::RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState) 16 | : Transition(ruleStart), ruleIndex(ruleIndex), precedence(precedence) { 17 | this->followState = followState; 18 | } 19 | 20 | Transition::SerializationType RuleTransition::getSerializationType() const { 21 | return RULE; 22 | } 23 | 24 | bool RuleTransition::isEpsilon() const { 25 | return true; 26 | } 27 | 28 | bool RuleTransition::matches(size_t /*symbol*/, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 29 | return false; 30 | } 31 | 32 | std::string RuleTransition::toString() const { 33 | std::stringstream ss; 34 | ss << "RULE " << Transition::toString() << " { ruleIndex: " << ruleIndex << ", precedence: " << precedence << 35 | ", followState: " << std::hex << followState << " }"; 36 | return ss.str(); 37 | } 38 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/RuleTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC RuleTransition : public Transition { 14 | public: 15 | /// Ptr to the rule definition object for this rule ref. 16 | const size_t ruleIndex; // no Rule object at runtime 17 | 18 | const int precedence; 19 | 20 | /// What node to begin computations following ref to rule. 21 | ATNState *followState; 22 | 23 | /// @deprecated Use 24 | /// instead. 25 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, ATNState *followState); 26 | 27 | RuleTransition(RuleStartState *ruleStart, size_t ruleIndex, int precedence, ATNState *followState); 28 | RuleTransition(RuleTransition const&) = delete; 29 | RuleTransition& operator=(RuleTransition const&) = delete; 30 | 31 | virtual SerializationType getSerializationType() const override; 32 | 33 | virtual bool isEpsilon() const override; 34 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 35 | 36 | virtual std::string toString() const override; 37 | }; 38 | 39 | } // namespace atn 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/SetTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Token.h" 7 | #include "misc/IntervalSet.h" 8 | 9 | #include "atn/SetTransition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | SetTransition::SetTransition(ATNState *target, const misc::IntervalSet &aSet) 15 | : Transition(target), set(aSet.isEmpty() ? misc::IntervalSet::of(Token::INVALID_TYPE) : aSet) { 16 | } 17 | 18 | Transition::SerializationType SetTransition::getSerializationType() const { 19 | return SET; 20 | } 21 | 22 | misc::IntervalSet SetTransition::label() const { 23 | return set; 24 | } 25 | 26 | bool SetTransition::matches(size_t symbol, size_t /*minVocabSymbol*/, size_t /*maxVocabSymbol*/) const { 27 | return set.contains(symbol); 28 | } 29 | 30 | std::string SetTransition::toString() const { 31 | return "SET " + Transition::toString() + " { set: " + set.toString() + "}"; 32 | } 33 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/SetTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// 14 | /// A transition containing a set of values. 15 | class ANTLR4CPP_PUBLIC SetTransition : public Transition { 16 | public: 17 | const misc::IntervalSet set; 18 | 19 | SetTransition(ATNState *target, const misc::IntervalSet &set); 20 | 21 | virtual SerializationType getSerializationType() const override; 22 | 23 | virtual misc::IntervalSet label() const override; 24 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 25 | 26 | virtual std::string toString() const override; 27 | }; 28 | 29 | } // namespace atn 30 | } // namespace antlr4 31 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/StarBlockStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarBlockStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t StarBlockStartState::getStateType() { 11 | return STAR_BLOCK_START; 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/StarBlockStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/BlockStartState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The block that begins a closure loop. 14 | class ANTLR4CPP_PUBLIC StarBlockStartState final : public BlockStartState { 15 | 16 | public: 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/StarLoopEntryState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | StarLoopEntryState::StarLoopEntryState() : DecisionState(), isPrecedenceDecision(false) { 11 | } 12 | 13 | size_t StarLoopEntryState::getStateType() { 14 | return STAR_LOOP_ENTRY; 15 | } 16 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/StarLoopEntryState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopEntryState final : public DecisionState { 14 | public: 15 | StarLoopEntryState(); 16 | 17 | /** 18 | * Indicates whether this state can benefit from a precedence DFA during SLL 19 | * decision making. 20 | * 21 | *

This is a computed property that is calculated during ATN deserialization 22 | * and stored for use in {@link ParserATNSimulator} and 23 | * {@link ParserInterpreter}.

24 | * 25 | * @see DFA#isPrecedenceDfa() 26 | */ 27 | bool isPrecedenceDecision = false; 28 | 29 | StarLoopbackState *loopBackState = nullptr; 30 | 31 | virtual size_t getStateType() override; 32 | }; 33 | 34 | } // namespace atn 35 | } // namespace antlr4 36 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/StarLoopbackState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/StarLoopEntryState.h" 7 | #include "atn/Transition.h" 8 | 9 | #include "atn/StarLoopbackState.h" 10 | 11 | using namespace antlr4::atn; 12 | 13 | StarLoopEntryState *StarLoopbackState::getLoopEntryState() { 14 | return dynamic_cast(transitions[0]->target); 15 | } 16 | 17 | size_t StarLoopbackState::getStateType() { 18 | return STAR_LOOP_BACK; 19 | } 20 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/StarLoopbackState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/ATNState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC StarLoopbackState final : public ATNState { 14 | public: 15 | StarLoopEntryState *getLoopEntryState(); 16 | 17 | virtual size_t getStateType() override; 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/TokensStartState.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/TokensStartState.h" 7 | 8 | using namespace antlr4::atn; 9 | 10 | size_t TokensStartState::getStateType() { 11 | return TOKEN_START; 12 | } 13 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/TokensStartState.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/DecisionState.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | /// The Tokens rule start state linking to each lexer rule start state. 14 | class ANTLR4CPP_PUBLIC TokensStartState final : public DecisionState { 15 | 16 | public: 17 | virtual size_t getStateType(); 18 | }; 19 | 20 | } // namespace atn 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/Transition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "support/Arrays.h" 8 | 9 | #include "atn/Transition.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::atn; 13 | 14 | using namespace antlrcpp; 15 | 16 | const std::vector Transition::serializationNames = { 17 | "INVALID", "EPSILON", "RANGE", "RULE", "PREDICATE", "ATOM", "ACTION", "SET", "NOT_SET", "WILDCARD", "PRECEDENCE" 18 | }; 19 | 20 | Transition::Transition(ATNState *target) { 21 | if (target == nullptr) { 22 | throw NullPointerException("target cannot be null."); 23 | } 24 | 25 | this->target = target; 26 | } 27 | 28 | Transition::~Transition() { 29 | } 30 | 31 | bool Transition::isEpsilon() const { 32 | return false; 33 | } 34 | 35 | misc::IntervalSet Transition::label() const { 36 | return misc::IntervalSet::EMPTY_SET; 37 | } 38 | 39 | std::string Transition::toString() const { 40 | std::stringstream ss; 41 | ss << "(Transition " << std::hex << this << ", target: " << std::hex << target << ')'; 42 | 43 | return ss.str(); 44 | } 45 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/WildcardTransition.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "atn/ATNState.h" 7 | 8 | #include "atn/WildcardTransition.h" 9 | 10 | using namespace antlr4::atn; 11 | 12 | WildcardTransition::WildcardTransition(ATNState *target) : Transition(target) { 13 | } 14 | 15 | Transition::SerializationType WildcardTransition::getSerializationType() const { 16 | return WILDCARD; 17 | } 18 | 19 | bool WildcardTransition::matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const { 20 | return symbol >= minVocabSymbol && symbol <= maxVocabSymbol; 21 | } 22 | 23 | std::string WildcardTransition::toString() const { 24 | return "WILDCARD " + Transition::toString() + " {}"; 25 | } 26 | -------------------------------------------------------------------------------- /antlr4-runtime/atn/WildcardTransition.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "atn/Transition.h" 9 | 10 | namespace antlr4 { 11 | namespace atn { 12 | 13 | class ANTLR4CPP_PUBLIC WildcardTransition final : public Transition { 14 | public: 15 | WildcardTransition(ATNState *target); 16 | 17 | virtual SerializationType getSerializationType() const override; 18 | 19 | virtual bool matches(size_t symbol, size_t minVocabSymbol, size_t maxVocabSymbol) const override; 20 | 21 | virtual std::string toString() const override; 22 | }; 23 | 24 | } // namespace atn 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr4-runtime/dfa/DFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "Vocabulary.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | /// A DFA walker that knows how to dump them to serialized strings. 14 | class ANTLR4CPP_PUBLIC DFASerializer { 15 | public: 16 | DFASerializer(const DFA *dfa, const std::vector& tnames); 17 | DFASerializer(const DFA *dfa, const Vocabulary &vocabulary); 18 | virtual ~DFASerializer(); 19 | 20 | virtual std::string toString() const; 21 | 22 | protected: 23 | virtual std::string getEdgeLabel(size_t i) const; 24 | virtual std::string getStateString(DFAState *s) const; 25 | 26 | private: 27 | const DFA *_dfa; 28 | const Vocabulary &_vocabulary; 29 | }; 30 | 31 | } // namespace atn 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /antlr4-runtime/dfa/LexerDFASerializer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Vocabulary.h" 7 | 8 | #include "dfa/LexerDFASerializer.h" 9 | 10 | using namespace antlr4::dfa; 11 | 12 | LexerDFASerializer::LexerDFASerializer(DFA *dfa) : DFASerializer(dfa, Vocabulary::EMPTY_VOCABULARY) { 13 | } 14 | 15 | LexerDFASerializer::~LexerDFASerializer() { 16 | } 17 | 18 | std::string LexerDFASerializer::getEdgeLabel(size_t i) const { 19 | return std::string("'") + static_cast(i) + "'"; 20 | } 21 | -------------------------------------------------------------------------------- /antlr4-runtime/dfa/LexerDFASerializer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "dfa/DFASerializer.h" 9 | 10 | namespace antlr4 { 11 | namespace dfa { 12 | 13 | class ANTLR4CPP_PUBLIC LexerDFASerializer : public DFASerializer { 14 | public: 15 | LexerDFASerializer(DFA *dfa); 16 | virtual ~LexerDFASerializer(); 17 | 18 | protected: 19 | virtual std::string getEdgeLabel(size_t i) const override; 20 | }; 21 | 22 | } // namespace atn 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /antlr4-runtime/misc/InterpreterDataReader.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | struct InterpreterData { 14 | atn::ATN atn; 15 | dfa::Vocabulary vocabulary; 16 | std::vector ruleNames; 17 | std::vector channels; // Only valid for lexer grammars. 18 | std::vector modes; // ditto 19 | 20 | InterpreterData() {}; // For invalid content. 21 | InterpreterData(std::vector const& literalNames, std::vector const& symbolicNames); 22 | }; 23 | 24 | // A class to read plain text interpreter data produced by ANTLR. 25 | class ANTLR4CPP_PUBLIC InterpreterDataReader { 26 | public: 27 | static InterpreterData parseFile(std::string const& fileName); 28 | }; 29 | 30 | } // namespace atn 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /antlr4-runtime/misc/Predicate.cpp: -------------------------------------------------------------------------------- 1 | #include "misc/Predicate.h" 2 | 3 | antlr4::misc::Predicate::~Predicate() { 4 | } 5 | -------------------------------------------------------------------------------- /antlr4-runtime/misc/Predicate.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace misc { 12 | 13 | class ANTLR4CPP_PUBLIC Predicate { 14 | public: 15 | virtual ~Predicate(); 16 | 17 | virtual bool test(tree::ParseTree *t) = 0; 18 | }; 19 | 20 | } // namespace tree 21 | } // namespace antlr4 22 | -------------------------------------------------------------------------------- /antlr4-runtime/support/Any.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Any.h" 7 | 8 | using namespace antlrcpp; 9 | 10 | Any::~Any() 11 | { 12 | delete _ptr; 13 | } 14 | 15 | Any::Base::~Base() { 16 | } 17 | -------------------------------------------------------------------------------- /antlr4-runtime/support/Arrays.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "Exceptions.h" 8 | 9 | #include "support/Arrays.h" 10 | 11 | using namespace antlrcpp; 12 | 13 | std::string Arrays::listToString(const std::vector &list, const std::string &separator) 14 | { 15 | std::stringstream ss; 16 | bool firstEntry = true; 17 | 18 | ss << '['; 19 | for (auto &entry : list) { 20 | ss << entry; 21 | if (firstEntry) { 22 | ss << separator; 23 | firstEntry = false; 24 | } 25 | } 26 | 27 | ss << ']'; 28 | return ss.str(); 29 | } 30 | 31 | template <> 32 | std::string Arrays::toString(const std::vector &source) { 33 | std::string result = "["; 34 | bool firstEntry = true; 35 | for (auto value : source) { 36 | result += value->toStringTree(); 37 | if (firstEntry) { 38 | result += ", "; 39 | firstEntry = false; 40 | } 41 | } 42 | return result + "]"; 43 | } 44 | -------------------------------------------------------------------------------- /antlr4-runtime/support/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/StringUtils.h" 7 | 8 | namespace antlrcpp { 9 | 10 | void replaceAll(std::string& str, std::string const& from, std::string const& to) 11 | { 12 | if (from.empty()) 13 | return; 14 | 15 | size_t start_pos = 0; 16 | while ((start_pos = str.find(from, start_pos)) != std::string::npos) { 17 | str.replace(start_pos, from.length(), to); 18 | start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'. 19 | } 20 | } 21 | 22 | std::string ws2s(std::wstring const& wstr) { 23 | std::wstring_convert> converter; 24 | std::string narrow = converter.to_bytes(wstr); 25 | 26 | return narrow; 27 | } 28 | 29 | std::wstring s2ws(const std::string &str) { 30 | std::wstring_convert> converter; 31 | std::wstring wide = converter.from_bytes(str); 32 | 33 | return wide; 34 | } 35 | 36 | } // namespace antrlcpp 37 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ErrorNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | 8 | antlr4::tree::ErrorNode::~ErrorNode() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ErrorNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ErrorNode : public virtual TerminalNode { 14 | public: 15 | ~ErrorNode() override; 16 | }; 17 | 18 | } // namespace tree 19 | } // namespace antlr4 20 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ErrorNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | #include "tree/ParseTreeVisitor.h" 8 | 9 | #include "tree/ErrorNodeImpl.h" 10 | 11 | using namespace antlr4; 12 | using namespace antlr4::misc; 13 | using namespace antlr4::tree; 14 | 15 | ErrorNodeImpl::ErrorNodeImpl(Token *token) : TerminalNodeImpl(token) { 16 | } 17 | 18 | ErrorNodeImpl::~ErrorNodeImpl() { 19 | } 20 | 21 | antlrcpp::Any ErrorNodeImpl::accept(ParseTreeVisitor *visitor) { 22 | return visitor->visitErrorNode(this); 23 | } 24 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ErrorNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ErrorNode.h" 9 | #include "tree/TerminalNodeImpl.h" 10 | #include "misc/Interval.h" 11 | 12 | #include "support/Any.h" 13 | 14 | namespace antlr4 { 15 | namespace tree { 16 | 17 | /// 18 | /// Represents a token that was consumed during resynchronization 19 | /// rather than during a valid match operation. For example, 20 | /// we will create this kind of a node during single token insertion 21 | /// and deletion as well as during "consume until error recovery set" 22 | /// upon no viable alternative exceptions. 23 | /// 24 | class ANTLR4CPP_PUBLIC ErrorNodeImpl : public virtual TerminalNodeImpl, public virtual ErrorNode { 25 | public: 26 | ErrorNodeImpl(Token *token); 27 | ~ErrorNodeImpl() override; 28 | 29 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ParseTree.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | 8 | using namespace antlr4::tree; 9 | 10 | ParseTree::ParseTree() : parent(nullptr) { 11 | } 12 | 13 | bool ParseTree::operator == (const ParseTree &other) const { 14 | return &other == this; 15 | } 16 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ParseTreeListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeListener.h" 7 | 8 | antlr4::tree::ParseTreeListener::~ParseTreeListener() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ParseTreeListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | /** This interface describes the minimal core of methods triggered 14 | * by {@link ParseTreeWalker}. E.g., 15 | * 16 | * ParseTreeWalker walker = new ParseTreeWalker(); 17 | * walker.walk(myParseTreeListener, myParseTree); <-- triggers events in your listener 18 | * 19 | * If you want to trigger events in multiple listeners during a single 20 | * tree walk, you can use the ParseTreeDispatcher object available at 21 | * 22 | * https://github.com/antlr/antlr4/issues/841 23 | */ 24 | class ANTLR4CPP_PUBLIC ParseTreeListener { 25 | public: 26 | virtual ~ParseTreeListener(); 27 | 28 | virtual void visitTerminal(TerminalNode *node) = 0; 29 | virtual void visitErrorNode(ErrorNode *node) = 0; 30 | virtual void enterEveryRule(ParserRuleContext *ctx) = 0; 31 | virtual void exitEveryRule(ParserRuleContext *ctx) = 0; 32 | 33 | bool operator == (const ParseTreeListener &other) { 34 | return this == &other; 35 | } 36 | }; 37 | 38 | } // namespace tree 39 | } // namespace antlr4 40 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ParseTreeProperty.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | /// 14 | /// Associate a property with a parse tree node. Useful with parse tree listeners 15 | /// that need to associate values with particular tree nodes, kind of like 16 | /// specifying a return value for the listener event method that visited a 17 | /// particular node. Example: 18 | /// 19 | ///
20 |   /// ParseTreeProperty<Integer> values = new ParseTreeProperty<Integer>();
21 |   /// values.put(tree, 36);
22 |   /// int x = values.get(tree);
23 |   /// values.removeFrom(tree);
24 |   /// 
25 | /// 26 | /// You would make one decl (values here) in the listener and use lots of times 27 | /// in your event methods. 28 | ///
29 | template 30 | class ANTLR4CPP_PUBLIC ParseTreeProperty { 31 | public: 32 | virtual V get(ParseTree *node) { 33 | return _annotations[node]; 34 | } 35 | virtual void put(ParseTree *node, V value) { 36 | _annotations[node] = value; 37 | } 38 | virtual V removeFrom(ParseTree *node) { 39 | auto value = _annotations[node]; 40 | _annotations.erase(node); 41 | return value; 42 | } 43 | 44 | protected: 45 | std::map _annotations; 46 | }; 47 | 48 | } // namespace tree 49 | } // namespace antlr4 50 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ParseTreeVisitor.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "ParseTreeVisitor.h" 7 | 8 | antlr4::tree::ParseTreeVisitor::~ParseTreeVisitor() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ParseTreeWalker.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ErrorNode.h" 7 | #include "ParserRuleContext.h" 8 | #include "tree/ParseTreeListener.h" 9 | #include "support/CPPUtils.h" 10 | 11 | #include "tree/IterativeParseTreeWalker.h" 12 | #include "tree/ParseTreeWalker.h" 13 | 14 | using namespace antlr4::tree; 15 | using namespace antlrcpp; 16 | 17 | static IterativeParseTreeWalker defaultWalker; 18 | ParseTreeWalker &ParseTreeWalker::DEFAULT = defaultWalker; 19 | 20 | ParseTreeWalker::~ParseTreeWalker() { 21 | } 22 | 23 | void ParseTreeWalker::walk(ParseTreeListener *listener, ParseTree *t) const { 24 | if (is(t)) { 25 | listener->visitErrorNode(dynamic_cast(t)); 26 | return; 27 | } else if (is(t)) { 28 | listener->visitTerminal(dynamic_cast(t)); 29 | return; 30 | } 31 | 32 | enterRule(listener, t); 33 | for (auto &child : t->children) { 34 | walk(listener, child); 35 | } 36 | exitRule(listener, t); 37 | } 38 | 39 | void ParseTreeWalker::enterRule(ParseTreeListener *listener, ParseTree *r) const { 40 | ParserRuleContext *ctx = dynamic_cast(r); 41 | listener->enterEveryRule(ctx); 42 | ctx->enterRule(listener); 43 | } 44 | 45 | void ParseTreeWalker::exitRule(ParseTreeListener *listener, ParseTree *r) const { 46 | ParserRuleContext *ctx = dynamic_cast(r); 47 | ctx->exitRule(listener); 48 | listener->exitEveryRule(ctx); 49 | } 50 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/ParseTreeWalker.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC ParseTreeWalker { 14 | public: 15 | static ParseTreeWalker &DEFAULT; 16 | 17 | virtual ~ParseTreeWalker(); 18 | 19 | virtual void walk(ParseTreeListener *listener, ParseTree *t) const; 20 | 21 | protected: 22 | /// The discovery of a rule node, involves sending two events: the generic 23 | /// and a 24 | /// -specific event. First we trigger the generic and then 25 | /// the rule specific. We do them in reverse order upon finishing the node. 26 | virtual void enterRule(ParseTreeListener *listener, ParseTree *r) const; 27 | virtual void exitRule(ParseTreeListener *listener, ParseTree *r) const; 28 | }; 29 | 30 | } // namespace tree 31 | } // namespace antlr4 32 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/TerminalNode.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/TerminalNode.h" 7 | 8 | antlr4::tree::TerminalNode::~TerminalNode() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/TerminalNode.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/ParseTree.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNode : public ParseTree { 14 | public: 15 | ~TerminalNode() override; 16 | 17 | virtual Token* getSymbol() = 0; 18 | 19 | /** Set the parent for this leaf node. 20 | * 21 | * Technically, this is not backward compatible as it changes 22 | * the interface but no one was able to create custom 23 | * TerminalNodes anyway so I'm adding as it improves internal 24 | * code quality. 25 | * 26 | * @since 4.7 27 | */ 28 | virtual void setParent(RuleContext *parent) = 0; 29 | }; 30 | 31 | } // namespace tree 32 | } // namespace antlr4 33 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/TerminalNodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "misc/Interval.h" 7 | #include "Token.h" 8 | #include "RuleContext.h" 9 | #include "tree/ParseTreeVisitor.h" 10 | 11 | #include "tree/TerminalNodeImpl.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | 16 | TerminalNodeImpl::TerminalNodeImpl(Token *symbol_) : symbol(symbol_) { 17 | } 18 | 19 | Token* TerminalNodeImpl::getSymbol() { 20 | return symbol; 21 | } 22 | 23 | void TerminalNodeImpl::setParent(RuleContext *parent_) { 24 | this->parent = parent_; 25 | } 26 | 27 | misc::Interval TerminalNodeImpl::getSourceInterval() { 28 | if (symbol == nullptr) { 29 | return misc::Interval::INVALID; 30 | } 31 | 32 | size_t tokenIndex = symbol->getTokenIndex(); 33 | return misc::Interval(tokenIndex, tokenIndex); 34 | } 35 | 36 | antlrcpp::Any TerminalNodeImpl::accept(ParseTreeVisitor *visitor) { 37 | return visitor->visitTerminal(this); 38 | } 39 | 40 | std::string TerminalNodeImpl::getText() { 41 | return symbol->getText(); 42 | } 43 | 44 | std::string TerminalNodeImpl::toStringTree(Parser * /*parser*/) { 45 | return toString(); 46 | } 47 | 48 | std::string TerminalNodeImpl::toString() { 49 | if (symbol->getType() == Token::EOF) { 50 | return ""; 51 | } 52 | return symbol->getText(); 53 | } 54 | 55 | std::string TerminalNodeImpl::toStringTree() { 56 | return toString(); 57 | } 58 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/TerminalNodeImpl.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "tree/TerminalNode.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | 13 | class ANTLR4CPP_PUBLIC TerminalNodeImpl : public virtual TerminalNode { 14 | public: 15 | Token *symbol; 16 | 17 | TerminalNodeImpl(Token *symbol); 18 | 19 | virtual Token* getSymbol() override; 20 | virtual void setParent(RuleContext *parent) override; 21 | virtual misc::Interval getSourceInterval() override; 22 | 23 | virtual antlrcpp::Any accept(ParseTreeVisitor *visitor) override; 24 | 25 | virtual std::string getText() override; 26 | virtual std::string toStringTree(Parser *parser) override; 27 | virtual std::string toString() override; 28 | virtual std::string toStringTree() override; 29 | 30 | }; 31 | 32 | } // namespace tree 33 | } // namespace antlr4 34 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/pattern/Chunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/Chunk.h" 7 | 8 | antlr4::tree::pattern::Chunk::~Chunk() { 9 | } 10 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/pattern/Chunk.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace pattern { 13 | 14 | /// 15 | /// A chunk is either a token tag, a rule tag, or a span of literal text within a 16 | /// tree pattern. 17 | ///

18 | /// The method returns a list of 19 | /// chunks in preparation for creating a token stream by 20 | /// . From there, we get a parse 21 | /// tree from with . These 22 | /// chunks are converted to , , or the 23 | /// regular tokens of the text surrounding the tags. 24 | ///

25 | class ANTLR4CPP_PUBLIC Chunk { 26 | public: 27 | Chunk() = default; 28 | Chunk(Chunk const&) = default; 29 | virtual ~Chunk(); 30 | 31 | Chunk& operator=(Chunk const&) = default; 32 | 33 | /// This method returns a text representation of the tag chunk. Labeled tags 34 | /// are returned in the form {@code label:tag}, and unlabeled tags are 35 | /// returned as just the tag name. 36 | virtual std::string toString() { 37 | std::string str; 38 | return str; 39 | } 40 | }; 41 | 42 | } // namespace pattern 43 | } // namespace tree 44 | } // namespace antlr4 45 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/pattern/TagChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TagChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TagChunk::TagChunk(const std::string &tag) : TagChunk("", tag) { 13 | } 14 | 15 | TagChunk::TagChunk(const std::string &label, const std::string &tag) : _tag(tag), _label(label) { 16 | if (tag.empty()) { 17 | throw IllegalArgumentException("tag cannot be null or empty"); 18 | } 19 | 20 | } 21 | 22 | TagChunk::~TagChunk() { 23 | } 24 | 25 | std::string TagChunk::getTag() { 26 | return _tag; 27 | } 28 | 29 | std::string TagChunk::getLabel() { 30 | return _label; 31 | } 32 | 33 | std::string TagChunk::toString() { 34 | if (!_label.empty()) { 35 | return _label + ":" + _tag; 36 | } 37 | 38 | return _tag; 39 | } 40 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/pattern/TextChunk.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "Exceptions.h" 7 | 8 | #include "tree/pattern/TextChunk.h" 9 | 10 | using namespace antlr4::tree::pattern; 11 | 12 | TextChunk::TextChunk(const std::string &text) : text(text) { 13 | if (text == "") { 14 | throw IllegalArgumentException("text cannot be nul"); 15 | } 16 | 17 | } 18 | 19 | TextChunk::~TextChunk() { 20 | } 21 | 22 | std::string TextChunk::getText() { 23 | return text; 24 | } 25 | 26 | std::string TextChunk::toString() { 27 | return std::string("'") + text + std::string("'"); 28 | } 29 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/pattern/TokenTagToken.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/pattern/TokenTagToken.h" 7 | 8 | using namespace antlr4::tree::pattern; 9 | 10 | TokenTagToken::TokenTagToken(const std::string &/*tokenName*/, int type) 11 | : CommonToken(type), tokenName(""), label("") { 12 | } 13 | 14 | TokenTagToken::TokenTagToken(const std::string &tokenName, int type, const std::string &label) 15 | : CommonToken(type), tokenName(tokenName), label(label) { 16 | } 17 | 18 | std::string TokenTagToken::getTokenName() const { 19 | return tokenName; 20 | } 21 | 22 | std::string TokenTagToken::getLabel() const { 23 | return label; 24 | } 25 | 26 | std::string TokenTagToken::getText() const { 27 | if (!label.empty()) { 28 | return "<" + label + ":" + tokenName + ">"; 29 | } 30 | 31 | return "<" + tokenName + ">"; 32 | } 33 | 34 | std::string TokenTagToken::toString() const { 35 | return tokenName + ":" + std::to_string(_type); 36 | } 37 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "support/CPPUtils.h" 7 | 8 | #include "XPathElement.h" 9 | 10 | using namespace antlr4::tree; 11 | using namespace antlr4::tree::xpath; 12 | 13 | XPathElement::XPathElement(const std::string &nodeName) { 14 | _nodeName = nodeName; 15 | } 16 | 17 | XPathElement::~XPathElement() { 18 | } 19 | 20 | std::vector XPathElement::evaluate(ParseTree * /*t*/) { 21 | return {}; 22 | } 23 | 24 | std::string XPathElement::toString() const { 25 | std::string inv = _invert ? "!" : ""; 26 | return antlrcpp::toString(*this) + "[" + inv + _nodeName + "]"; 27 | } 28 | 29 | void XPathElement::setInvert(bool value) { 30 | _invert = value; 31 | } 32 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "antlr4-common.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | class ParseTree; 13 | 14 | namespace xpath { 15 | 16 | class ANTLR4CPP_PUBLIC XPathElement { 17 | public: 18 | /// Construct element like {@code /ID} or {@code ID} or {@code /*} etc... 19 | /// op is null if just node 20 | XPathElement(const std::string &nodeName); 21 | XPathElement(XPathElement const&) = default; 22 | virtual ~XPathElement(); 23 | 24 | XPathElement& operator=(XPathElement const&) = default; 25 | 26 | /// Given tree rooted at {@code t} return all nodes matched by this path 27 | /// element. 28 | virtual std::vector evaluate(ParseTree *t); 29 | virtual std::string toString() const; 30 | 31 | void setInvert(bool value); 32 | 33 | protected: 34 | std::string _nodeName; 35 | bool _invert = false; 36 | }; 37 | 38 | } // namespace xpath 39 | } // namespace tree 40 | } // namespace antlr4 41 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathLexer.g4: -------------------------------------------------------------------------------- 1 | lexer grammar XPathLexer; 2 | 3 | tokens { TOKEN_REF, RULE_REF } 4 | 5 | /* 6 | path : separator? word (separator word)* EOF ; 7 | 8 | separator 9 | : '/' '!' 10 | | '//' '!' 11 | | '/' 12 | | '//' 13 | ; 14 | 15 | word: TOKEN_REF 16 | | RULE_REF 17 | | STRING 18 | | '*' 19 | ; 20 | */ 21 | 22 | ANYWHERE : '//' ; 23 | ROOT : '/' ; 24 | WILDCARD : '*' ; 25 | BANG : '!' ; 26 | 27 | ID : NameStartChar NameChar* 28 | { 29 | if (isupper(getText()[0])) 30 | setType(TOKEN_REF); 31 | else 32 | setType(RULE_REF); 33 | } 34 | ; 35 | 36 | fragment 37 | NameChar : NameStartChar 38 | | '0'..'9' 39 | | '_' 40 | | '\u00B7' 41 | | '\u0300'..'\u036F' 42 | | '\u203F'..'\u2040' 43 | ; 44 | 45 | fragment 46 | NameStartChar 47 | : 'A'..'Z' | 'a'..'z' 48 | | '\u00C0'..'\u00D6' 49 | | '\u00D8'..'\u00F6' 50 | | '\u00F8'..'\u02FF' 51 | | '\u0370'..'\u037D' 52 | | '\u037F'..'\u1FFF' 53 | | '\u200C'..'\u200D' 54 | | '\u2070'..'\u218F' 55 | | '\u2C00'..'\u2FEF' 56 | | '\u3001'..'\uD7FF' 57 | | '\uF900'..'\uFDCF' 58 | | '\uFDF0'..'\uFFFF' // implicitly includes ['\u10000-'\uEFFFF] 59 | ; 60 | 61 | STRING : '\'' .*? '\''; 62 | 63 | //WS : [ \t\r\n]+ -> skip ; 64 | 65 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathLexer.tokens: -------------------------------------------------------------------------------- 1 | TOKEN_REF=1 2 | RULE_REF=2 3 | ANYWHERE=3 4 | ROOT=4 5 | WILDCARD=5 6 | BANG=6 7 | ID=7 8 | STRING=8 9 | '//'=3 10 | '/'=4 11 | '*'=5 12 | '!'=6 13 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathLexerErrorListener.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPathLexerErrorListener.h" 7 | 8 | using namespace antlr4; 9 | using namespace antlr4::tree::xpath; 10 | 11 | void XPathLexerErrorListener::syntaxError(Recognizer * /*recognizer*/, Token * /*offendingSymbol*/, 12 | size_t /*line*/, size_t /*charPositionInLine*/, const std::string &/*msg*/, std::exception_ptr /*e*/) { 13 | } 14 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathLexerErrorListener.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "BaseErrorListener.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathLexerErrorListener : public BaseErrorListener { 15 | public: 16 | virtual void syntaxError(Recognizer *recognizer, Token *offendingSymbol, size_t line, 17 | size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override; 18 | }; 19 | 20 | } // namespace xpath 21 | } // namespace tree 22 | } // namespace antlr4 23 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathRuleAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "tree/xpath/XPathRuleAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleAnywhereElement::XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllRuleNodes(t, _ruleIndex); 20 | } 21 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathRuleAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | /// Either {@code ID} at start of path or {@code ...//ID} in middle of path. 15 | class ANTLR4CPP_PUBLIC XPathRuleAnywhereElement : public XPathElement { 16 | public: 17 | XPathRuleAnywhereElement(const std::string &ruleName, int ruleIndex); 18 | 19 | virtual std::vector evaluate(ParseTree *t) override; 20 | 21 | protected: 22 | int _ruleIndex = 0; 23 | }; 24 | 25 | } // namespace xpath 26 | } // namespace tree 27 | } // namespace antlr4 28 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathRuleElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathRuleElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathRuleElement::XPathRuleElement(const std::string &ruleName, size_t ruleIndex) : XPathElement(ruleName) { 15 | _ruleIndex = ruleIndex; 16 | } 17 | 18 | std::vector XPathRuleElement::evaluate(ParseTree *t) { 19 | // return all children of t that match nodeName 20 | std::vector nodes; 21 | for (auto c : t->children) { 22 | if (antlrcpp::is(c)) { 23 | ParserRuleContext *ctx = dynamic_cast(c); 24 | if ((ctx->getRuleIndex() == _ruleIndex && !_invert) || (ctx->getRuleIndex() != _ruleIndex && _invert)) { 25 | nodes.push_back(ctx); 26 | } 27 | } 28 | } 29 | return nodes; 30 | } 31 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathRuleElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathRuleElement : public XPathElement { 15 | public: 16 | XPathRuleElement(const std::string &ruleName, size_t ruleIndex); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _ruleIndex = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathTokenAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | 9 | #include "XPathTokenAnywhereElement.h" 10 | 11 | using namespace antlr4::tree; 12 | using namespace antlr4::tree::xpath; 13 | 14 | XPathTokenAnywhereElement::XPathTokenAnywhereElement(const std::string &tokenName, int tokenType) : XPathElement(tokenName) { 15 | this->tokenType = tokenType; 16 | } 17 | 18 | std::vector XPathTokenAnywhereElement::evaluate(ParseTree *t) { 19 | return Trees::findAllTokenNodes(t, tokenType); 20 | } 21 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathTokenAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenAnywhereElement : public XPathElement { 15 | protected: 16 | int tokenType = 0; 17 | public: 18 | XPathTokenAnywhereElement(const std::string &tokenName, int tokenType); 19 | 20 | virtual std::vector evaluate(ParseTree *t) override; 21 | }; 22 | 23 | } // namespace xpath 24 | } // namespace tree 25 | } // namespace antlr4 26 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathTokenElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "tree/ParseTree.h" 7 | #include "tree/Trees.h" 8 | #include "support/CPPUtils.h" 9 | #include "Token.h" 10 | 11 | #include "XPathTokenElement.h" 12 | 13 | using namespace antlr4; 14 | using namespace antlr4::tree; 15 | using namespace antlr4::tree::xpath; 16 | 17 | XPathTokenElement::XPathTokenElement(const std::string &tokenName, size_t tokenType) : XPathElement(tokenName) { 18 | _tokenType = tokenType; 19 | } 20 | 21 | std::vector XPathTokenElement::evaluate(ParseTree *t) { 22 | // return all children of t that match nodeName 23 | std::vector nodes; 24 | for (auto c : t->children) { 25 | if (antlrcpp::is(c)) { 26 | TerminalNode *tnode = dynamic_cast(c); 27 | if ((tnode->getSymbol()->getType() == _tokenType && !_invert) || (tnode->getSymbol()->getType() != _tokenType && _invert)) { 28 | nodes.push_back(tnode); 29 | } 30 | } 31 | } 32 | return nodes; 33 | } 34 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathTokenElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathTokenElement : public XPathElement { 15 | public: 16 | XPathTokenElement(const std::string &tokenName, size_t tokenType); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | 20 | protected: 21 | size_t _tokenType = 0; 22 | }; 23 | 24 | } // namespace xpath 25 | } // namespace tree 26 | } // namespace antlr4 27 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathWildcardAnywhereElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardAnywhereElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardAnywhereElement::XPathWildcardAnywhereElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardAnywhereElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | return Trees::getDescendants(t); 23 | } 24 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathWildcardAnywhereElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardAnywhereElement : public XPathElement { 15 | public: 16 | XPathWildcardAnywhereElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathWildcardElement.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #include "XPath.h" 7 | #include "tree/ParseTree.h" 8 | #include "tree/Trees.h" 9 | 10 | #include "XPathWildcardElement.h" 11 | 12 | using namespace antlr4::tree; 13 | using namespace antlr4::tree::xpath; 14 | 15 | XPathWildcardElement::XPathWildcardElement() : XPathElement(XPath::WILDCARD) { 16 | } 17 | 18 | std::vector XPathWildcardElement::evaluate(ParseTree *t) { 19 | if (_invert) { 20 | return {}; // !* is weird but valid (empty) 21 | } 22 | 23 | return t->children; 24 | } 25 | -------------------------------------------------------------------------------- /antlr4-runtime/tree/xpath/XPathWildcardElement.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. 2 | * Use of this file is governed by the BSD 3-clause license that 3 | * can be found in the LICENSE.txt file in the project root. 4 | */ 5 | 6 | #pragma once 7 | 8 | #include "XPathElement.h" 9 | 10 | namespace antlr4 { 11 | namespace tree { 12 | namespace xpath { 13 | 14 | class ANTLR4CPP_PUBLIC XPathWildcardElement : public XPathElement { 15 | public: 16 | XPathWildcardElement(); 17 | 18 | virtual std::vector evaluate(ParseTree *t) override; 19 | }; 20 | 21 | } // namespace xpath 22 | } // namespace tree 23 | } // namespace antlr4 24 | -------------------------------------------------------------------------------- /libs/PascalRTL.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/libs/PascalRTL.jar -------------------------------------------------------------------------------- /libs/antlr-4.7-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/libs/antlr-4.7-complete.jar -------------------------------------------------------------------------------- /libs/libantlr-runtime.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/libs/libantlr-runtime.a -------------------------------------------------------------------------------- /outputs/correct_100.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/outputs/correct_100.PNG -------------------------------------------------------------------------------- /outputs/s.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/outputs/s.class -------------------------------------------------------------------------------- /scripts/assemble.sh: -------------------------------------------------------------------------------- 1 | # set -x 2 | 3 | REPO_PATH="C:/Users/JP/Desktop/compiler" 4 | ASSEMBLER_PATH="$REPO_PATH/tools/jasmin-assembler" 5 | LIBS_PATH="$REPO_PATH/libs" 6 | 7 | # Need to use these CD commands because java would not find the jars in a different directory 8 | START_FROM_ROOT_DIR="cd $REPO_PATH" 9 | MOVE_J_FILE_TO_OUPUTS="cp s.j outputs" 10 | ASSEMBLE_CMD="cd $ASSEMBLER_PATH && java -jar "jasmin.jar" -g "../../outputs/$1.j"" 11 | MOVE_TO_OUTPUTS="mv s.class ../../outputs" 12 | EXECUTE_CMD="cd $LIBS_PATH && java -cp \".;../outputs;PascalRTL.jar\" "$1"" 13 | 14 | echo $START_FROM_ROOT_DIR 15 | echo $ASSEMBLE_CMD 16 | echo $EXECUTE_CMD 17 | 18 | eval "$START_FROM_ROOT_DIR" 19 | eval "$MOVE_J_FILE_TO_OUPUTS" 20 | eval "$ASSEMBLE_CMD" 21 | eval "$MOVE_TO_OUTPUTS" 22 | eval "$EXECUTE_CMD" -------------------------------------------------------------------------------- /scripts/compile.sh: -------------------------------------------------------------------------------- 1 | set -x 2 | 3 | REPO_PATH="C:/Users/JP/Desktop/compiler" 4 | 5 | # Call compiler from output folder so output files will be placed there 6 | cd $REPO_PATH/outputs 7 | ../build/compiler.exe ../samples/$1.c -------------------------------------------------------------------------------- /src/backend/pass1/Pass1Visitor.cpp: -------------------------------------------------------------------------------- 1 | #include "Pass1Visitor.hpp" 2 | 3 | 4 | 5 | namespace backend 6 | { 7 | 8 | Pass1Visitor::Pass1Visitor( 9 | const std::string fname, 10 | std::ofstream & j_file, 11 | JasminEmitter & j_emitter, 12 | SpeedLoggerPtr logger) : 13 | PassVisitor(1, j_file), 14 | program_name(fname), 15 | j_emitter(j_emitter), 16 | logger(logger) 17 | { 18 | // Store the global symbol table, created in the constructor of symbol table stack, inside the symbol store 19 | PassVisitor::store.register_symbol_table(symbol_table_stack.get_local_symbol_table()); 20 | } 21 | 22 | void Pass1Visitor::lookup_symbol_type(const std::string & variable, backend::TypeSpecifier & type, char & type_letter) 23 | { 24 | if (auto symbol = symbol_table_stack.lookup_symbol_globally(variable)) 25 | { 26 | type.set_type(symbol->get_type()); 27 | type_letter = letter_map_lookup(type); 28 | } 29 | else 30 | { 31 | THROW_EXCEPTION(MissingSymbol, variable); 32 | } 33 | } 34 | 35 | } /// backend 36 | -------------------------------------------------------------------------------- /src/backend/pass1/pass1_visitor_common.cpp: -------------------------------------------------------------------------------- 1 | #include "Pass1Visitor.hpp" 2 | 3 | 4 | 5 | namespace backend 6 | { 7 | 8 | antlrcpp::Any Pass1Visitor::visitCompilationUnit(CmmParser::CompilationUnitContext *context) 9 | { 10 | PRINT_CONTEXT_AND_EXIT_IF_PARSE_ERROR(); 11 | 12 | // Emit the program header 13 | j_emitter.emit_main_class(program_name); 14 | j_emitter.emit_class_variable("_runTimer", "LRunTimer;"); 15 | j_emitter.emit_box_comment("Global Variables"); 16 | 17 | auto value = visitChildren(context); 18 | 19 | #if 0 20 | // Print the cross-reference table 21 | CrossReferencer cross_referencer; 22 | cross_referencer.print(symtab_stack); 23 | #endif 24 | 25 | return value; 26 | } 27 | 28 | antlrcpp::Any Pass1Visitor::visitTranslationUnit(CmmParser::TranslationUnitContext *context) 29 | { 30 | PRINT_CONTEXT_AND_EXIT_IF_PARSE_ERROR(); 31 | return visitChildren(context); 32 | } 33 | 34 | antlrcpp::Any Pass1Visitor::visitTypeSpecifier(CmmParser::TypeSpecifierContext *context) 35 | { 36 | PRINT_CONTEXT_AND_EXIT_IF_PARSE_ERROR(); 37 | return visitChildren(context); 38 | } 39 | 40 | } /// backend 41 | -------------------------------------------------------------------------------- /src/backend/pass2/pass2_visitor_common.cpp: -------------------------------------------------------------------------------- 1 | #include "Pass2Visitor.hpp" 2 | 3 | 4 | 5 | namespace backend 6 | { 7 | 8 | antlrcpp::Any Pass2Visitor::visitCompilationUnit(CmmParser::CompilationUnitContext *context) 9 | { 10 | PRINT_CONTEXT_AND_EXIT_IF_PARSE_ERROR(); 11 | return visitChildren(context); 12 | } 13 | 14 | antlrcpp::Any Pass2Visitor::visitTranslationUnit(CmmParser::TranslationUnitContext * context) 15 | { 16 | PRINT_CONTEXT_AND_EXIT_IF_PARSE_ERROR(); 17 | return visitChildren(context); 18 | } 19 | 20 | antlrcpp::Any Pass2Visitor::visitTypeSpecifier(CmmParser::TypeSpecifierContext *context) 21 | { 22 | PRINT_CONTEXT_AND_EXIT_IF_PARSE_ERROR(); 23 | return visitChildren(context); 24 | } 25 | 26 | } /// backend 27 | -------------------------------------------------------------------------------- /src/backend/pass2/pass2_visitor_declarations.cpp: -------------------------------------------------------------------------------- 1 | #include "Pass2Visitor.hpp" 2 | 3 | 4 | 5 | namespace backend 6 | { 7 | 8 | antlrcpp::Any Pass2Visitor::visitDeclaration(CmmParser::DeclarationContext *context) 9 | { 10 | PRINT_CONTEXT_AND_EXIT_IF_PARSE_ERROR(); 11 | return visitChildren(context); 12 | } 13 | 14 | } /// backend 15 | -------------------------------------------------------------------------------- /src/common/common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /// Common STL includes 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | /// Common project includes 16 | #include "CustomException.hpp" 17 | 18 | /// Common using directives from namespace std { 19 | using std::cout; 20 | using std::cerr; 21 | using std::endl; 22 | using std::vector; 23 | using std::map; 24 | using std::string; 25 | /// } 26 | -------------------------------------------------------------------------------- /src/intermediate/src/SymbolTable.cpp: -------------------------------------------------------------------------------- 1 | #include "SymbolTable.hpp" 2 | 3 | 4 | 5 | namespace intermediate 6 | { 7 | 8 | const SymbolPtr & SymbolTable::create_and_add_symbol(const std::string & name, backend::TypeSpecifier type) 9 | { 10 | if (backend::Type::t_double == type.get_type() || backend::Type::t_long == type.get_type()) 11 | { 12 | m_current_symbol_id++; 13 | } 14 | 15 | SymbolPtr s_ptr = std::make_shared (m_current_symbol_id, type); 16 | m_table[name] = s_ptr; 17 | 18 | m_current_symbol_id++; 19 | 20 | return m_table[name]; 21 | } 22 | 23 | SymbolPtr SymbolTable::lookup_symbol(const std::string & name) const 24 | { 25 | SymbolPtr s_ptr = nullptr; 26 | 27 | if (m_table.find(name) != m_table.end()) 28 | { 29 | s_ptr = m_table.at(name); 30 | } 31 | 32 | return s_ptr; 33 | } 34 | 35 | bool SymbolTable::symbol_exists(const std::string & name) const 36 | { 37 | return (m_table.find(name) != m_table.end()); 38 | } 39 | 40 | std::vector SymbolTable::glob_all_symbols() const 41 | { 42 | std::vector symbols; 43 | 44 | for (const auto & pair : m_table) 45 | { 46 | symbols.push_back(pair.second); 47 | } 48 | 49 | return symbols; 50 | } 51 | 52 | } /// intermediate 53 | -------------------------------------------------------------------------------- /src/utils/logger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /// spdlog module includes 6 | #include "spdlog/spdlog.h" 7 | #include "spdlog/sinks/stdout_color_sinks.h" 8 | 9 | 10 | 11 | /// Default logger name for typical logging operations 12 | #define DEFAULT_LOGGER_NAME "logger" 13 | 14 | /// Alias for logger pointer 15 | using SpeedLoggerPtr = std::shared_ptr ; 16 | 17 | /** 18 | * Factory method for creating a logger object 19 | * @param debug_flag : True to set debug level to info, false for all levels 20 | * @param name : Name of logger object 21 | */ 22 | inline SpeedLoggerPtr logger_create(const bool debug_flag, const std::string & name = DEFAULT_LOGGER_NAME) 23 | { 24 | // Replaces the default logging format pattern 25 | static const std::string pattern = "%^[%l]%$ %v"; 26 | spdlog::set_pattern(pattern); 27 | 28 | // Create a logger 29 | SpeedLoggerPtr logger = spdlog::stdout_color_mt(name); 30 | 31 | // Change the logging level 32 | if (!debug_flag) 33 | { 34 | logger->set_level(spdlog::level::info); 35 | } 36 | else 37 | { 38 | logger->set_level(spdlog::level::debug); 39 | } 40 | 41 | return logger; 42 | } 43 | 44 | /// Returns a handle to the default logger 45 | inline SpeedLoggerPtr logger_get_default_logger() 46 | { 47 | return spdlog::get(DEFAULT_LOGGER_NAME); 48 | } -------------------------------------------------------------------------------- /tools/jasmin-assembler/jasmin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/tools/jasmin-assembler/jasmin.jar -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/ant-launcher.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/tools/jasmin-assembler/lib/ant-launcher.jar -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/ant.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/tools/jasmin-assembler/lib/ant.jar -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/jas/JASMIN_NOTES.txt: -------------------------------------------------------------------------------- 1 | 10 October 2004, Jon Meyer 2 | 3 | * Moved the jas src code into ../src/jas. 4 | 5 | 6 | 1 March 1997, Jon Meyer 7 | 8 | * Modified JAS to use self-contained RuntimeConstants interface. 9 | 10 | * Moved JAS classes into the Jasmin classes directory. 11 | 12 | * Fixed bug in CatchEntry. 13 | 14 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/jas/examples/simple.jas: -------------------------------------------------------------------------------- 1 | ;; script to create a class that does nothing. 2 | 3 | 4 | ; make-class-env creates 5 | ; a ClassEnv object which is 6 | ; used to store information about 7 | ; an object. 8 | (define my-class (make-class-env)) 9 | 10 | ; make-code creates a code object 11 | ; which contains the body of a 12 | ; method. 13 | 14 | (define init-code (make-code)) 15 | (jas-code-addinsn init-code 16 | (aload_0)) 17 | (jas-code-addinsn init-code 18 | (invokenonvirtual 19 | (make-method-cpe "java/lang/Object" "" "()V"))) 20 | (jas-code-addinsn init-code 21 | (return)) 22 | 23 | ; fill up the class with goodies 24 | (jas-class-setsuperclass my-class (make-class-cpe "java/lang/Object")) 25 | (jas-class-setclass my-class (make-class-cpe "out")) 26 | (jas-class-setaccess my-class acc-public) 27 | (jas-class-addmethod my-class acc-public "" "()V" init-code ()) 28 | 29 | ; and write it all out 30 | (jas-class-write my-class (make-outputstream "out.class")) 31 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/jas/examples/simple.java: -------------------------------------------------------------------------------- 1 | import jas.*; 2 | import java.io.*; 3 | import sun.tools.java.RuntimeConstants; 4 | 5 | // 6 | // This is program that makes calls into the jas package 7 | // to generate a class that does nothing at all. 8 | // 9 | 10 | class simple implements RuntimeConstants 11 | { 12 | public static void main(String argv[]) 13 | throws jasError, IOException 14 | { 15 | 16 | // CodeAttr's contain the body of 17 | // a method. 18 | 19 | CodeAttr init = new CodeAttr(); 20 | init.addInsn(new Insn(opc_aload_0)); 21 | init.addInsn(new Insn(opc_invokenonvirtual, 22 | new MethodCP("java/lang/Object", "", "()V"))); 23 | init.addInsn(new Insn(opc_return)); 24 | 25 | 26 | // ClassEnv's are used as a container 27 | // to hold all information about a class. 28 | 29 | ClassEnv nclass = new ClassEnv(); 30 | nclass.setClass(new ClassCP("out")); 31 | nclass.setSuperClass(new ClassCP("java/lang/Object")); 32 | 33 | 34 | 35 | // Add the init code to the class. 36 | nclass.addMethod((short)ACC_PUBLIC, "", "()V", init, null); 37 | 38 | 39 | // write it all out 40 | nclass.write(new DataOutputStream 41 | (new FileOutputStream("out.class"))); 42 | } 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/jas/examples/test.inp: -------------------------------------------------------------------------------- 1 | a = 10; 2 | println a; 3 | 4 | b = a + 5; 5 | 6 | println (b); 7 | println(a*b +2); 8 | 9 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/jas/tests/README: -------------------------------------------------------------------------------- 1 | This is a start of a basic set of tests intended to exercise the API 2 | functions available in the jas and scm packages. It is not complete by 3 | any means. 4 | 5 | all.java tries to touch as much of the jas API as it can, generating a 6 | non functional class called regress.class. all.jas does 7 | something similar, but for the scm package. 8 | 9 | Once the jas and scm packages are compiled, do this: 10 | 11 | % (cd ..; javac -d . tests/all.java; java all; cmp regress.class tests/regress.class) 12 | % (cd ..; java scm.driver tests/all.jas; cmp scmregress.class tests/scmregress.class) 13 | 14 | 15 | If both these complete silently, you are in good shape. Otherwise, 16 | mail me a bug report and enough details for me to replicate it :) 17 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/jas/tests/regress.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/tools/jasmin-assembler/lib/jas/tests/regress.class -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/jas/tests/scmregress.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/tools/jasmin-assembler/lib/jas/tests/scmregress.class -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/java_cup.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/tools/jasmin-assembler/lib/java_cup.jar -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/java_cup/JASMIN_NOTES.txt: -------------------------------------------------------------------------------- 1 | Jasmin use of Java Cup 2 | 3 | The source code for JavaCup, as it is used in the Jasmin distribution, has been moved to ../src/java_cup. 4 | 5 | 6 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/java_cup/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/tools/jasmin-assembler/lib/java_cup/Thumbs.db -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/java_cup/java_cup.logo.new.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jpan127/compiler/850d601772b37afedcd9095b3673ec8c037ae1b4/tools/jasmin-assembler/lib/java_cup/java_cup.logo.new.gif -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/java_cup/simple_calc/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String argv[]) 4 | { 5 | try { 6 | /* allocate a parser object */ 7 | parser parse_obj = new parser(); 8 | 9 | /* prompt the user */ 10 | System.out.println("Reading expressions from standard input..."); 11 | 12 | /* deterimine if we doing debug or normal parse, and do it */ 13 | if (argv.length >= 1 && argv[0].equals("-debug")) 14 | { 15 | parse_obj.debug_parse(); 16 | } 17 | else 18 | { 19 | parse_obj.parse(); 20 | } 21 | } catch (java.lang.Exception ex) { 22 | System.err.println("Exception: " + ex.getMessage()); 23 | ex.printStackTrace(); 24 | System.exit(-1); 25 | } 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/lib/java_cup/simple_calc/sym.java: -------------------------------------------------------------------------------- 1 | 2 | //---------------------------------------------------- 3 | // The following code was generated by Java(tm) CUP v0.9d 4 | // Sun Jan 07 17:10:10 EST 1996 5 | //---------------------------------------------------- 6 | 7 | /** JavaCup generated class containing symbol constants. */ 8 | public class sym { 9 | /* terminals */ 10 | static final int SEMI = 2; 11 | static final int EOF = 0; 12 | static final int DIVIDE = 6; 13 | static final int NUMBER = 10; 14 | static final int error = 1; 15 | static final int MINUS = 4; 16 | static final int TIMES = 5; 17 | static final int LPAREN = 8; 18 | static final int RPAREN = 9; 19 | static final int MOD = 7; 20 | static final int PLUS = 3; 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/Jasmin.java: -------------------------------------------------------------------------------- 1 | import jasmin.Main; 2 | 3 | public class Jasmin { 4 | public static void main(String args[]) 5 | { Main.main(args); } 6 | } 7 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/AnnotDefAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This attribute can associated with a method, field or class. 3 | * 4 | * @author $Author: Iouri Kharon $ 5 | * @version $Revision: 1.0 $ 6 | */ 7 | 8 | package jas; 9 | 10 | import java.io.*; 11 | import java.util.Vector; 12 | import java.util.Enumeration; 13 | 14 | public class AnnotDefAttr 15 | { 16 | static final CP attr = new AsciiCP("AnnotationDefault"); 17 | Annotation ann; 18 | 19 | public AnnotDefAttr() 20 | { ann = new Annotation(); } 21 | 22 | public Annotation get() 23 | { return(ann); } 24 | 25 | void resolve(ClassEnv e) 26 | { 27 | e.addCPItem(attr); 28 | ann.resolve(e); 29 | } 30 | 31 | void write(ClassEnv e, DataOutputStream out) 32 | throws IOException, jasError 33 | { 34 | out.writeShort(e.getCPIndex(attr)); 35 | out.writeInt(ann.size()); 36 | ann.write(e, out); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/AnnotationAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This attribute can associated with a method, field or class. 3 | * 4 | * @author $Author: Iouri Kharon $ 5 | * @version $Revision: 1.0 $ 6 | */ 7 | 8 | package jas; 9 | 10 | import java.io.*; 11 | import java.util.Vector; 12 | import java.util.Enumeration; 13 | 14 | public class AnnotationAttr 15 | { 16 | CP attr; 17 | Vector anns; 18 | 19 | public AnnotationAttr(boolean visible) 20 | { 21 | attr = new AsciiCP(visible ? "RuntimeVisibleAnnotations" : 22 | "RuntimeInvisibleAnnotations"); 23 | anns = new Vector(); 24 | } 25 | 26 | public void add(Annotation annotation) 27 | { anns.add(annotation); } 28 | 29 | void resolve(ClassEnv e) 30 | { 31 | e.addCPItem(attr); 32 | for(Enumeration en = anns.elements(); en.hasMoreElements(); ) 33 | ((Annotation)en.nextElement()).resolve(e); 34 | } 35 | 36 | void write(ClassEnv e, DataOutputStream out) 37 | throws IOException, jasError 38 | { 39 | out.writeShort(e.getCPIndex(attr)); 40 | int len = 2; 41 | for(Enumeration en = anns.elements(); en.hasMoreElements(); ) 42 | len += ((Annotation)en.nextElement()).size(); 43 | out.writeInt(len); 44 | out.writeShort((short)anns.size()); 45 | for(Enumeration en = anns.elements(); en.hasMoreElements(); ) 46 | ((Annotation)en.nextElement()).write(e, out); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/AsciiCP.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a class to create Ascii CP entries. 3 | * 4 | * @author $Author: jonmeyerny $ 5 | * @version $Revision: 1.1 $ 6 | */ 7 | 8 | package jas; 9 | 10 | import java.io.*; 11 | 12 | 13 | public class AsciiCP extends CP implements RuntimeConstants 14 | { 15 | /** 16 | * @param s Name of the ascii constant pool entry 17 | */ 18 | public AsciiCP(String s) 19 | { uniq = s.intern(); } 20 | void resolve(ClassEnv e) 21 | { return; } 22 | 23 | public String toString() { return "AsciiCP: " + uniq; } 24 | void write(ClassEnv e, DataOutputStream out) 25 | throws IOException 26 | { 27 | out.writeByte(CONSTANT_UTF8); 28 | out.writeUTF(uniq); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/CP.java: -------------------------------------------------------------------------------- 1 | /** 2 | * this is an abstraction to contain all the CPE items 3 | * that can be created. 4 | * 5 | * @see AsciiCP 6 | * @see ClassCP 7 | * @see NameTypeCP 8 | * @see FieldCP 9 | * @see InterfaceCP 10 | * @see MethodCP 11 | * @see IntegerCP 12 | * @see LongCP 13 | * @see FloatCP 14 | * @see DoubleCP 15 | * @see StringCP 16 | * 17 | * @author $Author: jonmeyerny $ 18 | * @version $Revision: 1.1 $ 19 | */ 20 | 21 | 22 | package jas; 23 | // one class to ring them all... 24 | 25 | import java.io.*; 26 | 27 | public abstract class CP 28 | { 29 | String uniq; 30 | 31 | String getUniq() { return uniq; } 32 | 33 | abstract void resolve(ClassEnv e); 34 | 35 | abstract void write(ClassEnv e, DataOutputStream out) 36 | throws IOException, jasError; 37 | } 38 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/ClassCP.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This is used to create a Class constant pool item 3 | * 4 | * @author $Author: jonmeyerny $ 5 | * @version $Revision: 1.1 $ 6 | */ 7 | 8 | package jas; 9 | 10 | import java.io.*; 11 | 12 | 13 | public class ClassCP extends CP implements RuntimeConstants 14 | { 15 | AsciiCP name; 16 | 17 | /** 18 | * @param name Name of the class 19 | */ 20 | public ClassCP(String name) 21 | { 22 | uniq = ("CLASS: #$%^#$" + name).intern(); 23 | this.name = new AsciiCP(name); 24 | } 25 | 26 | void resolve(ClassEnv e) 27 | { e.addCPItem(name); } 28 | 29 | void write(ClassEnv e, DataOutputStream out) 30 | throws IOException, jasError 31 | { 32 | out.writeByte(CONSTANT_CLASS); 33 | out.writeShort(e.getCPIndex(name)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/ConstAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This is typically used to represent a constant value for 3 | * a field entry (as in static final int foo = 20). 4 | * 5 | * @author $Author: jonmeyerny $ 6 | * @version $Revision: 1.1 $ 7 | */ 8 | 9 | package jas; 10 | 11 | import java.io.*; 12 | 13 | public class ConstAttr 14 | { 15 | static final CP attr = new AsciiCP("ConstantValue"); 16 | CP val; 17 | 18 | /** 19 | * Create a new constant attribute whose constant value 20 | * is picked up from constant pool with the given entry. 21 | * @param val Constant pool item whose value is associated 22 | * with the constant value attribute 23 | */ 24 | 25 | public ConstAttr(CP val) 26 | { this.val = val; } 27 | 28 | void resolve(ClassEnv e) 29 | { 30 | e.addCPItem(val); 31 | e.addCPItem(attr); 32 | } 33 | 34 | void write(ClassEnv e, DataOutputStream out) 35 | throws IOException, jasError 36 | { 37 | out.writeShort(e.getCPIndex(attr)); 38 | out.writeInt(2); 39 | out.writeShort(e.getCPIndex(val)); 40 | } 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/DeprecatedAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This attribute is used to mark class/method/field as deprecated. 3 | * @author $Author: jonmeyerny $ 4 | * @version $Revision: 1.1 $ 5 | */ 6 | 7 | package jas; 8 | 9 | import java.io.*; 10 | 11 | public class DeprecatedAttr 12 | { 13 | static final CP attr = new AsciiCP("Deprecated"); 14 | 15 | /** 16 | * Create a deprecated attribute. 17 | * @see ClassEnv#setDeprecated 18 | */ 19 | 20 | public DeprecatedAttr() { } 21 | 22 | void resolve(ClassEnv e) 23 | { e.addCPItem(attr); } 24 | 25 | void write(ClassEnv e, DataOutputStream out) 26 | throws IOException, jasError 27 | { 28 | out.writeShort(e.getCPIndex(attr)); 29 | out.writeInt(0); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/DoubleCP.java: -------------------------------------------------------------------------------- 1 | package jas; 2 | 3 | import java.io.*; 4 | 5 | 6 | /** 7 | * Wrap an Double constant reference with this CPE. 8 | * 9 | * @author $Author: jonmeyerny $ 10 | * @version $Revision: 1.1 $ 11 | */ 12 | 13 | public class DoubleCP extends CP implements RuntimeConstants 14 | { 15 | double val; 16 | 17 | /** 18 | * @param n Value for Double constant 19 | */ 20 | public DoubleCP(double n) 21 | { 22 | uniq = ("Double: @#$" + n).intern(); 23 | val = n; 24 | } 25 | void resolve(ClassEnv e) { return; } 26 | void write(ClassEnv e, DataOutputStream out) 27 | throws IOException 28 | { 29 | out.writeByte(CONSTANT_DOUBLE); 30 | out.writeDouble(val); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/EnclosingMethodAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This attribute is used to define the enclosing method of this class 3 | * @author $Author: Daniel Reynaud $ 4 | * @version $Revision: 1.0 $ 5 | */ 6 | 7 | package jas; 8 | 9 | import java.io.*; 10 | 11 | public class EnclosingMethodAttr 12 | { 13 | static final CP attr = new AsciiCP("EnclosingMethod"); 14 | CP clscp, 15 | ntcp; 16 | 17 | String cls, mtd, dsc; 18 | 19 | /** 20 | * Create an EnclosingMethod attribute 21 | * @param cls Name of the enclosing class 22 | * @param mtd Name of the enclosing method (can be null) 23 | * @param dsc Name of the enclosing method descriptor (can be null) 24 | * @see ClassEnv#setEnclosingMethod 25 | */ 26 | 27 | public EnclosingMethodAttr(String cls, String mtd, String dsc) 28 | { this.cls = cls; 29 | this.mtd = mtd; 30 | this.dsc = dsc; 31 | clscp = new ClassCP(cls); 32 | if(mtd!=null && dsc!=null) 33 | ntcp = new NameTypeCP(mtd, dsc); 34 | } 35 | 36 | void resolve(ClassEnv e) 37 | { e.addCPItem(attr); 38 | e.addCPItem(clscp); // add the CONSTANT_Class 39 | clscp.resolve(e); // add the CONSTANT_Utf8 for the class name 40 | if(ntcp!=null) { 41 | e.addCPItem(ntcp); // add the CONSTANT_NameAndType 42 | ntcp.resolve(e); // add the two CONSTANT_Utf8 43 | } 44 | } 45 | 46 | void write(ClassEnv e, DataOutputStream out) 47 | throws IOException, jasError 48 | { 49 | out.writeShort(e.getCPIndex(attr)); 50 | out.writeInt(4); 51 | out.writeShort(e.getCPIndex(clscp)); 52 | out.writeShort(ntcp==null ? 0 : e.getCPIndex(ntcp)); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/ExceptAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This attribute is associated with a method, and indicates 3 | * the set of exceptions (as classCP items) that can be thrown 4 | * by the method. 5 | * 6 | * @author $Author: jonmeyerny $ 7 | * @version $Revision: 1.1 $ 8 | */ 9 | 10 | package jas; 11 | 12 | import java.io.*; 13 | import java.util.*; 14 | 15 | public class ExceptAttr 16 | { 17 | static final CP attr = new AsciiCP("Exceptions"); 18 | 19 | Vector cps; 20 | 21 | public ExceptAttr() { cps = new Vector(); } 22 | /** 23 | * @param cp Exception class to be added to attribute. This is 24 | * typically a ClassCP 25 | */ 26 | public void addException(CP cp) 27 | { cps.addElement(cp); } 28 | 29 | void resolve(ClassEnv e) 30 | { 31 | e.addCPItem(attr); 32 | for (Enumeration en = cps.elements(); en.hasMoreElements();) 33 | { e.addCPItem((CP)(en.nextElement())); } 34 | } 35 | 36 | void write(ClassEnv e, DataOutputStream out) 37 | throws IOException, jasError 38 | { 39 | out.writeShort(e.getCPIndex(attr)); 40 | out.writeInt(cps.size()*2 + 2); 41 | out.writeShort(cps.size()); 42 | for (Enumeration en = cps.elements(); en.hasMoreElements();) 43 | { out.writeShort(e.getCPIndex((CP)(en.nextElement()))); } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/FieldCP.java: -------------------------------------------------------------------------------- 1 | /** 2 | * FieldCP's are used to refer to a field in a particular 3 | * class. 4 | * 5 | * @author $Author: jonmeyerny $ 6 | * @version $Revision: 1.1 $ 7 | */ 8 | 9 | package jas; 10 | 11 | import java.io.*; 12 | 13 | 14 | public class FieldCP extends CP implements RuntimeConstants 15 | { 16 | ClassCP clazz; 17 | NameTypeCP nt; 18 | 19 | /** 20 | * FieldCP's are created by specifying the class to which the 21 | * field belongs, the name of the symbol, and its signature. 22 | * For instance, to refer to the field out in 23 | * System.out use 24 | * new FieldCP("java/lang/System", "out", "Ljava/io/PrintStream;") 25 | * 26 | * @param clazz Name of class 27 | * @param name Name of symbol 28 | * @param sig Signature for symbol 29 | */ 30 | 31 | public FieldCP(String clazz, String name, String sig) 32 | { 33 | uniq = (clazz + "&%$#&" + name + "*()#$" + sig).intern(); 34 | this.clazz = new ClassCP(clazz); 35 | this.nt = new NameTypeCP(name, sig); 36 | } 37 | 38 | void resolve(ClassEnv e) 39 | { 40 | e.addCPItem(clazz); 41 | e.addCPItem(nt); 42 | } 43 | 44 | void write(ClassEnv e, DataOutputStream out) 45 | throws IOException, jasError 46 | { 47 | out.writeByte(CONSTANT_FIELD); 48 | out.writeShort(e.getCPIndex(clazz)); 49 | out.writeShort(e.getCPIndex(nt)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/FloatCP.java: -------------------------------------------------------------------------------- 1 | package jas; 2 | 3 | import java.io.*; 4 | 5 | 6 | /** 7 | * Wrap an Float constant reference with this CPE. 8 | * 9 | * @author $Author: jonmeyerny $ 10 | * @version $Revision: 1.1 $ 11 | */ 12 | 13 | public class FloatCP extends CP implements RuntimeConstants 14 | { 15 | float val; 16 | 17 | /** 18 | * @param n Value for Float constant 19 | */ 20 | public FloatCP(float n) 21 | { 22 | uniq = ("Float: @#$" + n).intern(); 23 | val = n; 24 | } 25 | void resolve(ClassEnv e) { return; } 26 | void write(ClassEnv e, DataOutputStream out) 27 | throws IOException 28 | { 29 | out.writeByte(CONSTANT_FLOAT); 30 | out.writeFloat(val); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/IincInsn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Some instructions are perniticky enough that its simpler 3 | * to write them separately instead of smushing them with 4 | * all the rest. the iinc instruction is one of them. 5 | * @author $Author: jonmeyerny $ 6 | * @version $Revision: 1.1 $ 7 | */ 8 | 9 | package jas; 10 | 11 | import java.io.*; 12 | 13 | 14 | public class IincInsn extends Insn implements RuntimeConstants 15 | { 16 | /** 17 | * @param vindex Index of variable to be incremented. 18 | * @param increment value to be added to the variable. 19 | * 20 | * A wide prefix is automatically added if either the 21 | * vindex exceeds 256, or the increment value lies 22 | * outside the range [-128, 127] 23 | * 24 | * The VM spec is unclear on how the wide instruction is implemented, 25 | * but the implementation makes both the constant and the 26 | * variable index 16 bit values for the wide version of this instruction. 27 | */ 28 | public IincInsn(int vindex, int increment, boolean Wide) 29 | { 30 | opc = opc_iinc; 31 | operand = new IincOperand(vindex, increment, Wide); 32 | } 33 | } 34 | 35 | /* --- Revision History --------------------------------------------------- 36 | --- Iouri Kharon, Aug 10 2006 37 | Added 'Wide' prefix support 38 | */ 39 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/InnerClass.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author $Author: Iouri Kharon $ 3 | * @version $Revision: 1.0 $ 4 | */ 5 | package jas; 6 | 7 | import java.io.*; 8 | 9 | public class InnerClass 10 | { 11 | ClassCP inner, outer; 12 | CP name; 13 | short access; 14 | 15 | public static int size() 16 | { return (4 * 2); } 17 | 18 | /** 19 | * Make up a new attribute 20 | * @see ClassEnv#addInnerClass 21 | */ 22 | public InnerClass(short access, String name, String inner, String outer) 23 | { 24 | this.access = access; 25 | this.name = null; 26 | if(name != null) this.name = new AsciiCP(name); 27 | this.inner = null; 28 | if(inner != null) this.inner = new ClassCP(inner); 29 | this.outer = null; 30 | if(outer != null) this.outer = new ClassCP(outer); 31 | } 32 | 33 | void resolve(ClassEnv e) 34 | { 35 | if(name != null) e.addCPItem(name); 36 | if(inner != null) { 37 | e.addCPItem(inner); 38 | inner.resolve(e); 39 | } 40 | if(outer != null) { 41 | e.addCPItem(outer); 42 | outer.resolve(e); 43 | } 44 | } 45 | 46 | void write(ClassEnv e, DataOutputStream out) throws IOException, jasError 47 | { 48 | short id = 0; 49 | if(inner != null) id = e.getCPIndex(inner); 50 | out.writeShort(id); 51 | id = 0; 52 | if(outer != null) id = e.getCPIndex(outer); 53 | out.writeShort(id); 54 | id = 0; 55 | if(name != null) id = e.getCPIndex(name); 56 | out.writeShort(id); 57 | out.writeShort(access); 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/InnerClassesAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author $Author: Iouri Kharon $ 3 | * @version $Revision: 1.0 $ 4 | */ 5 | 6 | package jas; 7 | 8 | import java.io.*; 9 | import java.util.Vector; 10 | import java.util.Enumeration; 11 | 12 | public class InnerClassesAttr 13 | { 14 | static final CP attr = new AsciiCP("InnerClasses"); 15 | private Vector list; 16 | 17 | public InnerClassesAttr() 18 | { list = new Vector(); } 19 | 20 | public void addInnerClass(InnerClass item) 21 | { list.add(item); } 22 | 23 | void resolve(ClassEnv e) 24 | { 25 | e.addCPItem(attr); 26 | for(Enumeration en = list.elements(); en.hasMoreElements(); ) 27 | ((InnerClass)en.nextElement()).resolve(e); 28 | } 29 | 30 | void write(ClassEnv e, DataOutputStream out) throws IOException, jasError 31 | { 32 | out.writeShort(e.getCPIndex(attr)); 33 | out.writeInt((list.size() * InnerClass.size()) + 2); 34 | out.writeShort((short)list.size()); 35 | for(Enumeration en = list.elements(); en.hasMoreElements(); ) 36 | ((InnerClass)en.nextElement()).write(e, out); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/IntegerCP.java: -------------------------------------------------------------------------------- 1 | package jas; 2 | 3 | import java.io.*; 4 | 5 | 6 | /** 7 | * Wrap an integer constant reference with this CPE. 8 | * 9 | * @author $Author: jonmeyerny $ 10 | * @version $Revision: 1.1 $ 11 | */ 12 | 13 | public class IntegerCP extends CP implements RuntimeConstants 14 | { 15 | int val; 16 | 17 | /** 18 | * @param n Value for integer constant 19 | */ 20 | public IntegerCP(int n) 21 | { 22 | uniq = ("Integer: @#$" + n).intern(); 23 | val = n; 24 | } 25 | void resolve(ClassEnv e) { return; } 26 | void write(ClassEnv e, DataOutputStream out) 27 | throws IOException 28 | { 29 | out.writeByte(CONSTANT_INTEGER); 30 | out.writeInt(val); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/InterfaceCP.java: -------------------------------------------------------------------------------- 1 | /** 2 | * An InterfaceCP is used to refer to an interface specification 3 | * 4 | * @author $Author: jonmeyerny $ 5 | * @version $Revision: 1.1 $ 6 | */ 7 | 8 | package jas; 9 | 10 | import java.io.*; 11 | 12 | 13 | public class InterfaceCP extends CP implements RuntimeConstants 14 | { 15 | ClassCP clazz; 16 | NameTypeCP nt; 17 | 18 | /** 19 | * @param cname Name of class defining the interface 20 | * @param varname symbol for the interface method 21 | * @param sig Signature for method 22 | */ 23 | public InterfaceCP(String cname, String varname, String sig) 24 | { 25 | uniq = (cname + "&%$#&" + varname + "*()#$" + sig).intern(); 26 | clazz = new ClassCP(cname); 27 | nt = new NameTypeCP(varname, sig); 28 | } 29 | 30 | void resolve(ClassEnv e) 31 | { 32 | e.addCPItem(clazz); 33 | e.addCPItem(nt); 34 | } 35 | 36 | void write(ClassEnv e, DataOutputStream out) 37 | throws IOException, jasError 38 | { 39 | out.writeByte(CONSTANT_INTERFACEMETHOD); 40 | out.writeShort(e.getCPIndex(clazz)); 41 | out.writeShort(e.getCPIndex(nt)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/InvokeinterfaceInsn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Some instructions are perniticky enough that its simpler 3 | * to write them separately instead of smushing them with 4 | * all the rest. the invokeinterface instruction is one of them. 5 | * @author $Author: jonmeyerny $ 6 | * @version $Revision: 1.1 $ 7 | */ 8 | 9 | package jas; 10 | 11 | import java.io.*; 12 | 13 | 14 | public class InvokeinterfaceInsn extends Insn implements RuntimeConstants 15 | { 16 | public InvokeinterfaceInsn(CP cpe, int nargs) 17 | { 18 | opc = opc_invokeinterface; 19 | operand = new InvokeinterfaceOperand(cpe, nargs); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/LabelOrOffset.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The purpose of this class is to have a generic type 3 | * for labels and offsets, used by tableswitch and lookupswitch 4 | * 5 | */ 6 | 7 | package jas; 8 | 9 | import java.io.DataOutputStream; 10 | import java.io.IOException; 11 | 12 | public class LabelOrOffset { 13 | private Label label; 14 | private int offset; 15 | 16 | public LabelOrOffset(Label l) { 17 | label = l; 18 | } 19 | 20 | public LabelOrOffset(int o) { 21 | offset = o; 22 | } 23 | 24 | Label getLabel() { 25 | return label; 26 | } 27 | 28 | int getOffset() { 29 | return offset; 30 | } 31 | 32 | void writeWideOffset(CodeAttr ce, Insn source, DataOutputStream out) 33 | throws jasError, IOException { 34 | if(label!=null) 35 | label.writeWideOffset(ce, source, out); 36 | else 37 | out.writeInt(offset); 38 | } 39 | } -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/LongCP.java: -------------------------------------------------------------------------------- 1 | package jas; 2 | 3 | import java.io.*; 4 | 5 | 6 | /** 7 | * Wrap an Long constant reference with this CPE. 8 | * 9 | * @author $Author: jonmeyerny $ 10 | * @version $Revision: 1.1 $ 11 | */ 12 | 13 | public class LongCP extends CP implements RuntimeConstants 14 | { 15 | long val; 16 | 17 | /** 18 | * @param n Value for Long constant 19 | */ 20 | public LongCP(long n) 21 | { 22 | uniq = ("Long: @#$" + n).intern(); 23 | val = n; 24 | } 25 | void resolve(ClassEnv e) { return; } 26 | void write(ClassEnv e, DataOutputStream out) 27 | throws IOException 28 | { 29 | out.writeByte(CONSTANT_LONG); 30 | out.writeLong(val); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/LookupswitchInsn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Some instructions are perniticky enough that its simpler 3 | * to write them separately instead of smushing them with 4 | * all the rest. The lookupswitch instruction is one of them. 5 | * @author $Author: jonmeyerny $ 6 | * @version $Revision: 1.1 $ 7 | */ 8 | 9 | package jas; 10 | 11 | import java.io.*; 12 | 13 | 14 | public class LookupswitchInsn extends Insn implements RuntimeConstants 15 | { 16 | /** 17 | * @param def default Label for switch 18 | * @param match array of match values for switch 19 | * @param target Label array of corresponding targets for each match 20 | */ 21 | 22 | public LookupswitchInsn(LabelOrOffset def, int match[], 23 | LabelOrOffset target[]) { 24 | opc = opc_lookupswitch; 25 | operand = new LookupswitchOperand(this, def, match, target); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/MethodCP.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MethodCP's are used to make references to methods in classes 3 | * 4 | * @author $Author: jonmeyerny $ 5 | * @version $Revision: 1.1 $ 6 | */ 7 | 8 | package jas; 9 | import java.io.*; 10 | 11 | 12 | public class MethodCP extends CP implements RuntimeConstants 13 | { 14 | ClassCP clazz; 15 | NameTypeCP nt; 16 | 17 | /** 18 | * @param cname Class in which method exists 19 | * @param varname name of method 20 | * @param sig Signature of method 21 | */ 22 | public MethodCP(String cname, String varname, String sig) 23 | { 24 | uniq = cname + "&%$91&" + varname + "*(012$" + sig; 25 | clazz = new ClassCP(cname); 26 | nt = new NameTypeCP(varname, sig); 27 | } 28 | 29 | void resolve(ClassEnv e) 30 | { 31 | e.addCPItem(clazz); 32 | e.addCPItem(nt); 33 | } 34 | 35 | void write(ClassEnv e, DataOutputStream out) 36 | throws IOException, jasError 37 | { 38 | out.writeByte(CONSTANT_METHOD); 39 | out.writeShort(e.getCPIndex(clazz)); 40 | out.writeShort(e.getCPIndex(nt)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/MultiarrayInsn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Some instructions are perniticky enough that its simpler 3 | * to write them separately instead of smushing them with 4 | * all the rest. the multiarray instruction is one of them. 5 | * @author $Author: jonmeyerny $ 6 | * @version $Revision: 1.1 $ 7 | */ 8 | 9 | package jas; 10 | 11 | import java.io.*; 12 | 13 | 14 | public class MultiarrayInsn extends Insn implements RuntimeConstants 15 | { 16 | /** 17 | * @param cpe CP item for the array type 18 | * @param sz number of dimensions for the array 19 | */ 20 | public MultiarrayInsn(CP cpe, int sz) 21 | { 22 | opc = opc_multianewarray; 23 | operand = new MultiarrayOperand(cpe, sz); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/NameTypeCP.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Create a name/type entry constant pool entry 3 | * 4 | * @author $Author: jonmeyerny $ 5 | * @version $Revision: 1.1 $ 6 | */ 7 | 8 | package jas; 9 | 10 | import java.io.*; 11 | 12 | 13 | public class NameTypeCP extends CP implements RuntimeConstants 14 | { 15 | AsciiCP name, sig; 16 | 17 | /** 18 | * Name/type entries are used to specify the type associated 19 | * with a symbol name. 20 | * 21 | * @param name Name of symbol 22 | * @param sig Signature of symbol 23 | */ 24 | public NameTypeCP(String name, String sig) 25 | { 26 | uniq = ("NT : @#$%" + name + "SD#$"+ sig).intern(); 27 | this.name = new AsciiCP(name); 28 | this.sig = new AsciiCP(sig); 29 | } 30 | 31 | void resolve(ClassEnv e) 32 | { 33 | e.addCPItem(name); 34 | e.addCPItem(sig); 35 | } 36 | 37 | void write(ClassEnv e, DataOutputStream out) 38 | throws IOException, jasError 39 | { 40 | out.writeByte(CONSTANT_NAMEANDTYPE); 41 | out.writeShort(e.getCPIndex(name)); 42 | out.writeShort(e.getCPIndex(sig)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/SignatureAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This attribute is used to represent the signature of a class, 3 | * field or method 4 | * @author $Author: jonmeyerny $ 5 | * @version $Revision: 1.1 $ 6 | */ 7 | 8 | package jas; 9 | 10 | import java.io.*; 11 | 12 | public class SignatureAttr 13 | { 14 | static final CP attr = new AsciiCP("Signature"); 15 | 16 | CP signature; 17 | 18 | /** 19 | * Create a Signature attribute. 20 | * @param signature The signature of the class, field or method 21 | * @see ClassEnv#setSignature 22 | */ 23 | 24 | public SignatureAttr(String signature) 25 | { this.signature = new AsciiCP(signature); } 26 | 27 | /** 28 | * Create a signature attribute, with more control over attribute name 29 | * @param signature CP to be associated as the signature or the attribute 30 | * @see ClassEnv#setSignature 31 | */ 32 | public SignatureAttr(CP signature) 33 | { this.signature = signature; } 34 | 35 | void resolve(ClassEnv e) 36 | { e.addCPItem(attr); e.addCPItem(signature); } 37 | 38 | void write(ClassEnv e, DataOutputStream out) 39 | throws IOException, jasError 40 | { 41 | out.writeShort(e.getCPIndex(attr)); 42 | out.writeInt(2); 43 | out.writeShort(e.getCPIndex(signature)); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/SourceAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This attribute is used to embed Source file information into 3 | * a class file. 4 | * @author $Author: jonmeyerny $ 5 | * @version $Revision: 1.1 $ 6 | */ 7 | 8 | package jas; 9 | 10 | import java.io.*; 11 | 12 | public class SourceAttr 13 | { 14 | static final CP attr = new AsciiCP("SourceFile"); 15 | 16 | CP name; 17 | 18 | /** 19 | * Create a source file attribute. 20 | * @param name Name of the source file 21 | * @see ClassEnv#setSource 22 | */ 23 | 24 | public SourceAttr(String name) 25 | { this.name = new AsciiCP(name); } 26 | 27 | /** 28 | * Create a source file attribute, with more control over attribute name 29 | * @param name CP to be associated as the name of the source file 30 | * @see ClassEnv#setSource 31 | */ 32 | public SourceAttr(CP name) 33 | { this.name = name; } 34 | 35 | void resolve(ClassEnv e) 36 | { e.addCPItem(attr); e.addCPItem(name); } 37 | 38 | void write(ClassEnv e, DataOutputStream out) 39 | throws IOException, jasError 40 | { 41 | out.writeShort(e.getCPIndex(attr)); 42 | out.writeInt(2); 43 | out.writeShort(e.getCPIndex(name)); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/SourceDebugExtensionAttr.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This attribute is used to embed extended debug information 3 | * @author $Author: Daniel Reynaud $ 4 | * @version $Revision: 1.0 $ 5 | */ 6 | 7 | package jas; 8 | 9 | import java.io.*; 10 | 11 | public class SourceDebugExtensionAttr 12 | { 13 | static final CP attr = new AsciiCP("SourceDebugExtension"); 14 | 15 | String debug; 16 | 17 | /** 18 | * Create a source file attribute. 19 | * @param debug Name of the source file 20 | * @see ClassEnv#setSource 21 | */ 22 | 23 | public SourceDebugExtensionAttr(String debug) 24 | { this.debug = debug; } 25 | 26 | public void append(String debug) 27 | { this.debug += debug; } 28 | 29 | void resolve(ClassEnv e) 30 | { e.addCPItem(attr); } 31 | 32 | void write(ClassEnv e, DataOutputStream out) 33 | throws IOException, jasError 34 | { 35 | out.writeShort(e.getCPIndex(attr)); 36 | 37 | ByteArrayOutputStream buf = new ByteArrayOutputStream(); 38 | DataOutputStream dat = new DataOutputStream(buf); 39 | dat.writeUTF(debug); 40 | 41 | // need to write the length of the attribute first as int 42 | // (writeUTF store it in stream as short) 43 | out.writeShort(0); 44 | // and then write the actual utf8 string 45 | buf.writeTo(out); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/StringCP.java: -------------------------------------------------------------------------------- 1 | package jas; 2 | 3 | import java.io.*; 4 | 5 | 6 | /** 7 | * Wrap an String constant reference with this CPE. 8 | * 9 | * @author $Author: jonmeyerny $ 10 | * @version $Revision: 1.1 $ 11 | */ 12 | 13 | public class StringCP extends CP implements RuntimeConstants 14 | { 15 | AsciiCP val; 16 | 17 | /** 18 | * @param s Value for String constant 19 | */ 20 | public StringCP(String s) 21 | { 22 | uniq = ("String: @#$" + s).intern(); 23 | val = new AsciiCP(s); 24 | } 25 | void resolve(ClassEnv e) { e.addCPItem(val); } 26 | void write(ClassEnv e, DataOutputStream out) 27 | throws IOException, jasError 28 | { 29 | out.writeByte(CONSTANT_STRING); 30 | out.writeShort(e.getCPIndex(val)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/TableswitchInsn.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Some instructions are perniticky enough that its simpler 3 | * to write them separately instead of smushing them with 4 | * all the rest. The tableswitch instruction is one of them. 5 | * @author $Author: jonmeyerny $ 6 | * @version $Revision: 1.1 $ 7 | */ 8 | 9 | package jas; 10 | 11 | import java.io.*; 12 | 13 | 14 | public class TableswitchInsn extends Insn implements RuntimeConstants 15 | { 16 | /** 17 | * @param min minimum index value 18 | * @param max maximum index value 19 | * @param def default Label for switch 20 | * @param j array of Labels, one for each possible index. 21 | */ 22 | 23 | public TableswitchInsn(int min, int max, LabelOrOffset def, LabelOrOffset j[]) 24 | { 25 | opc = opc_tableswitch; 26 | operand = new TableswitchOperand(this, min, max, def, j); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jas/jasError.java: -------------------------------------------------------------------------------- 1 | package jas; 2 | 3 | /** 4 | * Error thrown on problems encountered while running the 5 | * basic jas assembler itself. 6 | * @author $Author: jonmeyerny $ 7 | * @version $Revision: 1.1 $ 8 | */ 9 | 10 | public class jasError extends Exception 11 | { 12 | public boolean numTag; 13 | public jasError() { super(); numTag = false; } 14 | public jasError(String s) { super(s); numTag = false; } 15 | public jasError(String s, boolean isNum) { super(s); numTag = true; } 16 | } 17 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jasmin.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Implementation-Title: Java Runtime Environment 3 | Implementation-Version: 2.4 4 | Main-Class: jasmin.Main 5 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jasmin/num_token.java: -------------------------------------------------------------------------------- 1 | 2 | package jasmin; 3 | import java_cup.*; 4 | 5 | /** This subclass of token represents symbols that need to maintain one 6 | * number value as an attribute. It maintains that value in the public 7 | * field num_val. 8 | * 9 | * @see java_cup.runtime.str_token 10 | * @version last updated: 1/7/96 11 | * @author Jon Meyer 12 | */ 13 | 14 | class num_token extends java_cup.runtime.token { 15 | 16 | /** Full constructor. */ 17 | public num_token(int term_num, Number v) 18 | { 19 | /* super class does most of the work */ 20 | super(term_num); 21 | 22 | num_val = v; 23 | } 24 | 25 | /** Constructor with default value of 0 */ 26 | public num_token(int term_num) 27 | { 28 | this(term_num, new Integer(0)); 29 | } 30 | 31 | /** The stored number reference. */ 32 | public Number num_val; 33 | }; 34 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jasmin/relative_num_token.java: -------------------------------------------------------------------------------- 1 | 2 | package jasmin; 3 | import java_cup.*; 4 | 5 | /** This subclass of token represents numbers beginning with '+' or '-' 6 | * 7 | * @see java_cup.runtime.str_token 8 | * @version last updated: 26/10/05 9 | * @author Jon Meyer 10 | */ 11 | 12 | class relative_num_token extends java_cup.runtime.int_token { 13 | public relative_num_token(int term_num, int v) { 14 | super(term_num, v); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/jasmin/var_token.java: -------------------------------------------------------------------------------- 1 | 2 | package jasmin; 3 | import java_cup.*; 4 | 5 | /** This subclass of token represents symbols that need to maintain one 6 | * number value as an attribute. It maintains that value in the public 7 | * field var_val. 8 | * 9 | * @see java_cup.runtime.str_token 10 | * @version last updated: 1/7/96 11 | * @author Jon Meyer 12 | */ 13 | 14 | class var_token extends java_cup.runtime.token { 15 | 16 | /** Full constructor. */ 17 | public var_token(int term_num, Number v) 18 | { 19 | /* super class does most of the work */ 20 | super(term_num); 21 | 22 | var_val = v; 23 | } 24 | 25 | public var_token(int term_num, String v) 26 | { 27 | /* super class does most of the work */ 28 | super(term_num); 29 | 30 | var_val = v; 31 | } 32 | 33 | /** Constructor with default value of 0 */ 34 | public var_token(int term_num) 35 | { 36 | this(term_num, new Integer(0)); 37 | } 38 | 39 | /** The stored number reference. */ 40 | public Object var_val; 41 | }; 42 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup.mf: -------------------------------------------------------------------------------- 1 | Main-Class: java_cup.Main 2 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/action_production.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup; 3 | 4 | /** A specialized version of a production used when we split an existing 5 | * production in order to remove an embedded action. Here we keep a bit 6 | * of extra bookkeeping so that we know where we came from. 7 | * @version last updated: 11/25/95 8 | * @author Scott Hudson 9 | */ 10 | 11 | public class action_production extends production { 12 | 13 | /** Constructor. 14 | * @param base the production we are being factored out of. 15 | * @param lhs_sym the LHS symbol for this production. 16 | * @param rhs_parts array of production parts for the RHS. 17 | * @param rhs_len how much of the rhs_parts array is valid. 18 | * @param action_str the trailing reduce action for this production. 19 | */ 20 | public action_production( 21 | production base, 22 | non_terminal lhs_sym, 23 | production_part rhs_parts[], 24 | int rhs_len, 25 | String action_str) 26 | throws internal_error 27 | { 28 | super(lhs_sym, rhs_parts, rhs_len, action_str); 29 | _base_production = base; 30 | } 31 | 32 | /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ 33 | 34 | /** The production we were taken out of. */ 35 | protected production _base_production; 36 | 37 | /** The production we were taken out of. */ 38 | public production base_production() {return _base_production;} 39 | }; 40 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/internal_error.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup; 3 | 4 | /** Exception subclass for reporting internal errors in JavaCup. */ 5 | public class internal_error extends Exception 6 | { 7 | /** Constructor with a message */ 8 | public internal_error(String msg) 9 | { 10 | super(msg); 11 | } 12 | 13 | /** Method called to do a forced error exit on an internal error 14 | for cases when we can't actually throw the exception. */ 15 | public void crash() 16 | { 17 | System.err.println("JavaCUP Fatal Internal Error Detected"); 18 | System.err.println(getMessage()); 19 | printStackTrace(); 20 | System.exit(-1); 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/parse_reduce_row.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup; 3 | 4 | /** This class represents one row (corresponding to one machine state) of the 5 | * reduce-goto parse table. 6 | */ 7 | public class parse_reduce_row { 8 | /*-----------------------------------------------------------*/ 9 | /*--- Constructor(s) ----------------------------------------*/ 10 | /*-----------------------------------------------------------*/ 11 | 12 | /** Simple constructor. Note: this should not be used until the number 13 | * of terminals in the grammar has been established. 14 | */ 15 | public parse_reduce_row() 16 | { 17 | /* make sure the size is set */ 18 | if (_size <= 0 ) _size = non_terminal.number(); 19 | 20 | /* allocate the array */ 21 | under_non_term = new lalr_state[size()]; 22 | } 23 | 24 | /*-----------------------------------------------------------*/ 25 | /*--- (Access to) Static (Class) Variables ------------------*/ 26 | /*-----------------------------------------------------------*/ 27 | 28 | /** Number of columns (non terminals) in every row. */ 29 | protected static int _size = 0; 30 | 31 | /** Number of columns (non terminals) in every row. */ 32 | public static int size() {return _size;} 33 | 34 | /*-----------------------------------------------------------*/ 35 | /*--- (Access to) Instance Variables ------------------------*/ 36 | /*-----------------------------------------------------------*/ 37 | 38 | /** Actual entries for the row. */ 39 | public lalr_state under_non_term[]; 40 | }; 41 | 42 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/runtime/char_token.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup.runtime; 3 | 4 | /** This subclass of token represents symbols that need to maintain one 5 | * char value as an attribute. It maintains that value in the public 6 | * field int_val. 7 | * 8 | * @see java_cup.runtime.str_token 9 | * @version last updated: 1/7/96 10 | * @author Scott Hudson 11 | */ 12 | 13 | public class char_token extends token { 14 | 15 | /** Full constructor. */ 16 | public char_token(int term_num, char v) 17 | { 18 | /* super class does most of the work */ 19 | super(term_num); 20 | 21 | char_val = v; 22 | } 23 | 24 | /** Constructor with default value of 0 */ 25 | public char_token(int term_num) 26 | { 27 | this(term_num, '\0'); 28 | } 29 | 30 | /** The stored char value. */ 31 | public char char_val; 32 | }; 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/runtime/double_token.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup.runtime; 3 | 4 | /** This subclass of token represents symbols that need to maintain one 5 | * double value as an attribute. It maintains that value in the public 6 | * field int_val. 7 | * 8 | * @see java_cup.runtime.str_token 9 | * @version last updated: 1/7/96 10 | * @author Scott Hudson 11 | */ 12 | 13 | public class double_token extends token { 14 | 15 | /** Full constructor. */ 16 | public double_token(int term_num, double v) 17 | { 18 | /* super class does most of the work */ 19 | super(term_num); 20 | 21 | double_val = v; 22 | } 23 | 24 | /** Constructor with default value of 0.0. */ 25 | public double_token(int term_num) 26 | { 27 | this(term_num,0.0f); 28 | } 29 | 30 | /** The stored double value. */ 31 | public double double_val; 32 | }; 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/runtime/float_token.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup.runtime; 3 | 4 | /** This subclass of token represents symbols that need to maintain one 5 | * float value as an attribute. It maintains that value in the public 6 | * field int_val. 7 | * 8 | * @see java_cup.runtime.str_token 9 | * @version last updated: 1/7/96 10 | * @author Scott Hudson 11 | */ 12 | 13 | public class float_token extends token { 14 | 15 | /** Full constructor. */ 16 | public float_token(int term_num, float v) 17 | { 18 | /* super class does most of the work */ 19 | super(term_num); 20 | 21 | float_val = v; 22 | } 23 | 24 | /** Constructor with default value of 0.0. */ 25 | public float_token(int term_num) 26 | { 27 | this(term_num,0.0f); 28 | } 29 | 30 | /** The stored float value. */ 31 | public float float_val; 32 | }; 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/runtime/int_token.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup.runtime; 3 | 4 | /** This subclass of token represents symbols that need to maintain one 5 | * int value as an attribute. It maintains that value in the public 6 | * field int_val. 7 | * 8 | * @see java_cup.runtime.str_token 9 | * @version last updated: 11/25/95 10 | * @author Scott Hudson 11 | */ 12 | 13 | public class int_token extends token { 14 | 15 | /** Full constructor. */ 16 | public int_token(int term_num, int iv) 17 | { 18 | /* super class does most of the work */ 19 | super(term_num); 20 | 21 | int_val = iv; 22 | } 23 | 24 | /** Constructor with default value of 0. */ 25 | public int_token(int term_num) 26 | { 27 | this(term_num,0); 28 | } 29 | 30 | /** The stored int value. */ 31 | public int int_val; 32 | }; 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/runtime/long_token.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup.runtime; 3 | 4 | /** This subclass of token represents symbols that need to maintain one 5 | * long value as an attribute. It maintains that value in the public 6 | * field int_val. 7 | * 8 | * @see java_cup.runtime.str_token 9 | * @version last updated: 1/7/96 10 | * @author Scott Hudson 11 | */ 12 | 13 | public class long_token extends token { 14 | 15 | /** Full constructor. */ 16 | public long_token(int term_num, long lv) 17 | { 18 | /* super class does most of the work */ 19 | super(term_num); 20 | 21 | long_val = lv; 22 | } 23 | 24 | /** Constructor with default value of 0. */ 25 | public long_token(int term_num) 26 | { 27 | this(term_num,0); 28 | } 29 | 30 | /** The stored long value. */ 31 | public long long_val; 32 | }; 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/runtime/str_token.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup.runtime; 3 | 4 | /** This subclass of token represents symbols that need to maintain one 5 | * String value as an attribute. It maintains that value in the public 6 | * field str_val. 7 | * 8 | * @see java_cup.runtime.int_token 9 | * @version last updated: 11/25/95 10 | * @author Scott Hudson 11 | */ 12 | 13 | public class str_token extends token { 14 | /** Full constructor. */ 15 | public str_token(int term_num, String v) 16 | { 17 | /* super class does most of the work */ 18 | super(term_num); 19 | 20 | str_val = v; 21 | } 22 | 23 | /** Constructor for value defaulting to an empty string. */ 24 | public str_token(int term_num) 25 | { 26 | this(term_num, ""); 27 | } 28 | 29 | /** The stored string value. */ 30 | public String str_val; 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/runtime/token.java: -------------------------------------------------------------------------------- 1 | 2 | package java_cup.runtime; 3 | 4 | /** This subclass of symbol represents (at least) terminal symbols returned 5 | * by the scanner and placed on the parse stack. At present, this 6 | * class does nothing more than its super class. 7 | * 8 | * @see java_cup.runtime.int_token 9 | * @see java_cup.runtime.str_token 10 | * @version last updated: 11/25/95 11 | * @author Scott Hudson 12 | */ 13 | public class token extends symbol { 14 | 15 | /* Simple constructor -- just delegates to the super class. */ 16 | public token(int term_num) 17 | { 18 | /* super class does all the work */ 19 | super(term_num); 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /tools/jasmin-assembler/src/java_cup/sym.java: -------------------------------------------------------------------------------- 1 | 2 | //---------------------------------------------------- 3 | // The following code was generated by Java(tm) CUP v0.9d 4 | // Thu Aug 10 03:51:39 MSD 2006 5 | //---------------------------------------------------- 6 | 7 | package java_cup; 8 | 9 | /** JavaCup generated class containing symbol constants. */ 10 | public class sym { 11 | /* terminals */ 12 | static final int IMPORT = 3; 13 | static final int INIT = 9; 14 | static final int CODE_STRING = 22; 15 | static final int DEBUG = 20; 16 | static final int SEMI = 13; 17 | static final int STAR = 15; 18 | static final int CODE = 4; 19 | static final int COLON = 17; 20 | static final int NON = 8; 21 | static final int ID = 21; 22 | static final int WITH = 11; 23 | static final int TERMINAL = 7; 24 | static final int COLON_COLON_EQUALS = 18; 25 | static final int COMMA = 14; 26 | static final int EOF = 0; 27 | static final int PARSER = 6; 28 | static final int error = 1; 29 | static final int DOT = 16; 30 | static final int ACTION = 5; 31 | static final int START = 12; 32 | static final int PACKAGE = 2; 33 | static final int BAR = 19; 34 | static final int SCAN = 10; 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /unused/Logger.cpp: -------------------------------------------------------------------------------- 1 | // #include "Logger.hpp" 2 | 3 | // /// spdlog module includes 4 | // #include "spdlog/spdlog.h" 5 | // #include "spdlog/sinks/stdout_color_sinks.h" 6 | 7 | 8 | // Logger::create(const std::string & name, const bool debug_flag) 9 | // { 10 | // // Replaces the default logging format pattern 11 | // static const std::string pattern = "%^[%l]%$ %v"; 12 | // spdlog::set_pattern(pattern); 13 | 14 | // // Create a logger 15 | // std::shared_ptr logger = spdlog::stdout_color_mt("logger"); 16 | 17 | // // Change the logging level 18 | // if (!debug_flag) 19 | // { 20 | // logger->set_level(spdlog::level::info); 21 | // } 22 | // else 23 | // { 24 | // logger->set_level(spdlog::level::debug); 25 | // } 26 | 27 | // return logger; 28 | // } 29 | 30 | // #pragma once 31 | 32 | // #include 33 | 34 | 35 | 36 | // class Logger 37 | // { 38 | 39 | // public: 40 | 41 | // /// Retrieves the singleton pointer 42 | // static Logger & get() 43 | // { 44 | // static Logger logger; 45 | // return logger; 46 | // } 47 | 48 | // private: 49 | 50 | // /// Private constructor 51 | // Logger(); 52 | 53 | // * 54 | // * Factory method for creating a logger object 55 | // * @param name : Name of logger object 56 | // * @param debug_flag : True to set debug level to info, false for all levels 57 | 58 | // void create(const std::string & name, const bool debug_flag); 59 | 60 | // }; 61 | -------------------------------------------------------------------------------- /unused/wci/intermediate/ICode.h: -------------------------------------------------------------------------------- 1 | /** 2 | *

ICode

3 | * 4 | *

The framework interface that represents the intermediate code.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #ifndef WCI_INTERMEDIATE_ICODE_H_ 10 | #define WCI_INTERMEDIATE_ICODE_H_ 11 | 12 | namespace wci { namespace intermediate { 13 | 14 | class ICodeNode; // forward declaration 15 | 16 | class ICode 17 | { 18 | public: 19 | /** 20 | * Destructor. 21 | */ 22 | virtual ~ICode() {}; 23 | 24 | /** 25 | * Get the root node. 26 | * @return the root node. 27 | */ 28 | virtual ICodeNode *get_root() const = 0; 29 | 30 | /** 31 | * Set and return the root node. 32 | * @param node the node to set as root. 33 | * @return the root node. 34 | */ 35 | virtual ICodeNode *set_root(ICodeNode *node) = 0; 36 | }; 37 | 38 | }} // namespace wci::intermediate 39 | 40 | #endif /* WCI_INTERMEDIATE_ICODE_H_ */ 41 | -------------------------------------------------------------------------------- /unused/wci/intermediate/ICodeFactory.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | *

ICodeFactory

3 | * 4 | *

A factory for creating objects that implement the intermediate code.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #include "ICodeFactory.h" 10 | #include "ICode.h" 11 | #include "ICodeNode.h" 12 | #include "icodeimpl/ICodeImpl.h" 13 | #include "icodeimpl/ICodeNodeImpl.h" 14 | 15 | namespace wci { namespace intermediate { 16 | 17 | using namespace wci::intermediate::icodeimpl; 18 | 19 | ICode *ICodeFactory::create_icode() 20 | { 21 | return new ICodeImpl(); 22 | } 23 | 24 | ICodeNode *ICodeFactory::create_icode_node(const ICodeNodeType type) 25 | { 26 | return new ICodeNodeImpl(type); 27 | } 28 | 29 | }} // namespace wci::intermediate 30 | -------------------------------------------------------------------------------- /unused/wci/intermediate/ICodeFactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | *

ICodeFactory

3 | * 4 | *

A factory for creating objects that implement the intermediate code.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #include "ICode.h" 10 | #include "ICodeNode.h" 11 | 12 | #ifndef ICODEFACTORY_H_ 13 | #define ICODEFACTORY_H_ 14 | 15 | namespace wci { namespace intermediate { 16 | 17 | class ICodeFactory 18 | { 19 | public: 20 | /** 21 | * Create and return an intermediate code implementation. 22 | * @return the intermediate code implementation. 23 | */ 24 | static ICode *create_icode(); 25 | 26 | /** 27 | * Create and return a node implementation. 28 | * @param type the node type. 29 | * @return the node implementation. 30 | */ 31 | static ICodeNode *create_icode_node(const ICodeNodeType type); 32 | }; 33 | 34 | }} // namespace wci::intermediate 35 | 36 | #endif /* ICODEFACTORY_H_ */ 37 | -------------------------------------------------------------------------------- /unused/wci/intermediate/SymTabFactory.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | *

SymTabFactory

3 | * 4 | *

A factory for creating objects that implement the symbol table.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #include "SymTabFactory.h" 10 | #include "SymTab.h" 11 | #include "SymTabEntry.h" 12 | #include "SymTabStack.h" 13 | #include "symtabimpl/SymTabImpl.h" 14 | #include "symtabimpl/SymTabEntryImpl.h" 15 | #include "symtabimpl/SymTabStackImpl.h" 16 | 17 | namespace wci { namespace intermediate { 18 | 19 | using namespace std; 20 | using namespace wci::intermediate::symtabimpl; 21 | 22 | SymTabStack *SymTabFactory::create_symtab_stack() 23 | { 24 | return new SymTabStackImpl(); 25 | } 26 | 27 | SymTab *SymTabFactory::create_symtab(int nesting_level) 28 | { 29 | return new SymTabImpl(nesting_level); 30 | } 31 | 32 | SymTabEntry *SymTabFactory::create_symtab_entry(string name, SymTab *symtab) 33 | { 34 | return new SymTabEntryImpl(name, symtab); 35 | } 36 | 37 | }} // namespace wci::intermediate 38 | -------------------------------------------------------------------------------- /unused/wci/intermediate/SymTabFactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | *

SymTabFactory

3 | * 4 | *

A factory for creating objects that implement the symbol table.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #ifndef WCI_INTERMEDIATE_SYMTABFACTORY_CPP_ 10 | #define WCI_INTERMEDIATE_SYMTABFACTORY_CPP_ 11 | 12 | #include "symtabimpl/SymTabImpl.h" 13 | #include "symtabimpl/SymTabEntryImpl.h" 14 | #include "symtabimpl/SymTabStackImpl.h" 15 | 16 | namespace wci { namespace intermediate { 17 | 18 | using namespace std; 19 | 20 | class SymTabFactory 21 | { 22 | public: 23 | /** 24 | * Create and return a symbol table stack implementation. 25 | * @return the symbol table implementation. 26 | */ 27 | static SymTabStack *create_symtab_stack(); 28 | 29 | /** 30 | * Create and return a symbol table implementation. 31 | * @param nesting_level the nesting level. 32 | * @return the symbol table implementation. 33 | */ 34 | static SymTab *create_symtab(int nesting_level); 35 | 36 | /** 37 | * Create and return a symbol table entry implementation. 38 | * @param name the identifier name. 39 | * @param symtab the symbol table that contains this entry. 40 | * @return the symbol table entry implementation. 41 | */ 42 | static SymTabEntry *create_symtab_entry(string name, SymTab *symtab); 43 | }; 44 | 45 | }} // namespace wci::intermediate 46 | 47 | #endif /* WCI_INTERMEDIATE_SYMTABFACTORY_CPP_ */ 48 | -------------------------------------------------------------------------------- /unused/wci/intermediate/TypeFactory.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | *

TypeFactory

3 | * 4 | *

A factory for creating type specifications.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #include 10 | #include "TypeFactory.h" 11 | #include "TypeSpec.h" 12 | #include "typeimpl/TypeSpecImpl.h" 13 | 14 | namespace wci { namespace intermediate { 15 | 16 | using namespace std; 17 | using namespace wci::intermediate::typeimpl; 18 | 19 | TypeSpec *TypeFactory::create_type(const TypeFormImpl form) 20 | { 21 | return new TypeSpecImpl(form); 22 | } 23 | 24 | TypeSpec *TypeFactory::create_string_type(const string value) 25 | { 26 | return new TypeSpecImpl(value); 27 | } 28 | 29 | }} // namespace wci::intermediate 30 | -------------------------------------------------------------------------------- /unused/wci/intermediate/TypeFactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | *

TypeFactory

3 | * 4 | *

A factory for creating type specifications.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #ifndef TYPEFACTORY_H_ 10 | #define TYPEFACTORY_H_ 11 | 12 | #include 13 | #include "TypeSpec.h" 14 | 15 | namespace wci { namespace intermediate { 16 | 17 | using namespace std; 18 | 19 | class TypeFactory 20 | { 21 | public: 22 | /** 23 | * Create a type specification of a given form. 24 | * @param form the form. 25 | * @return the type specification. 26 | */ 27 | static TypeSpec *create_type(const TypeFormImpl form); 28 | 29 | /** 30 | * Create a string type specification. 31 | * @param value the string value. 32 | * @return the type specification. 33 | */ 34 | static TypeSpec *create_string_type(const string value); 35 | }; 36 | 37 | }} // namespace wci::intermediate 38 | 39 | #endif /* TYPEFACTORY_H_ */ 40 | -------------------------------------------------------------------------------- /unused/wci/intermediate/icodeimpl/ICodeImpl.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | *

ICodeImpl

3 | * 4 | *

An implementation of the intermediate code as a parse tree.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #include "ICodeImpl.h" 10 | #include "../ICodeNode.h" 11 | 12 | namespace wci { namespace intermediate { namespace icodeimpl { 13 | 14 | using namespace wci::intermediate; 15 | 16 | ICodeNode *ICodeImpl::get_root() const { return root; } 17 | 18 | ICodeNode *ICodeImpl::set_root(ICodeNode *node) 19 | { 20 | root = node; 21 | return node; 22 | } 23 | 24 | }}} // namespace wci::intermediate::icodeimpl 25 | -------------------------------------------------------------------------------- /unused/wci/intermediate/icodeimpl/ICodeImpl.h: -------------------------------------------------------------------------------- 1 | /** 2 | *

ICodeImpl

3 | * 4 | *

An implementation of the intermediate code as a parse tree.

5 | * 6 | *

Copyright (c) 2017 by Ronald Mak

7 | *

For instructional purposes only. No warranties.

8 | */ 9 | #ifndef ICODEIMPL_H_ 10 | #define ICODEIMPL_H_ 11 | 12 | #include "../ICode.h" 13 | 14 | namespace wci { namespace intermediate { namespace icodeimpl { 15 | 16 | class ICodeImpl : public ICode 17 | { 18 | public: 19 | /** 20 | * Get the root node. 21 | * @return the root node. 22 | */ 23 | ICodeNode *get_root() const; 24 | 25 | /** 26 | * Set and return the root node. 27 | * @param node the node to set as root. 28 | * @return the root node. 29 | */ 30 | ICodeNode *set_root(ICodeNode *node); 31 | 32 | private: 33 | ICodeNode *root; 34 | }; 35 | 36 | }}} // namespace wci::intermediate::icodeimpl 37 | 38 | #endif /* ICODEIMPL_H_ */ 39 | --------------------------------------------------------------------------------