Documente Academic
Documente Profesional
Documente Cultură
Lexical Analysis
Reads characters and Produces The output is called token and is a pair of the form
Examples:
Type checking: report error if an operator is applied to an incompatible operand.
Eg : Array index is an integer; report error if floating point index.
Check flow-of-controls.
Uniqueness or name-related checks.
Code Optimisation
The goal is to improve the intermediate code
Error Recovery
Panic mode
When a parser encounters an error anywhere in the statement, it ignores the rest of the statement by
not processing input from erroneous input to delimiter, such as semi-colon
Statement mode
When a parser encounters an error, it tries to take corrective measures,
For example, inserting a missing semicolon, replacing comma with a semicolon etc
Error productions
Some common errors are known to the compiler designers that may occur in the code.
the designers can create augmented grammar to be used, as productions that generate erroneous
constructs when these errors are encountered.
Global correction
The parser considers the program in hand as a whole and tries to figure out what the program is
intended to do and tries to find out a closest match for it, which is error-free.
Input Buffering
Buffer Pairs
Parsing
Parsing methods
The top-down
Bottom-up methods
Top-down parsing, construction starts at the root and proceeds to the leaves.
Bottom-up parsing, construction starts at the leaves and proceeds towards the root.
1. Top-down parsers are easy to build by hand.
2. Bottom-up parsing,
3. Can handle a larger class of grammars.
They are not as easy to build, but tools for generating them directly from a grammar are
available.
Predictive Parsing
Recursive-descent parsing Is a top down method of syntax analysis in which a set of recursive
procedures is used to process the input.
Simple form of recursive descent–Predictive Parsing
Backtracking
A syntax-directed definition (SDD) is a context-free grammar together with attributes and rules.
Attributes are associated with grammar symbols and rules are associated with productions.
PRODUCTION SEMANTIC RULE
E → E1 + T E.code= E1.code || T.code|| ‘+’
Syntax-Directed Translation Schemes (SDT) embeds program fragments called semantic actions
within production bodies
SDTs are more efficient than SDDs as they indicate the order of evaluation of semantic actions
associated with a production rule.
Annotated parse-tree
AN ANNOTATED PARSE TREE. is a parse tree showing the values of the attributes at each
node. The process of computing the attribute values at the nodes is called annotating or
decorating the parse tree. Example 3 The following syntax-directed definition is from a desk
calculator.