The problem occurs when my lexer goes to read in a token:
Code: Select all
while (true) {
auto pos = in.tellg();
std::uint8_t c = 0;
in >> std::noskipws >> c; // problem occurs on this line...
// Figure out what we've got
if (STATE_TBL[c][static_cast<std::uint64_t>(state)] ==
DfaState::Accept ||
!c) {
in.seekg(pos);
if (!trim(str).empty()) {
// Store token...
}
if (c == 0) {
break;
}
str.clear();
prev_state = DfaState::Whitespace;
state = DfaState::Whitespace;
continue;
}
if (STATE_TBL[c][static_cast<std::uint64_t>(state)] ==
DfaState::Error) {
std::stringstream ss;
ss << "Invalid token at position " << in.tellg()
<< ": was parsing char " << unsigned(c) << " in state "
<< unsigned(state) << "; got " << str
<< "\nTransitional state: " << unsigned(c)
<< ", transitions to state "
<< unsigned(STATE_TBL[c][static_cast<std::uint64_t>(state)])
<< " from state " << unsigned(prev_state) << " and "
<< unsigned(state);
throw std::runtime_error(ss.str());
} else {
str += static_cast<unsigned char>(c);
prev_state = state;
state = STATE_TBL[c][static_cast<std::uint64_t>(state)];
}
}
Code: Select all
program code;
Code: Select all
program code;
var x,y,sum:integer;
var A:integer;
procedure SumAvg(P1,P2:integer; var Avg:integer);
var s:integer;
begin
s:=P1+P2;
sum:=s;
Avg:=sum/2;
end;
begin
x:=5;
y:=7;
SumAvg(x,y,A);
end.