Commit 40b271a6 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

minor bug fix for fermion operator parser


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent d600bc20
......@@ -68,6 +68,9 @@ void bind_ir(py::module &m) {
py::class_<xacc::CompositeInstruction,
std::shared_ptr<xacc::CompositeInstruction>>(
m, "CompositeInstruction", "")
.def("nParameters", &xacc::CompositeInstruction::nParameters, "")
.def("nLogicalBits", &xacc::CompositeInstruction::nLogicalBits, "")
.def("nPhysicalBits", &xacc::CompositeInstruction::nPhysicalBits, "")
.def("nInstructions", &xacc::CompositeInstruction::nInstructions, "")
.def("getInstruction", &xacc::CompositeInstruction::getInstruction, "")
.def("getInstructions", &xacc::CompositeInstruction::getInstructions, "")
......
......@@ -14,15 +14,17 @@
namespace xacc {
namespace quantum {
void FermionListenerImpl::enterPlusorminus(FermionOperatorParser::PlusorminusContext * ctx) {
void FermionListenerImpl::enterPlusorminus(
FermionOperatorParser::PlusorminusContext *ctx) {
isMinus = ctx->getText() == "-";
}
void FermionListenerImpl::enterTerm(FermionOperatorParser::TermContext * ctx) {
void FermionListenerImpl::enterTerm(FermionOperatorParser::TermContext *ctx) {
// std::cout << "ENTER TERM: " << ctx->getText() << ", " << ctx->fermion().size() << "\n";
// std::cout << "ENTER TERM: " << ctx->getText() << ", " << ctx->fermion().size()
// << "\n";
std::complex<double> coeff(1.0,0.0);
std::complex<double> coeff(1.0, 0.0);
if (ctx->coeff() != nullptr) {
if (ctx->coeff()->complex() != nullptr) {
auto complexAsStr = ctx->coeff()->complex()->getText();
......@@ -36,31 +38,37 @@ void FermionListenerImpl::enterTerm(FermionOperatorParser::TermContext * ctx) {
}
}
if (isMinus) {
coeff *= -1.0;
isMinus=false;
}
if (isMinus) {
coeff *= -1.0;
isMinus=false;
}
Operators term;
for (int i = 0; i < ctx->fermion().size(); i++) {
auto str = ctx->fermion(i)->getText();
auto str = ctx->fermion(i)->getText();
bool creation = false;
if (str.find("^") != std::string::npos) {
creation = true;
}
bool creation = ctx->fermion(i)->op()->carat() != nullptr;
// if (str.find("^") != std::string::npos) {
// creation = true;
// }
term.push_back({std::stoi(ctx->fermion(i)->op()->INT()->getText()), creation});
term.push_back(
{std::stoi(ctx->fermion(i)->op()->INT()->getText()), creation});
// std::cout << "HI: " << ctx->fermion(i)->getText() << ", " << "\n";
// std::cout << "HI: " << ctx->fermion(i)->getText() << ", "
// << "\n";
}
// std::cout << "SIZE OF TERMS: " << term.size() << "\n";
_op += FermionOperator(term, coeff);
// std::cout << _op.toString() << "\n";
// std::cout << "SIZE OF TERMS: " << term.size() << ", " << coeff << "\n";
FermionOperator tmp(term, coeff);
// std::cout << "TMP: " << tmp.toString() << "\n";
// std::cout << "ENTER TERM: " << ctx->getText() << ", " << ctx->fermion().size() << "\n";
_op += tmp;
}
// std::cout << _op.toString() << "\n";
// std::cout << "ENTER TERM: " << ctx->getText() << ", " <<
// ctx->fermion().size() << "\n";
}
}
\ No newline at end of file
} // namespace quantum
} // namespace xacc
\ No newline at end of file
......@@ -106,7 +106,6 @@ const std::string FermionOperator::toString() {
std::vector<int> creations, annhilations;
for (auto &t : ops) {
// std::cout << "tostring " << t.first << ", " << t.second << "\n";
if (t.second) {
creations.push_back(t.first);
} else {
......@@ -114,9 +113,6 @@ const std::string FermionOperator::toString() {
}
}
std::sort(creations.rbegin(), creations.rend());
std::sort(annhilations.rbegin(), annhilations.rend());
for (auto &t : creations) {
s << t << "^" << std::string(" ");
}
......
grammar FermionOperator;
fermionSrc : term(plusorminus term) *;
fermionSrc : term ( plusorminus term ) *;
plusorminus : '+' | '-';
......@@ -8,7 +8,9 @@ term : coeff ? (fermion) *;
fermion : op;
op : INT '^' | INT;
op : INT carat?;
carat : '^';
coeff : complex | real;
......@@ -24,7 +26,7 @@ COMMENT : '#' ~[\r\n] * EOL;
REAL : ('-') ? INT ? '.' INT;
/* Non-negative integer */
INT : ('0'..'9') + ;
INT : ('-') ? ('0'..'9') + ;
/* Strings include numbers and slashes */
......
......@@ -32,6 +32,7 @@ plusorminus
term
fermion
op
carat
coeff
complex
real
......@@ -39,4 +40,4 @@ comment
atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 13, 68, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 3, 2, 3, 2, 3, 2, 3, 2, 7, 2, 25, 10, 2, 12, 2, 14, 2, 28, 11, 2, 3, 3, 3, 3, 3, 4, 5, 4, 33, 10, 4, 3, 4, 7, 4, 36, 10, 4, 12, 4, 14, 4, 39, 11, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 5, 6, 46, 10, 6, 3, 7, 3, 7, 5, 7, 50, 10, 7, 3, 8, 3, 8, 3, 8, 5, 8, 55, 10, 8, 3, 8, 3, 8, 3, 8, 5, 8, 60, 10, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 2, 2, 11, 2, 4, 6, 8, 10, 12, 14, 16, 18, 2, 3, 3, 2, 3, 4, 2, 65, 2, 20, 3, 2, 2, 2, 4, 29, 3, 2, 2, 2, 6, 32, 3, 2, 2, 2, 8, 40, 3, 2, 2, 2, 10, 45, 3, 2, 2, 2, 12, 49, 3, 2, 2, 2, 14, 51, 3, 2, 2, 2, 16, 63, 3, 2, 2, 2, 18, 65, 3, 2, 2, 2, 20, 26, 5, 6, 4, 2, 21, 22, 5, 4, 3, 2, 22, 23, 5, 6, 4, 2, 23, 25, 3, 2, 2, 2, 24, 21, 3, 2, 2, 2, 25, 28, 3, 2, 2, 2, 26, 24, 3, 2, 2, 2, 26, 27, 3, 2, 2, 2, 27, 3, 3, 2, 2, 2, 28, 26, 3, 2, 2, 2, 29, 30, 9, 2, 2, 2, 30, 5, 3, 2, 2, 2, 31, 33, 5, 12, 7, 2, 32, 31, 3, 2, 2, 2, 32, 33, 3, 2, 2, 2, 33, 37, 3, 2, 2, 2, 34, 36, 5, 8, 5, 2, 35, 34, 3, 2, 2, 2, 36, 39, 3, 2, 2, 2, 37, 35, 3, 2, 2, 2, 37, 38, 3, 2, 2, 2, 38, 7, 3, 2, 2, 2, 39, 37, 3, 2, 2, 2, 40, 41, 5, 10, 6, 2, 41, 9, 3, 2, 2, 2, 42, 43, 7, 11, 2, 2, 43, 46, 7, 5, 2, 2, 44, 46, 7, 11, 2, 2, 45, 42, 3, 2, 2, 2, 45, 44, 3, 2, 2, 2, 46, 11, 3, 2, 2, 2, 47, 50, 5, 14, 8, 2, 48, 50, 5, 16, 9, 2, 49, 47, 3, 2, 2, 2, 49, 48, 3, 2, 2, 2, 50, 13, 3, 2, 2, 2, 51, 54, 7, 6, 2, 2, 52, 55, 5, 16, 9, 2, 53, 55, 7, 11, 2, 2, 54, 52, 3, 2, 2, 2, 54, 53, 3, 2, 2, 2, 55, 56, 3, 2, 2, 2, 56, 59, 7, 7, 2, 2, 57, 60, 5, 16, 9, 2, 58, 60, 7, 11, 2, 2, 59, 57, 3, 2, 2, 2, 59, 58, 3, 2, 2, 2, 60, 61, 3, 2, 2, 2, 61, 62, 7, 8, 2, 2, 62, 15, 3, 2, 2, 2, 63, 64, 7, 10, 2, 2, 64, 17, 3, 2, 2, 2, 65, 66, 7, 9, 2, 2, 66, 19, 3, 2, 2, 2, 9, 26, 32, 37, 45, 49, 54, 59]
\ No newline at end of file
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 13, 71, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 3, 2, 3, 2, 3, 2, 3, 2, 7, 2, 27, 10, 2, 12, 2, 14, 2, 30, 11, 2, 3, 3, 3, 3, 3, 4, 5, 4, 35, 10, 4, 3, 4, 7, 4, 38, 10, 4, 12, 4, 14, 4, 41, 11, 4, 3, 5, 3, 5, 3, 6, 3, 6, 5, 6, 47, 10, 6, 3, 7, 3, 7, 3, 8, 3, 8, 5, 8, 53, 10, 8, 3, 9, 3, 9, 3, 9, 5, 9, 58, 10, 9, 3, 9, 3, 9, 3, 9, 5, 9, 63, 10, 9, 3, 9, 3, 9, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 2, 2, 12, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 2, 3, 3, 2, 3, 4, 2, 67, 2, 22, 3, 2, 2, 2, 4, 31, 3, 2, 2, 2, 6, 34, 3, 2, 2, 2, 8, 42, 3, 2, 2, 2, 10, 44, 3, 2, 2, 2, 12, 48, 3, 2, 2, 2, 14, 52, 3, 2, 2, 2, 16, 54, 3, 2, 2, 2, 18, 66, 3, 2, 2, 2, 20, 68, 3, 2, 2, 2, 22, 28, 5, 6, 4, 2, 23, 24, 5, 4, 3, 2, 24, 25, 5, 6, 4, 2, 25, 27, 3, 2, 2, 2, 26, 23, 3, 2, 2, 2, 27, 30, 3, 2, 2, 2, 28, 26, 3, 2, 2, 2, 28, 29, 3, 2, 2, 2, 29, 3, 3, 2, 2, 2, 30, 28, 3, 2, 2, 2, 31, 32, 9, 2, 2, 2, 32, 5, 3, 2, 2, 2, 33, 35, 5, 14, 8, 2, 34, 33, 3, 2, 2, 2, 34, 35, 3, 2, 2, 2, 35, 39, 3, 2, 2, 2, 36, 38, 5, 8, 5, 2, 37, 36, 3, 2, 2, 2, 38, 41, 3, 2, 2, 2, 39, 37, 3, 2, 2, 2, 39, 40, 3, 2, 2, 2, 40, 7, 3, 2, 2, 2, 41, 39, 3, 2, 2, 2, 42, 43, 5, 10, 6, 2, 43, 9, 3, 2, 2, 2, 44, 46, 7, 11, 2, 2, 45, 47, 5, 12, 7, 2, 46, 45, 3, 2, 2, 2, 46, 47, 3, 2, 2, 2, 47, 11, 3, 2, 2, 2, 48, 49, 7, 5, 2, 2, 49, 13, 3, 2, 2, 2, 50, 53, 5, 16, 9, 2, 51, 53, 5, 18, 10, 2, 52, 50, 3, 2, 2, 2, 52, 51, 3, 2, 2, 2, 53, 15, 3, 2, 2, 2, 54, 57, 7, 6, 2, 2, 55, 58, 5, 18, 10, 2, 56, 58, 7, 11, 2, 2, 57, 55, 3, 2, 2, 2, 57, 56, 3, 2, 2, 2, 58, 59, 3, 2, 2, 2, 59, 62, 7, 7, 2, 2, 60, 63, 5, 18, 10, 2, 61, 63, 7, 11, 2, 2, 62, 60, 3, 2, 2, 2, 62, 61, 3, 2, 2, 2, 63, 64, 3, 2, 2, 2, 64, 65, 7, 8, 2, 2, 65, 17, 3, 2, 2, 2, 66, 67, 7, 10, 2, 2, 67, 19, 3, 2, 2, 2, 68, 69, 7, 9, 2, 2, 69, 21, 3, 2, 2, 2, 9, 28, 34, 39, 46, 52, 57, 62]
\ No newline at end of file
......@@ -33,6 +33,9 @@ public:
virtual void enterOp(FermionOperatorParser::OpContext * /*ctx*/) override { }
virtual void exitOp(FermionOperatorParser::OpContext * /*ctx*/) override { }
virtual void enterCarat(FermionOperatorParser::CaratContext * /*ctx*/) override { }
virtual void exitCarat(FermionOperatorParser::CaratContext * /*ctx*/) override { }
virtual void enterCoeff(FermionOperatorParser::CoeffContext * /*ctx*/) override { }
virtual void exitCoeff(FermionOperatorParser::CoeffContext * /*ctx*/) override { }
......
......@@ -102,7 +102,7 @@ FermionOperatorLexer::Initializer::Initializer() {
_serializedATN = {
0x3, 0x608b, 0xa72a, 0x8133, 0xb9ed, 0x417c, 0x3be7, 0x7786, 0x5964,
0x2, 0xd, 0x45, 0x8, 0x1, 0x4, 0x2, 0x9, 0x2, 0x4, 0x3, 0x9, 0x3, 0x4,
0x2, 0xd, 0x48, 0x8, 0x1, 0x4, 0x2, 0x9, 0x2, 0x4, 0x3, 0x9, 0x3, 0x4,
0x4, 0x9, 0x4, 0x4, 0x5, 0x9, 0x5, 0x4, 0x6, 0x9, 0x6, 0x4, 0x7, 0x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, 0x2f, 0x2, 0x2, 0x38, 0x37, 0x3, 0x2, 0x2, 0x2, 0x38, 0x39, 0x3,
0x2, 0x2, 0x2, 0x39, 0x3b, 0x3, 0x2, 0x2, 0x2, 0x3a, 0x3c, 0x4, 0x32,
0x3b, 0x2, 0x3b, 0x3a, 0x3, 0x2, 0x2, 0x2, 0x3c, 0x3d, 0x3, 0x2, 0x2,
0x2, 0x3d, 0x3b, 0x3, 0x2, 0x2, 0x2, 0x3d, 0x3e, 0x3, 0x2, 0x2, 0x2,
0x3e, 0x14, 0x3, 0x2, 0x2, 0x2, 0x3f, 0x40, 0x9, 0x3, 0x2, 0x2, 0x40,
0x41, 0x3, 0x2, 0x2, 0x2, 0x41, 0x42, 0x8, 0xb, 0x2, 0x2, 0x42, 0x16,
0x3, 0x2, 0x2, 0x2, 0x43, 0x45, 0x7, 0xf, 0x2, 0x2, 0x44, 0x43, 0x3,
0x2, 0x2, 0x2, 0x44, 0x45, 0x3, 0x2, 0x2, 0x2, 0x45, 0x46, 0x3, 0x2,
0x2, 0x2, 0x46, 0x47, 0x7, 0xc, 0x2, 0x2, 0x47, 0x18, 0x3, 0x2, 0x2,
0x2, 0x9, 0x2, 0x29, 0x2f, 0x32, 0x38, 0x3d, 0x44, 0x3, 0x8, 0x2, 0x2,
};
atn::ATNDeserializer deserializer;
......
......@@ -47,4 +47,4 @@ mode names:
DEFAULT_MODE
atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 13, 69, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 7, 8, 40, 10, 8, 12, 8, 14, 8, 43, 11, 8, 3, 8, 3, 8, 3, 9, 5, 9, 48, 10, 9, 3, 9, 5, 9, 51, 10, 9, 3, 9, 3, 9, 3, 9, 3, 10, 6, 10, 57, 10, 10, 13, 10, 14, 10, 58, 3, 11, 3, 11, 3, 11, 3, 11, 3, 12, 5, 12, 66, 10, 12, 3, 12, 3, 12, 2, 2, 13, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 3, 2, 4, 4, 2, 12, 12, 15, 15, 5, 2, 11, 12, 15, 15, 34, 34, 2, 73, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 3, 25, 3, 2, 2, 2, 5, 27, 3, 2, 2, 2, 7, 29, 3, 2, 2, 2, 9, 31, 3, 2, 2, 2, 11, 33, 3, 2, 2, 2, 13, 35, 3, 2, 2, 2, 15, 37, 3, 2, 2, 2, 17, 47, 3, 2, 2, 2, 19, 56, 3, 2, 2, 2, 21, 60, 3, 2, 2, 2, 23, 65, 3, 2, 2, 2, 25, 26, 7, 45, 2, 2, 26, 4, 3, 2, 2, 2, 27, 28, 7, 47, 2, 2, 28, 6, 3, 2, 2, 2, 29, 30, 7, 96, 2, 2, 30, 8, 3, 2, 2, 2, 31, 32, 7, 42, 2, 2, 32, 10, 3, 2, 2, 2, 33, 34, 7, 46, 2, 2, 34, 12, 3, 2, 2, 2, 35, 36, 7, 43, 2, 2, 36, 14, 3, 2, 2, 2, 37, 41, 7, 37, 2, 2, 38, 40, 10, 2, 2, 2, 39, 38, 3, 2, 2, 2, 40, 43, 3, 2, 2, 2, 41, 39, 3, 2, 2, 2, 41, 42, 3, 2, 2, 2, 42, 44, 3, 2, 2, 2, 43, 41, 3, 2, 2, 2, 44, 45, 5, 23, 12, 2, 45, 16, 3, 2, 2, 2, 46, 48, 7, 47, 2, 2, 47, 46, 3, 2, 2, 2, 47, 48, 3, 2, 2, 2, 48, 50, 3, 2, 2, 2, 49, 51, 5, 19, 10, 2, 50, 49, 3, 2, 2, 2, 50, 51, 3, 2, 2, 2, 51, 52, 3, 2, 2, 2, 52, 53, 7, 48, 2, 2, 53, 54, 5, 19, 10, 2, 54, 18, 3, 2, 2, 2, 55, 57, 4, 50, 59, 2, 56, 55, 3, 2, 2, 2, 57, 58, 3, 2, 2, 2, 58, 56, 3, 2, 2, 2, 58, 59, 3, 2, 2, 2, 59, 20, 3, 2, 2, 2, 60, 61, 9, 3, 2, 2, 61, 62, 3, 2, 2, 2, 62, 63, 8, 11, 2, 2, 63, 22, 3, 2, 2, 2, 64, 66, 7, 15, 2, 2, 65, 64, 3, 2, 2, 2, 65, 66, 3, 2, 2, 2, 66, 67, 3, 2, 2, 2, 67, 68, 7, 12, 2, 2, 68, 24, 3, 2, 2, 2, 8, 2, 41, 47, 50, 58, 65, 3, 8, 2, 2]
\ No newline at end of file
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 13, 72, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 7, 8, 40, 10, 8, 12, 8, 14, 8, 43, 11, 8, 3, 8, 3, 8, 3, 9, 5, 9, 48, 10, 9, 3, 9, 5, 9, 51, 10, 9, 3, 9, 3, 9, 3, 9, 3, 10, 5, 10, 57, 10, 10, 3, 10, 6, 10, 60, 10, 10, 13, 10, 14, 10, 61, 3, 11, 3, 11, 3, 11, 3, 11, 3, 12, 5, 12, 69, 10, 12, 3, 12, 3, 12, 2, 2, 13, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 3, 2, 4, 4, 2, 12, 12, 15, 15, 5, 2, 11, 12, 15, 15, 34, 34, 2, 77, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 3, 25, 3, 2, 2, 2, 5, 27, 3, 2, 2, 2, 7, 29, 3, 2, 2, 2, 9, 31, 3, 2, 2, 2, 11, 33, 3, 2, 2, 2, 13, 35, 3, 2, 2, 2, 15, 37, 3, 2, 2, 2, 17, 47, 3, 2, 2, 2, 19, 56, 3, 2, 2, 2, 21, 63, 3, 2, 2, 2, 23, 68, 3, 2, 2, 2, 25, 26, 7, 45, 2, 2, 26, 4, 3, 2, 2, 2, 27, 28, 7, 47, 2, 2, 28, 6, 3, 2, 2, 2, 29, 30, 7, 96, 2, 2, 30, 8, 3, 2, 2, 2, 31, 32, 7, 42, 2, 2, 32, 10, 3, 2, 2, 2, 33, 34, 7, 46, 2, 2, 34, 12, 3, 2, 2, 2, 35, 36, 7, 43, 2, 2, 36, 14, 3, 2, 2, 2, 37, 41, 7, 37, 2, 2, 38, 40, 10, 2, 2, 2, 39, 38, 3, 2, 2, 2, 40, 43, 3, 2, 2, 2, 41, 39, 3, 2, 2, 2, 41, 42, 3, 2, 2, 2, 42, 44, 3, 2, 2, 2, 43, 41, 3, 2, 2, 2, 44, 45, 5, 23, 12, 2, 45, 16, 3, 2, 2, 2, 46, 48, 7, 47, 2, 2, 47, 46, 3, 2, 2, 2, 47, 48, 3, 2, 2, 2, 48, 50, 3, 2, 2, 2, 49, 51, 5, 19, 10, 2, 50, 49, 3, 2, 2, 2, 50, 51, 3, 2, 2, 2, 51, 52, 3, 2, 2, 2, 52, 53, 7, 48, 2, 2, 53, 54, 5, 19, 10, 2, 54, 18, 3, 2, 2, 2, 55, 57, 7, 47, 2, 2, 56, 55, 3, 2, 2, 2, 56, 57, 3, 2, 2, 2, 57, 59, 3, 2, 2, 2, 58, 60, 4, 50, 59, 2, 59, 58, 3, 2, 2, 2, 60, 61, 3, 2, 2, 2, 61, 59, 3, 2, 2, 2, 61, 62, 3, 2, 2, 2, 62, 20, 3, 2, 2, 2, 63, 64, 9, 3, 2, 2, 64, 65, 3, 2, 2, 2, 65, 66, 8, 11, 2, 2, 66, 22, 3, 2, 2, 2, 67, 69, 7, 15, 2, 2, 68, 67, 3, 2, 2, 2, 68, 69, 3, 2, 2, 2, 69, 70, 3, 2, 2, 2, 70, 71, 7, 12, 2, 2, 71, 24, 3, 2, 2, 2, 9, 2, 41, 47, 50, 56, 61, 68, 3, 8, 2, 2]
\ No newline at end of file
......@@ -31,6 +31,9 @@ public:
virtual void enterOp(FermionOperatorParser::OpContext *ctx) = 0;
virtual void exitOp(FermionOperatorParser::OpContext *ctx) = 0;
virtual void enterCarat(FermionOperatorParser::CaratContext *ctx) = 0;
virtual void exitCarat(FermionOperatorParser::CaratContext *ctx) = 0;
virtual void enterCoeff(FermionOperatorParser::CoeffContext *ctx) = 0;
virtual void exitCoeff(FermionOperatorParser::CoeffContext *ctx) = 0;
......
......@@ -81,19 +81,19 @@ FermionOperatorParser::FermionSrcContext* FermionOperatorParser::fermionSrc() {
});
try {
enterOuterAlt(_localctx, 1);
setState(18);
setState(20);
term();
setState(24);
setState(26);
_errHandler->sync(this);
_la = _input->LA(1);
while (_la == FermionOperatorParser::T__0
|| _la == FermionOperatorParser::T__1) {
setState(19);
setState(21);
plusorminus();
setState(20);
setState(22);
term();
setState(26);
setState(28);
_errHandler->sync(this);
_la = _input->LA(1);
}
......@@ -141,7 +141,7 @@ FermionOperatorParser::PlusorminusContext* FermionOperatorParser::plusorminus()
});
try {
enterOuterAlt(_localctx, 1);
setState(27);
setState(29);
_la = _input->LA(1);
if (!(_la == FermionOperatorParser::T__0
......@@ -208,23 +208,23 @@ FermionOperatorParser::TermContext* FermionOperatorParser::term() {
});
try {
enterOuterAlt(_localctx, 1);
setState(30);
setState(32);
_errHandler->sync(this);
_la = _input->LA(1);
if (_la == FermionOperatorParser::T__3
|| _la == FermionOperatorParser::REAL) {
setState(29);
setState(31);
coeff();
}
setState(35);
setState(37);
_errHandler->sync(this);
_la = _input->LA(1);
while (_la == FermionOperatorParser::INT) {
setState(32);
setState(34);
fermion();
setState(37);
setState(39);
_errHandler->sync(this);
_la = _input->LA(1);
}
......@@ -275,7 +275,7 @@ FermionOperatorParser::FermionContext* FermionOperatorParser::fermion() {
});
try {
enterOuterAlt(_localctx, 1);
setState(38);
setState(40);
op();
}
......@@ -298,6 +298,10 @@ tree::TerminalNode* FermionOperatorParser::OpContext::INT() {
return getToken(FermionOperatorParser::INT, 0);
}
FermionOperatorParser::CaratContext* FermionOperatorParser::OpContext::carat() {
return getRuleContext<FermionOperatorParser::CaratContext>(0);
}
size_t FermionOperatorParser::OpContext::getRuleIndex() const {
return FermionOperatorParser::RuleOp;
......@@ -318,31 +322,68 @@ void FermionOperatorParser::OpContext::exitRule(tree::ParseTreeListener *listene
FermionOperatorParser::OpContext* FermionOperatorParser::op() {
OpContext *_localctx = _tracker.createInstance<OpContext>(_ctx, getState());
enterRule(_localctx, 8, FermionOperatorParser::RuleOp);
size_t _la = 0;
auto onExit = finally([=] {
exitRule();
});
try {
setState(43);
enterOuterAlt(_localctx, 1);
setState(42);
match(FermionOperatorParser::INT);
setState(44);
_errHandler->sync(this);
switch (getInterpreter<atn::ParserATNSimulator>()->adaptivePredict(_input, 3, _ctx)) {
case 1: {
enterOuterAlt(_localctx, 1);
setState(40);
match(FermionOperatorParser::INT);
setState(41);
match(FermionOperatorParser::T__2);
break;
}
case 2: {
enterOuterAlt(_localctx, 2);
setState(42);
match(FermionOperatorParser::INT);
break;
_la = _input->LA(1);
if (_la == FermionOperatorParser::T__2) {
setState(43);
carat();
}
}
catch (RecognitionException &e) {
_errHandler->reportError(this, e);
_localctx->exception = std::current_exception();
_errHandler->recover(this, _localctx->exception);
}
}
return _localctx;
}
//----------------- CaratContext ------------------------------------------------------------------
FermionOperatorParser::CaratContext::CaratContext(ParserRuleContext *parent, size_t invokingState)
: ParserRuleContext(parent, invokingState) {
}
size_t FermionOperatorParser::CaratContext::getRuleIndex() const {
return FermionOperatorParser::RuleCarat;
}
void FermionOperatorParser::CaratContext::enterRule(tree::ParseTreeListener *listener) {
auto parserListener = dynamic_cast<FermionOperatorListener *>(listener);
if (parserListener != nullptr)
parserListener->enterCarat(this);
}
void FermionOperatorParser::CaratContext::exitRule(tree::ParseTreeListener *listener) {
auto parserListener = dynamic_cast<FermionOperatorListener *>(listener);
if (parserListener != nullptr)
parserListener->exitCarat(this);
}
FermionOperatorParser::CaratContext* FermionOperatorParser::carat() {
CaratContext *_localctx = _tracker.createInstance<CaratContext>(_ctx, getState());
enterRule(_localctx, 10, FermionOperatorParser::RuleCarat);
auto onExit = finally([=] {
exitRule();
});
try {
enterOuterAlt(_localctx, 1);
setState(46);
match(FermionOperatorParser::T__2);
}
catch (RecognitionException &e) {
......@@ -387,25 +428,25 @@ void FermionOperatorParser::CoeffContext::exitRule(tree::ParseTreeListener *list
FermionOperatorParser::CoeffContext* FermionOperatorParser::coeff() {
CoeffContext *_localctx = _tracker.createInstance<CoeffContext>(_ctx, getState());
enterRule(_localctx, 10, FermionOperatorParser::RuleCoeff);
enterRule(_localctx, 12, FermionOperatorParser::RuleCoeff);
auto onExit = finally([=] {
exitRule();
});
try {
setState(47);
setState(50);
_errHandler->sync(this);
switch (_input->LA(1)) {
case FermionOperatorParser::T__3: {
enterOuterAlt(_localctx, 1);
setState(45);
setState(48);
complex();
break;
}
case FermionOperatorParser::REAL: {
enterOuterAlt(_localctx, 2);
setState(46);
setState(49);
real();
break;
}
......@@ -465,26 +506,26 @@ void FermionOperatorParser::ComplexContext::exitRule(tree::ParseTreeListener *li
FermionOperatorParser::ComplexContext* FermionOperatorParser::complex() {
ComplexContext *_localctx = _tracker.createInstance<ComplexContext>(_ctx, getState());
enterRule(_localctx, 12, FermionOperatorParser::RuleComplex);
enterRule(_localctx, 14, FermionOperatorParser::RuleComplex);
auto onExit = finally([=] {
exitRule();
});
try {
enterOuterAlt(_localctx, 1);
setState(49);
match(FermionOperatorParser::T__3);
setState(52);
match(FermionOperatorParser::T__3);
setState(55);
_errHandler->sync(this);
switch (_input->LA(1)) {
case FermionOperatorParser::REAL: {
setState(50);
setState(53);
real();
break;
}
case FermionOperatorParser::INT: {
setState(51);
setState(54);
match(FermionOperatorParser::INT);
break;
}
......@@ -492,19 +533,19 @@ FermionOperatorParser::ComplexContext* FermionOperatorParser::complex() {
default:
throw NoViableAltException(this);
}
setState(54);
match(FermionOperatorParser::T__4);
setState(57);
match(FermionOperatorParser::T__4);
setState(60);
_errHandler->sync(this);
switch (_input->LA(1)) {
case FermionOperatorParser::REAL: {
setState(55);
setState(58);
real();
break;
}
case FermionOperatorParser::INT: {
setState(56);
setState(59);
match(FermionOperatorParser::INT);
break;
}
......@@ -512,7 +553,7 @@ FermionOperatorParser::ComplexContext* FermionOperatorParser::complex() {
default:
throw NoViableAltException(this);
}
setState(59);
setState(62);
match(FermionOperatorParser::T__5);
}
......@@ -554,14 +595,14 @@ void FermionOperatorParser::RealContext::exitRule(tree::ParseTreeListener *liste
FermionOperatorParser::RealContext* FermionOperatorParser::real() {
RealContext *_localctx = _tracker.createInstance<RealContext>(_ctx, getState());
enterRule(_localctx, 14, FermionOperatorParser::RuleReal);
enterRule(_localctx, 16, FermionOperatorParser::RuleReal);
auto onExit = finally([=] {
exitRule();
});
try {
enterOuterAlt(_localctx, 1);
setState(61);
setState(64);
match(FermionOperatorParser::REAL);
}
......@@ -603,14 +644,14 @@ void FermionOperatorParser::CommentContext::exitRule(tree::ParseTreeListener *li
FermionOperatorParser::CommentContext* FermionOperatorParser::comment() {
CommentContext *_localctx = _tracker.createInstance<CommentContext>(_ctx, getState());
enterRule(_localctx, 16, FermionOperatorParser::RuleComment);
enterRule(_localctx, 18, FermionOperatorParser::RuleComment);
auto onExit = finally([=] {
exitRule();
});
try {
enterOuterAlt(_localctx, 1);
setState(63);
setState(66);