










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











2
4
5
7
8
YACC file for a calculator
%token NUMBER LPAREN RPAREN %token PLUS MINUS TIMES DIVIDE %% expr : expr PLUS expr | expr MINUS expr | expr TIMES expr | expr DIVIDE expr | LPAREN expr RPAREN | MINUS expr | NUMBER ; %%
10
struct and union
struct rec { int x; // 4 bytes double y; // 8 bytes char c; // 1 byte } v, w;
sizeof v: 13 bytes, sizeof w: 13 bytes
v.x = 10; v.y = 0.345; v.c = ‘#’; w.x = 20; w.y = 24.05; w.c = ‘$’;
11
struct and union
struct rec { int x; // 4 bytes double y; // 8 bytes char c; // 1 byte } v, w;
sizeof v: 13 bytes, sizeof w: 13 bytes
v.x = 10; v.y = 0.345; v.c = ‘#’; w.x = 20; w.y = 24.05; w.c = ‘$’;
13
struct and union
union urec { int x; // 4 bytes double y; // 8 bytes char c; // 1 byte } v, w;
sizeof v: 8 bytes, sizeof w: 8 bytes
assign to one of the 3 fields v.x, v.y, or v.c
14
struct and union
union urec { int x; // 4 bytes double y; // 8 bytes char c; // 1 byte } v, w;
sizeof v: 8 bytes, sizeof w: 8 bytes
assign to one of the 3 fields v.x, v.y, or v.c
16
struct
struct rec { int x; double y; char c; } v;
c ( 1 byte )
y ( 8 bytes )
x ( 4 bytes )
17
8 bytes
union
union urec { int x; double y; char c; } v;
c ( 1 byte )
y ( 8 bytes )
x ( 4 bytes )