0% found this document useful (0 votes)
7 views9 pages

PPL Unit-1

The document covers key concepts in attribute grammars, types of parsers, and runtime environments, including synthesized and inherited attributes, S-attributed and L-attributed SDTs. It discusses storage allocation techniques such as static, stack, and heap allocation, as well as semantic analysis, type checking, and the use of Backus-Naur Form (BNF) for formal syntax representation. Additionally, it highlights the importance of semantic correctness in programming and provides examples of semantic errors and their resolution.

Uploaded by

Manoj D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

PPL Unit-1

The document covers key concepts in attribute grammars, types of parsers, and runtime environments, including synthesized and inherited attributes, S-attributed and L-attributed SDTs. It discusses storage allocation techniques such as static, stack, and heap allocation, as well as semantic analysis, type checking, and the use of Backus-Naur Form (BNF) for formal syntax representation. Additionally, it highlights the importance of semantic correctness in programming and provides examples of semantic errors and their resolution.

Uploaded by

Manoj D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

UNIT-1

1) Attribute Grammar
E → E + T { E.value = E.value + T.value }

Synthesized attributes
These attributes get values from the attribute values of their
child nodes. To illustrate, assume the following production:
S → ABC

Inherited attributes
In contrast to synthesized attributes, inherited attributes can
take values from parent and/or siblings. As in the following
production,
S → ABC

S-attributed SDT
If an SDT uses only synthesized attributes, it is called as S-
attributed SDT.
L-attributed SDT
This form of SDT uses both synthesized and inherited attributes
with restriction of not taking values from right siblings.
Attributes in L-attributed SDTs are evaluated by depth-first and
left-to-right parsing manner.

2) Types of Parser:
3) Lexical Analyzer:
Note:

4)Runtime(Referencing) Environment:
A translation needs to relate the static source text of a program
to the dynamic actions that must occur at runtime.
Runtime environment is a state of the target machine.
The program consists of names for procedures, identifiers, etc.,
that require mapping with the actual memory location at runtime.
Activation Tree:

Activation Records:
o Control stack is a run time stack which is used to keep track of
the live procedure activations i.e. it is used to find out the
procedures whose execution have not been completed.
o When it is called (activation begins) then the procedure name
will push on to the stack and when it returns (activation ends)
then it will popped.
o Activation record is used to manage the information needed by
a single execution of a procedure.
o An activation record is pushed into the stack when a procedure
is called and it is popped when the control returns to the caller
function.
The diagram below shows the contents of activation records:

Return Value: It is used by calling procedure to return a value to


calling procedure.
Actual Parameter: It is used by calling procedures to supply
parameters to the called procedures.
Control Link: It points to activation record of the caller.
Access Link: It is used to refer to non-local data held in other
activation records.
Saved Machine Status: It holds the information about status of
machine before the procedure is called.
Local Data: It holds the data that is local to the execution of the
procedure.
Temporaries: It stores the value that arises in the evaluation of an
expression.
STORAGE ALLOCATION TECHNIQUES
I. Static Storage Allocation
• For any program, if we create a memory at compile-time only,
memory is created only once.
• It doesn’t support dynamic data structure i.e memory is created
at compile-time and deallocated after program completion.
• Recursion is not supported.
II. Stack Storage Allocation
• Storage is organized as a stack and activation records are
pushed and popped as activation begins and end respectively.
• Recursion is supported in stack allocation
III. Heap Storage Allocation
• Memory allocation and deallocation can be done at any time
and at any place depending on the requirement of the user.
Basic terminology :
• R- value: The value of an expression is called its r-value. The
value contained in a single variable also becomes an r-value, if
its appear on the right side of the assignment operator
• L-value: The location of the memory(address) where the
expression is stored is known as the L-value of that expression.
It always appears on the left side if the assignment operator.
5) Semantic Analysis
Semantic Analysis makes sure that declarations and statements
of program are semantically correct.
Type checking is an important part of semantic analysis where
compiler makes sure that each operator has matching operands.
Semantic Errors:
Errors recognized by semantic analyzer are as follows:
• Type mismatch
• Undeclared variables
• Reserved identifier misuse
Functions of Semantic Analysis:
1. Type Checking –
Ensures that data types are used in a way consistent with their
definition.
2. Label Checking –
A program should contain labels references.
3. Flow Control Check –
Keeps a check that control structures are used in a proper
manner.(example: no break statement outside a loop)
Example:
float y = x*30;
In the above example integer 30 will be typecasted to float 30.0
before multiplication, by semantic analyzer.
Static and Dynamic Semantics:
1.Static Semantics
2. Dynamic Semantic Analysis
6) Recursive Decent Parser:
Note:
7) Bottom-up Parsing:
Note:
8) Formal methods of describing syntax
• Context-Free Grammars (CFG):
• Backus-Naur Form (BNF):
• Regular expressions:
9) BNF:
BNF stands for Backus-Naur Form. It is used to write a formal
representation of a context-free grammar.
It is also used to describe the syntax of a programming
language.
BNF notation is basically just a variant of a context-free
grammar.
In BNF, productions have the form:
Left side → definition
Where leftside ∈ (Vn∪ Vt)+ and definition ∈ (Vn∪ Vt)*. In BNF, the
leftside contains one non-terminal.
EBNF:
EBNF is no more “powerful” than BNF; that is, anything that can
be expressed in EBNF can also be expressed in BNF
Extensions:
• “ *” (The Kleene Star): means 0 or more occurrences
• “ +” (The Kleene Cross): means 1 or more occurrences
• “ ?”: means 0 or 1 occurrences (sometimes “[ … ]” used instead)
Example:
BNF:
<expr>::= <digits>| empty
EBNF:
<expr>::=<digits>*

You might also like