#include "AST.h"
#include "Parser.h"
#include "ParserIdDef.h"
#include "Scanner.h"
#include <iostream>
#include <sstream>
int main()
{
std::string line;
while (std::cerr <<"Q: ", std::getline(std::cin, line))
{
if (line.empty())
break;
std::ostringstream err_out;
C_Parser parser{err_out};
C_Scanner scanner{screener};
if (const auto err_str = err_out.str(); !err_str.empty())
{
std::cerr <<err_str <<"Fail to parse!\n";
continue;
}
bool accepted{};
parser.eachAccepted([&](auto &p){
if (!accepted)
{
accepted = true;
std::cerr <<"A:\n";
}
auto &decl = dynamic_cast<const C_TypeDecl&>(*p);
std::cerr <<decl.m_name <<" = ";
{
const char *prepend = "(";
for (auto &i: *idList)
{
std::cerr <<prepend <<i;
prepend = ", ";
}
std::cerr <<")\n";
}
else if (auto expr = dynamic_cast<const C_BinaryOp*>(decl.m_type.get()))
std::cerr <<expr->toStr() <<'\n';
else if (decl.m_type)
std::cerr <<
"Unknown type: " <<
HRTN(*decl.m_type) <<
'\n';
else
std::cerr <<"nullptr\n";
});
if (!accepted)
std::cerr <<"Incomplete expression!\n";
}
std::cerr <<"Mission complete!\n";
}
{
if (auto expr = dynamic_cast<const C_BinaryOp*>(term.get()))
return expr->toStr();
return *id;
return '(' + toStr(*paren) + ')';
return "Unknown " +
HRTN(*term);
}
std::string C_BinaryOp::toStr() const
{
return '{' + ::toStr(m_lexpr) + m_op + ::toStr(m_rexpr) + '}';
}
std::shared_ptr< const I_LexAttr > C_LexPtr
T_CoConst< T_Data, T_Lex > * tryUnlex(const C_Ptr< T_Lex > &lex)
void scanFile(std::string_view filename, std::istream &in, I_Scanner< T_Char > &scanner, T_LexID endToken=TID_EOF, T_Encoding encoding=0)