shithub: scc

ref: a8b9e699e5f953f3521cbe2e3e9ad431f307823c
dir: /expr.c/

View raw version
#include <stdint.h>
#include <stdio.h>

#include "cc.h"
#include "code.h"
#include "tokens.h"
#include "symbol.h"


struct ctype *expr(void);

static struct ctype *
primary(void)
{
	register struct ctype *tp;

	switch (yytoken) {
	case IDEN:
		if (yylval.sym == NULL)
			error("'%s' undeclared", yytext);
		emitsym(yylval.sym);
		tp = yylval.sym->type;
		next();
		break;
	case CONSTANT:
		next();
		/* TODO: do something */
		break;
	case '(':
		next();
		tp = expr();
		expect(')');
		break;
	default:
		error("unexpected '%s'", yytoken);
	}
	return tp;
}

static struct ctype *
postfix(void)
{
	struct ctype * tp;

	tp = primary();
}

struct ctype *
expr(void)
{
	register struct ctype *tp;

	do
		tp = postfix();
	while (yytoken == ',');

	return tp;
}