shithub: scc

ref: 9a720370111cf87f4a1a9c2665c5e12f5c04855c
dir: /expr.c/

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

#include "cc.h"
#include "code.h"
#include "tokens.h"
#include "symbol.h"
#include "syntax.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:
		tp = NULL;
	}
	return tp;
}

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

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

	return tp;
}