#include #include "expr.h" #include "finalize.h" #include "sym.h" int main(void) { SymAdd(UStrAdd("x")); struct Expr *x = newIdentifierExpr(UStrAdd("x")); SymAdd(UStrAdd("y")); struct Expr *y = newIdentifierExpr(UStrAdd("y")); struct Expr *val1 = newUnsignedLiteralExpr(1); struct Expr *val2 = newUnsignedLiteralExpr(2); struct Expr *val42 = newUnsignedLiteralExpr(42); struct Expr *sum1 = newBinaryExpr(EK_ADD, x, val42); struct Expr *sum2 = newBinaryExpr(EK_ADD, y, val1); struct Expr *assign1 = newBinaryExpr(EK_ASSIGN, y, sum1); struct Expr *assign2 = newBinaryExpr(EK_ASSIGN, sum2, val2); printExprTree(assign1, stderr); printExprTree(assign2, stderr); if (isLValueExpr(y)) { printf("assign1 = %lf\n", evalExpr(assign1)); } else { printf("Lvalue expected\n"); } if (isLValueExpr(sum2)) { printf("assign2 = %lf\n", evalExpr(assign2)); } else { printf("Lvalue expected\n"); } finalize(); }