代码拉取完成,页面将自动刷新
同步操作将从 ylyhappy/编译原理虎书代码 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* prabsyn.c - Print Abstract Syntax data structures. Most functions
* handle an instance of an abstract syntax rule.
*/
#include "prabsyn.h"
#include "absyn.h"
#include <assert.h>
#include <stdio.h>
/* local function prototypes */
static void pr_yly_var(FILE *out, A_yly_var v, int d);
static void indent(FILE *out, int d) {
int i;
for (i = 0; i <= d; i++)
fprintf(out, " ");
}
static char str_oper[][10] = {"PLUS", "MINUS", "TIMES", "DIVIDE"};
static void pr_yly_oper(FILE *out, A_yly_oper d) { fprintf(out, "%s", str_oper[d]); }
/* Print A_var types. Indent d spaces. */
static void pr_yly_var(FILE *out, A_yly_var v, int d) {
indent(out, d);
switch (v->kind) {
case A_yly_simpleVar:
fprintf(out, "simpleVar(%s)", S_name(v->u.simple));
break;
case A_yly_seqVar:
fprintf(out, "%s", "seqVar(");
for (A_yly_varList i = v->u.seq; i; i = i->next){
pr_yly_var(out, i->data, 0);
fprintf(out, ",");
}
fprintf(out,")");
break;
default:
assert(0);
}
}
void pr_yly_exp(FILE *out, A_yly_exp v, int d) {
indent(out, d);
switch (v->kind) {
case A_yly_assignExp:
fprintf(out, "assignExp(\n");
pr_yly_var(out, v->u.assign.var, d + 1);
fprintf(out, ",\n");
pr_yly_exp(out, v->u.assign.exp, d + 1);
fprintf(out, ")");
break;
case A_yly_intExp:
fprintf(out, "intExp(%d)", v->u.intt);
break;
case A_yly_opExp:
fprintf(out, "opExp(\n");
indent(out, d+1); pr_yly_oper(out, v->u.op.oper); fprintf(out, ",\n");
//assert(v->u.op.left && v->u.op.right);
if (v->u.op.left == NULL && v->u.op.left == NULL) return;
pr_yly_exp(out, v->u.op.left, d+1); fprintf(out, ",\n");
pr_yly_exp(out, v->u.op.right, d+1); fprintf(out, ")");
break;
case A_yly_varExp:
fprintf(out, "varExp(\n"); pr_yly_var(out, v->u.var, d+1);
fprintf(out, "%s", ")");
break;
case A_yly_seqExp:
assert(0);
break;
default:
break;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。