0% found this document useful (0 votes)
5 views3 pages

Symbol Table

The document provides an overview of key concepts in compiler design, including symbol tables, handle pruning, and parsing techniques. It explains the translation of infix expressions to postfix and prefix forms, as well as the differences between parse trees, syntax trees, and directed acyclic graphs (DAGs). Additionally, it discusses synthesized and inherited attributes in relation to grammar productions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Symbol Table

The document provides an overview of key concepts in compiler design, including symbol tables, handle pruning, and parsing techniques. It explains the translation of infix expressions to postfix and prefix forms, as well as the differences between parse trees, syntax trees, and directed acyclic graphs (DAGs). Additionally, it discusses synthesized and inherited attributes in relation to grammar productions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Symbol Table
Definition: A symbol table is a data structure used by a compiler to store
information about variables, functions, objects, classes, etc.

Purpose:

Stores names and their attributes (type, scope, memory location)

Enables semantic analysis, type checking, and code generation

2. Handle & Handle Pruning


Handle: A handle is a substring that matches the right-hand side of a production
and can be reduced to a non-terminal.

Handle Pruning: The process of reducing handles in a right-sentential form to get


the start symbol (used in bottom-up parsing).

Stack Implementation in Shift-Reduce Parser:

Uses a stack and input buffer

Performs shift (push input symbol to stack) or reduce (replace handle on stack with
LHS of a production)

Example (Grammar: E → E+E | E*E | id; Input: id + id * id)

Shift id → stack: id

Reduce id → E

Shift + → stack: E +

Shift id → stack: E + id

Reduce id → E

Shift * → stack: E + E *

Shift id → stack: E + E * id

Reduce id → E

Reduce E * E → E

Reduce E + E → E

3. Infix to Postfix/Prefix Translation


Translation Scheme:

Infix: A + B

Postfix: A B +

Prefix: + A B

String: 4 * 5 + 7 - 2

Postfix: 4 5 * 7 + 2 -
Prefix: - + * 4 5 7 2

Annotated Parse Tree:


For brevity, just showing format:

Postfix Tree (Bottom-Up Order):

markdown
Copy
Edit
-
/ \
+ 2
/ \
* 7
/ \
4 5
Prefix Tree (Top-Down Order):

markdown
Copy
Edit
-
/ \
+ 2
/ \
* 7
/ \
4 5
4. Operator Grammar & Leading/Trailing
Operator Grammar: A grammar that does not have ε-productions or two adjacent non-
terminals.

Algorithm to Compute Leading & Trailing:

Leading(X):

If X → a..., add a

If X → Y..., add Leading(Y)

Trailing(X):

If X → ...a, add a

If X → ...Y, add Trailing(Y)

Example:
Grammar:
E → E + T | T
T → T * F | F
F → (E) | id

Leading(E) = { '(', id }
Trailing(E) = { ')', id }

5. Parse Tree vs Syntax Tree vs DAG


Feature Parse Tree Syntax Tree Directed Acyclic Graph (DAG)
Structure Represents grammar rules fully Abstracts unnecessary rules
Minimizes repeated computations
Redundancy High Moderate Low (common sub-expressions merged)
Example (A+A*B) Shows all productions Only operators and operands Shares node
for A

6. Synthesized vs Inherited Attributes


Attribute Type Direction Based On Example
Synthesized Bottom-Up Child nodes E.val = E1.val + T.val
Inherited Top-Down/Sideways Parent/sibling nodes T.type = E.type (passed from
parent)

Example:

kotlin
Copy
Edit
Production: E → E1 + T
Synthesized: E.val = E1.val + T.val
Inherited: T.inh = E1.type

You might also like