12.3 MiniC Grammar for yacc

%union { Symbol *sym; /* symbol table pointer */ Symbol *inst; /* machine instruction */ int narg; /* number of arguments */ } %token <sym>NUMBER STRING PRINT BLTIN UNDEF WHILE FOR IF ELSE %token <sym>FUNCTION PROCEDURE RETURN FUNC PROC READ INT VAR IVAR SVAR END %token <narg>ARG %type <sym> expr %type <inst> stmt asgn prlist stmtlist %type <inst>cond while for if begin end %type <sym>procname %type <narg>arglist %type <sym> dtype %type <sym> dlist %right ‘=’ ADDEQ SUBEQ MULEQ DIVEQ MODEQ %left OR %left AND %left GT GE LT LE EQ NE %left ‘+’ ‘–’ %left ‘*’ ‘/’ ‘%’ %left UNARYMINUS NOT INC DEC %right ‘^’ %% list: stmtlist END | stmtlist error END ; asgn: VAR ‘=’ expr | IVAR ‘=’ expr | IVAR ADDEQ expr | IVAR SUBEQ expr ...

Get Compilers: Principles and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.