Semantic Analysis · Compiler Design

Symbol Attributes

Watch lectures

Symbol Attributes

1. What They Are

Symbol attributes are the fields stored per identifier: everything later phases need to know without re-scanning source.

2. Standard Attribute Set

Attribute Meaning / Example
name lexeme string ("position")
kind var, func, type, const, param
type int, float, array(int,10), pointer, struct
scope / level nesting depth, owner function
offset / address frame offset (e.g. +12) or global label
size / width bytes (int=4, double=8)
lifetime static, stack, heap, register
extra func signature, param list, line no., init value

3. Examples

int x;              → {kind=var, type=int, size=4, offset=0, scope=foo}
float a[10];        → {kind=var, type=array(float,10), size=40, offset=4}
int f(int a,int b)  → {kind=func, type=int(int,int), params=[a,b], label=L_f}
const PI=3.14       → {kind=const, type=float, value=3.14}

Width computed recursively: array = n × width(elem); struct = sum of fields + padding.

4. How Filled

Declaration inserts partial record; semantic pass fills type/size/offset; codegen reads offset to emit LD [fp+12].

5. Exam Points

  • List symbol attributes with examples — 5 marks, very frequent.
  • Compute size/offset for array/struct decls — 5 marks, frequent.
  • Which phase fills vs uses each attribute — 3 marks, frequent.
Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.

← All Compiler Design modules