add antlr

This commit is contained in:
2020-09-29 23:16:42 +05:30
parent 34754a7130
commit 2b36e74ff5
181 changed files with 14689 additions and 7 deletions

14
lib/generated/bf.tokens Normal file
View File

@@ -0,0 +1,14 @@
COMMENT=1
INPUT=2
OUTPUT=3
DEC=4
INC=5
LEFT=6
RIGHT=7
'\\\\.*?\\\\'=1
'?'=2
'.'=3
'-'=4
'+'=5
'>'=6
'<'=7

View File

@@ -0,0 +1,7 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#include "bfBaseListener.h"

View File

@@ -0,0 +1,32 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#pragma once
#include "antlr4-runtime.h"
#include "bfListener.h"
/**
* This class provides an empty implementation of bfListener,
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
class bfBaseListener : public bfListener {
public:
virtual void enterProgram(bfParser::ProgramContext * /*ctx*/) override { }
virtual void exitProgram(bfParser::ProgramContext * /*ctx*/) override { }
virtual void enterStatements(bfParser::StatementsContext * /*ctx*/) override { }
virtual void exitStatements(bfParser::StatementsContext * /*ctx*/) override { }
virtual void enterEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { }
virtual void exitEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { }
virtual void visitTerminal(antlr4::tree::TerminalNode * /*node*/) override { }
virtual void visitErrorNode(antlr4::tree::ErrorNode * /*node*/) override { }
};

View File

@@ -0,0 +1,7 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#include "bfBaseVisitor.h"

View File

@@ -0,0 +1,28 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#pragma once
#include "antlr4-runtime.h"
#include "bfVisitor.h"
/**
* This class provides an empty implementation of bfVisitor, which can be
* extended to create a visitor which only needs to handle a subset of the available methods.
*/
class bfBaseVisitor : public bfVisitor {
public:
virtual antlrcpp::Any visitProgram(bfParser::ProgramContext *ctx) override {
return visitChildren(ctx);
}
virtual antlrcpp::Any visitStatements(bfParser::StatementsContext *ctx) override {
return visitChildren(ctx);
}
};

139
lib/generated/bfLexer.cpp Normal file
View File

@@ -0,0 +1,139 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#include "bfLexer.h"
using namespace antlr4;
bfLexer::bfLexer(CharStream *input) : Lexer(input) {
_interpreter = new atn::LexerATNSimulator(this, _atn, _decisionToDFA, _sharedContextCache);
}
bfLexer::~bfLexer() {
delete _interpreter;
}
std::string bfLexer::getGrammarFileName() const {
return "bf.g4";
}
const std::vector<std::string>& bfLexer::getRuleNames() const {
return _ruleNames;
}
const std::vector<std::string>& bfLexer::getChannelNames() const {
return _channelNames;
}
const std::vector<std::string>& bfLexer::getModeNames() const {
return _modeNames;
}
const std::vector<std::string>& bfLexer::getTokenNames() const {
return _tokenNames;
}
dfa::Vocabulary& bfLexer::getVocabulary() const {
return _vocabulary;
}
const std::vector<uint16_t> bfLexer::getSerializedATN() const {
return _serializedATN;
}
const atn::ATN& bfLexer::getATN() const {
return _atn;
}
// Static vars and initialization.
std::vector<dfa::DFA> bfLexer::_decisionToDFA;
atn::PredictionContextCache bfLexer::_sharedContextCache;
// We own the ATN which in turn owns the ATN states.
atn::ATN bfLexer::_atn;
std::vector<uint16_t> bfLexer::_serializedATN;
std::vector<std::string> bfLexer::_ruleNames = {
u8"COMMENT", u8"INPUT", u8"OUTPUT", u8"DEC", u8"INC", u8"LEFT", u8"RIGHT"
};
std::vector<std::string> bfLexer::_channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
std::vector<std::string> bfLexer::_modeNames = {
u8"DEFAULT_MODE"
};
std::vector<std::string> bfLexer::_literalNames = {
"", u8"'\\\\.*?\\\\'", u8"'?'", u8"'.'", u8"'-'", u8"'+'", u8"'>'", u8"'<'"
};
std::vector<std::string> bfLexer::_symbolicNames = {
"", u8"COMMENT", u8"INPUT", u8"OUTPUT", u8"DEC", u8"INC", u8"LEFT", u8"RIGHT"
};
dfa::Vocabulary bfLexer::_vocabulary(_literalNames, _symbolicNames);
std::vector<std::string> bfLexer::_tokenNames;
bfLexer::Initializer::Initializer() {
// This code could be in a static initializer lambda, but VS doesn't allow access to private class members from there.
for (size_t i = 0; i < _symbolicNames.size(); ++i) {
std::string name = _vocabulary.getLiteralName(i);
if (name.empty()) {
name = _vocabulary.getSymbolicName(i);
}
if (name.empty()) {
_tokenNames.push_back("<INVALID>");
} else {
_tokenNames.push_back(name);
}
}
_serializedATN = {
0x3, 0x608b, 0xa72a, 0x8133, 0xb9ed, 0x417c, 0x3be7, 0x7786, 0x5964,
0x2, 0x9, 0x27, 0x8, 0x1, 0x4, 0x2, 0x9, 0x2, 0x4, 0x3, 0x9, 0x3, 0x4,
0x4, 0x9, 0x4, 0x4, 0x5, 0x9, 0x5, 0x4, 0x6, 0x9, 0x6, 0x4, 0x7, 0x9,
0x7, 0x4, 0x8, 0x9, 0x8, 0x3, 0x2, 0x3, 0x2, 0x3, 0x2, 0x3, 0x2, 0x3,
0x2, 0x3, 0x2, 0x3, 0x2, 0x3, 0x2, 0x3, 0x2, 0x3, 0x2, 0x3, 0x3, 0x3,
0x3, 0x3, 0x4, 0x3, 0x4, 0x3, 0x5, 0x3, 0x5, 0x3, 0x6, 0x3, 0x6, 0x3,
0x7, 0x3, 0x7, 0x3, 0x8, 0x3, 0x8, 0x2, 0x2, 0x9, 0x3, 0x3, 0x5, 0x4,
0x7, 0x5, 0x9, 0x6, 0xb, 0x7, 0xd, 0x8, 0xf, 0x9, 0x3, 0x2, 0x2, 0x2,
0x26, 0x2, 0x3, 0x3, 0x2, 0x2, 0x2, 0x2, 0x5, 0x3, 0x2, 0x2, 0x2, 0x2,
0x7, 0x3, 0x2, 0x2, 0x2, 0x2, 0x9, 0x3, 0x2, 0x2, 0x2, 0x2, 0xb, 0x3,
0x2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(_serializedATN);
size_t count = _atn.getNumberOfDecisions();
_decisionToDFA.reserve(count);
for (size_t i = 0; i < count; i++) {
_decisionToDFA.emplace_back(_atn.getDecisionState(i), i);
}
}
bfLexer::Initializer bfLexer::_init;

56
lib/generated/bfLexer.h Normal file
View File

@@ -0,0 +1,56 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#pragma once
#include "antlr4-runtime.h"
class bfLexer : public antlr4::Lexer {
public:
enum {
COMMENT = 1, INPUT = 2, OUTPUT = 3, DEC = 4, INC = 5, LEFT = 6, RIGHT = 7
};
bfLexer(antlr4::CharStream *input);
~bfLexer();
virtual std::string getGrammarFileName() const override;
virtual const std::vector<std::string>& getRuleNames() const override;
virtual const std::vector<std::string>& getChannelNames() const override;
virtual const std::vector<std::string>& getModeNames() const override;
virtual const std::vector<std::string>& getTokenNames() const override; // deprecated, use vocabulary instead
virtual antlr4::dfa::Vocabulary& getVocabulary() const override;
virtual const std::vector<uint16_t> getSerializedATN() const override;
virtual const antlr4::atn::ATN& getATN() const override;
private:
static std::vector<antlr4::dfa::DFA> _decisionToDFA;
static antlr4::atn::PredictionContextCache _sharedContextCache;
static std::vector<std::string> _ruleNames;
static std::vector<std::string> _tokenNames;
static std::vector<std::string> _channelNames;
static std::vector<std::string> _modeNames;
static std::vector<std::string> _literalNames;
static std::vector<std::string> _symbolicNames;
static antlr4::dfa::Vocabulary _vocabulary;
static antlr4::atn::ATN _atn;
static std::vector<uint16_t> _serializedATN;
// Individual action functions triggered by action() above.
// Individual semantic predicate functions triggered by sempred() above.
struct Initializer {
Initializer();
};
static Initializer _init;
};

View File

@@ -0,0 +1,14 @@
COMMENT=1
INPUT=2
OUTPUT=3
DEC=4
INC=5
LEFT=6
RIGHT=7
'\\\\.*?\\\\'=1
'?'=2
'.'=3
'-'=4
'+'=5
'>'=6
'<'=7

View File

@@ -0,0 +1,7 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#include "bfListener.h"

View File

@@ -0,0 +1,25 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#pragma once
#include "antlr4-runtime.h"
#include "bfParser.h"
/**
* This interface defines an abstract listener for a parse tree produced by bfParser.
*/
class bfListener : public antlr4::tree::ParseTreeListener {
public:
virtual void enterProgram(bfParser::ProgramContext *ctx) = 0;
virtual void exitProgram(bfParser::ProgramContext *ctx) = 0;
virtual void enterStatements(bfParser::StatementsContext *ctx) = 0;
virtual void exitStatements(bfParser::StatementsContext *ctx) = 0;
};

231
lib/generated/bfParser.cpp Normal file
View File

@@ -0,0 +1,231 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#include "bfListener.h"
#include "bfVisitor.h"
#include "bfParser.h"
using namespace antlrcpp;
using namespace antlr4;
bfParser::bfParser(TokenStream *input) : Parser(input) {
_interpreter = new atn::ParserATNSimulator(this, _atn, _decisionToDFA, _sharedContextCache);
}
bfParser::~bfParser() {
delete _interpreter;
}
std::string bfParser::getGrammarFileName() const {
return "bf.g4";
}
const std::vector<std::string>& bfParser::getRuleNames() const {
return _ruleNames;
}
dfa::Vocabulary& bfParser::getVocabulary() const {
return _vocabulary;
}
//----------------- ProgramContext ------------------------------------------------------------------
bfParser::ProgramContext::ProgramContext(ParserRuleContext *parent, size_t invokingState)
: ParserRuleContext(parent, invokingState) {
}
bfParser::StatementsContext* bfParser::ProgramContext::statements() {
return getRuleContext<bfParser::StatementsContext>(0);
}
size_t bfParser::ProgramContext::getRuleIndex() const {
return bfParser::RuleProgram;
}
void bfParser::ProgramContext::enterRule(tree::ParseTreeListener *listener) {
auto parserListener = dynamic_cast<bfListener *>(listener);
if (parserListener != nullptr)
parserListener->enterProgram(this);
}
void bfParser::ProgramContext::exitRule(tree::ParseTreeListener *listener) {
auto parserListener = dynamic_cast<bfListener *>(listener);
if (parserListener != nullptr)
parserListener->exitProgram(this);
}
antlrcpp::Any bfParser::ProgramContext::accept(tree::ParseTreeVisitor *visitor) {
if (auto parserVisitor = dynamic_cast<bfVisitor*>(visitor))
return parserVisitor->visitProgram(this);
else
return visitor->visitChildren(this);
}
bfParser::ProgramContext* bfParser::program() {
ProgramContext *_localctx = _tracker.createInstance<ProgramContext>(_ctx, getState());
enterRule(_localctx, 0, bfParser::RuleProgram);
auto onExit = finally([=] {
exitRule();
});
try {
enterOuterAlt(_localctx, 1);
setState(4);
statements();
}
catch (RecognitionException &e) {
_errHandler->reportError(this, e);
_localctx->exception = std::current_exception();
_errHandler->recover(this, _localctx->exception);
}
return _localctx;
}
//----------------- StatementsContext ------------------------------------------------------------------
bfParser::StatementsContext::StatementsContext(ParserRuleContext *parent, size_t invokingState)
: ParserRuleContext(parent, invokingState) {
}
tree::TerminalNode* bfParser::StatementsContext::INC() {
return getToken(bfParser::INC, 0);
}
tree::TerminalNode* bfParser::StatementsContext::DEC() {
return getToken(bfParser::DEC, 0);
}
tree::TerminalNode* bfParser::StatementsContext::INPUT() {
return getToken(bfParser::INPUT, 0);
}
tree::TerminalNode* bfParser::StatementsContext::OUTPUT() {
return getToken(bfParser::OUTPUT, 0);
}
size_t bfParser::StatementsContext::getRuleIndex() const {
return bfParser::RuleStatements;
}
void bfParser::StatementsContext::enterRule(tree::ParseTreeListener *listener) {
auto parserListener = dynamic_cast<bfListener *>(listener);
if (parserListener != nullptr)
parserListener->enterStatements(this);
}
void bfParser::StatementsContext::exitRule(tree::ParseTreeListener *listener) {
auto parserListener = dynamic_cast<bfListener *>(listener);
if (parserListener != nullptr)
parserListener->exitStatements(this);
}
antlrcpp::Any bfParser::StatementsContext::accept(tree::ParseTreeVisitor *visitor) {
if (auto parserVisitor = dynamic_cast<bfVisitor*>(visitor))
return parserVisitor->visitStatements(this);
else
return visitor->visitChildren(this);
}
bfParser::StatementsContext* bfParser::statements() {
StatementsContext *_localctx = _tracker.createInstance<StatementsContext>(_ctx, getState());
enterRule(_localctx, 2, bfParser::RuleStatements);
size_t _la = 0;
auto onExit = finally([=] {
exitRule();
});
try {
enterOuterAlt(_localctx, 1);
setState(6);
_la = _input->LA(1);
if (!((((_la & ~ 0x3fULL) == 0) &&
((1ULL << _la) & ((1ULL << bfParser::INPUT)
| (1ULL << bfParser::OUTPUT)
| (1ULL << bfParser::DEC)
| (1ULL << bfParser::INC))) != 0))) {
_errHandler->recoverInline(this);
}
else {
_errHandler->reportMatch(this);
consume();
}
}
catch (RecognitionException &e) {
_errHandler->reportError(this, e);
_localctx->exception = std::current_exception();
_errHandler->recover(this, _localctx->exception);
}
return _localctx;
}
// Static vars and initialization.
std::vector<dfa::DFA> bfParser::_decisionToDFA;
atn::PredictionContextCache bfParser::_sharedContextCache;
// We own the ATN which in turn owns the ATN states.
atn::ATN bfParser::_atn;
std::vector<uint16_t> bfParser::_serializedATN;
std::vector<std::string> bfParser::_ruleNames = {
"program", "statements"
};
std::vector<std::string> bfParser::_literalNames = {
"", "'\\\\.*?\\\\'", "'?'", "'.'", "'-'", "'+'", "'>'", "'<'"
};
std::vector<std::string> bfParser::_symbolicNames = {
"", "COMMENT", "INPUT", "OUTPUT", "DEC", "INC", "LEFT", "RIGHT"
};
dfa::Vocabulary bfParser::_vocabulary(_literalNames, _symbolicNames);
std::vector<std::string> bfParser::_tokenNames;
bfParser::Initializer::Initializer() {
for (size_t i = 0; i < _symbolicNames.size(); ++i) {
std::string name = _vocabulary.getLiteralName(i);
if (name.empty()) {
name = _vocabulary.getSymbolicName(i);
}
if (name.empty()) {
_tokenNames.push_back("<INVALID>");
} else {
_tokenNames.push_back(name);
}
}
_serializedATN = {
0x3, 0x608b, 0xa72a, 0x8133, 0xb9ed, 0x417c, 0x3be7, 0x7786, 0x5964,
0x3, 0x9, 0xb, 0x4, 0x2, 0x9, 0x2, 0x4, 0x3, 0x9, 0x3, 0x3, 0x2, 0x3,
0x2, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x2, 0x2, 0x4, 0x2, 0x4, 0x2, 0x3,
0x3, 0x2, 0x4, 0x7, 0x2, 0x8, 0x2, 0x6, 0x3, 0x2, 0x2, 0x2, 0x4, 0x8,
0x3, 0x2, 0x2, 0x2, 0x6, 0x7, 0x5, 0x4, 0x3, 0x2, 0x7, 0x3, 0x3, 0x2,
0x2, 0x2, 0x8, 0x9, 0x9, 0x2, 0x2, 0x2, 0x9, 0x5, 0x3, 0x2, 0x2, 0x2,
0x2,
};
atn::ATNDeserializer deserializer;
_atn = deserializer.deserialize(_serializedATN);
size_t count = _atn.getNumberOfDecisions();
_decisionToDFA.reserve(count);
for (size_t i = 0; i < count; i++) {
_decisionToDFA.emplace_back(_atn.getDecisionState(i), i);
}
}
bfParser::Initializer bfParser::_init;

87
lib/generated/bfParser.h Normal file
View File

@@ -0,0 +1,87 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#pragma once
#include "antlr4-runtime.h"
class bfParser : public antlr4::Parser {
public:
enum {
COMMENT = 1, INPUT = 2, OUTPUT = 3, DEC = 4, INC = 5, LEFT = 6, RIGHT = 7
};
enum {
RuleProgram = 0, RuleStatements = 1
};
bfParser(antlr4::TokenStream *input);
~bfParser();
virtual std::string getGrammarFileName() const override;
virtual const antlr4::atn::ATN& getATN() const override { return _atn; };
virtual const std::vector<std::string>& getTokenNames() const override { return _tokenNames; }; // deprecated: use vocabulary instead.
virtual const std::vector<std::string>& getRuleNames() const override;
virtual antlr4::dfa::Vocabulary& getVocabulary() const override;
class ProgramContext;
class StatementsContext;
class ProgramContext : public antlr4::ParserRuleContext {
public:
ProgramContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
StatementsContext *statements();
virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
};
ProgramContext* program();
class StatementsContext : public antlr4::ParserRuleContext {
public:
StatementsContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
antlr4::tree::TerminalNode *INC();
antlr4::tree::TerminalNode *DEC();
antlr4::tree::TerminalNode *INPUT();
antlr4::tree::TerminalNode *OUTPUT();
virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override;
virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override;
virtual antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor *visitor) override;
};
StatementsContext* statements();
private:
static std::vector<antlr4::dfa::DFA> _decisionToDFA;
static antlr4::atn::PredictionContextCache _sharedContextCache;
static std::vector<std::string> _ruleNames;
static std::vector<std::string> _tokenNames;
static std::vector<std::string> _literalNames;
static std::vector<std::string> _symbolicNames;
static antlr4::dfa::Vocabulary _vocabulary;
static antlr4::atn::ATN _atn;
static std::vector<uint16_t> _serializedATN;
struct Initializer {
Initializer();
};
static Initializer _init;
};

View File

@@ -0,0 +1,7 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#include "bfVisitor.h"

28
lib/generated/bfVisitor.h Normal file
View File

@@ -0,0 +1,28 @@
// Generated from /home/atreya/Documents/Projects/Miscellaneous/bfc/grammar/bf.g4 by ANTLR 4.8
#pragma once
#include "antlr4-runtime.h"
#include "bfParser.h"
/**
* This class defines an abstract visitor for a parse tree
* produced by bfParser.
*/
class bfVisitor : public antlr4::tree::AbstractParseTreeVisitor {
public:
/**
* Visit parse trees produced by bfParser.
*/
virtual antlrcpp::Any visitProgram(bfParser::ProgramContext *context) = 0;
virtual antlrcpp::Any visitStatements(bfParser::StatementsContext *context) = 0;
};