This commit is contained in:
Thomas Lindner 2023-01-06 18:56:53 +01:00
parent c7a4effaab
commit 4f3d1d2f2e
3 changed files with 11 additions and 7 deletions

View file

@ -43,6 +43,7 @@ std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) {
}
if (ctx->If()) {
int block = blockcount++;
output << "@if" << block << "_expr" << std::endl;
tmpcount = 0;
visitCondition(ctx->condition());
@ -60,6 +61,7 @@ std::any EmitVisitor::visitStatement(xlangParser::StatementContext *ctx) {
}
if (ctx->While()) {
int block = blockcount++;
output << "@while" << block << "_expr" << std::endl;
tmpcount = 0;
visitCondition(ctx->condition());
@ -115,12 +117,6 @@ std::any EmitVisitor::visitBoolean(xlangParser::BooleanContext *ctx) {
output << " " << tmp() << " = w xor 1, " << b << std::endl;
return {};
}
OPERATOR(Less, visitExpr, expr(0), visitExpr, expr(1), "csltw");
OPERATOR(LessEqual, visitExpr, expr(0), visitExpr, expr(1), "cslew");
OPERATOR(Greater, visitExpr, expr(0), visitExpr, expr(1), "csgtw");
OPERATOR(GreaterEqual, visitExpr, expr(0), visitExpr, expr(1), "csgew");
OPERATOR(Equal, visitExpr, expr(0), visitExpr, expr(1), "ceqw");
OPERATOR(NotEqual, visitExpr, expr(0), visitExpr, expr(1), "cnew");
if (ctx->True()) {
last = "1";
return {};
@ -129,6 +125,12 @@ std::any EmitVisitor::visitBoolean(xlangParser::BooleanContext *ctx) {
last = "0";
return {};
}
OPERATOR(Less, visitExpr, expr(0), visitExpr, expr(1), "csltw");
OPERATOR(LessEqual, visitExpr, expr(0), visitExpr, expr(1), "cslew");
OPERATOR(Greater, visitExpr, expr(0), visitExpr, expr(1), "csgtw");
OPERATOR(GreaterEqual, visitExpr, expr(0), visitExpr, expr(1), "csgew");
OPERATOR(Equal, visitExpr, expr(0), visitExpr, expr(1), "ceqw");
OPERATOR(NotEqual, visitExpr, expr(0), visitExpr, expr(1), "cnew");
visitChildren(ctx);
return {};
}
@ -178,6 +180,7 @@ std::any EmitVisitor::visitVariable(xlangParser::VariableContext *ctx) {
if (ctx->LeftParen()) {
std::vector<std::string> args;
if (auto arg_list = ctx->argumentList()) {
for (auto value : arg_list->value()) {
visitValue(value);

View file

@ -21,6 +21,7 @@ std::any TypeCheckVisitor::visitFile(xlangParser::FileContext *ctx) {
for (auto function : ctx->function()) {
auto token = function->Identifier()->getSymbol();
auto name = token->getText();
if (function_arity.find(name) != function_arity.end()) {
errorlistener.typeError(token->getLine(), token->getCharPositionInLine(),
"duplicate function '" + name + "'");

View file

@ -17,9 +17,9 @@ condition : condition (And|Or|Xor) boolean
| boolean
;
boolean : Not boolean
| expr (Less|LessEqual|Greater|GreaterEqual|Equal|NotEqual) expr
| True
| False
| expr (Less|LessEqual|Greater|GreaterEqual|Equal|NotEqual) expr
| variable
| LeftParen condition RightParen
;