Compiler Design Parsing Parsing During Compilation regular expressions
- Slides: 56
Compiler Design
Parsing
Parsing During Compilation regular expressions source program lexical analyzer errors token get next token parser symbol table • uses a grammar to check structure of tokens • produces a parse tree • syntactic errors and recovery • recognize correct syntax • report errors parse tree • • • rest of front end intermediate representation Collecting token information Perform type checking Intermediate code generation
Errors in Programs
Error Detection
Adequate Error Reporting is Not a Trivial Task
ERROR RECOVERY
ERROR RECOVERY MAY TRIGGER MORE ERRORS!
ERROR RECOVERY APPROACHES: PANIC MODE
ERROR RECOVERY APPROACHES: PHRASE-LEVEL RECOVERY
ERROR RECOVERY APPROACHES: ERROR PRODUCTIONS
ERROR RECOVERY APPROACHES: GLOBAL CORRECTION
Parsers
CONTEXT FREE GRAMMARS (CFG) A context-free grammar has four components: G = ( V, Σ, P, S ) üA set of non-terminals (V). Non-terminals are syntactic variables that denote sets of strings. The nonterminals define sets of strings that help define the language generated by the grammar. üA set of tokens, known as terminal symbols (Σ). Terminals are the basic symbols from which strings are formed. üA set of productions (P). The productions of a grammar specify the manner in which the terminals and nonterminals can be combined to form strings. Each production consists of a non-terminal called the left side of the production, an arrow, and a sequence of tokens and/or on- terminals, called the right side of the production. üOne of the non-terminals is designated as the start symbol (S); from where the production begins.
Example of CFG: G = ( V, Σ, P, S )Where: V = { Q, Z, N } Σ = { 0, 1 } P = { Q → Z | Q → N | Q → ℇ | Z → 0 Q 0 | N → 1 Q 1 } S={Q} ØThis grammar describes palindrome language, such as: 1001, 11100111, 00100, 1010101, 11111, etc.
RULE ALTERNATIVE NOTATIONS
NOTATIONAL CONVENTIONS
DERIVATIONS q. A derivation is basically a sequence of production rules, in order to get the input string. During parsing, we take two decisions for some sentential form of input: q. Deciding the non-terminal which is to be replaced. q. Deciding the production rule, by which, the non-terminal will be replaced. To decide which non-terminal to be replaced with production rule, we can have two options.
DERIVATIONS
DERIVATIONS
CFG Terminology
LEFTMOST DERIVATION
RIGHTMOST DERIVATION
PARSE TREE
PARSE TREE
PARSE TREE
PARSE TREE
PARSE TREE
AMBIGUOUS GRAMMAR
AMBIGUOUS GRAMMAR
AMBIGUOUS GRAMMAR
AMBIGUOUS GRAMMAR
AMBIGUOUS GRAMMAR
AMBIGUOUS GRAMMAR
AMBIGUOUS GRAMMAR
UNAMBIGUOUS GRAMMAR
PREDICTIVE PARSING
LEFT RECURSION: INFINITE LOOPING PROBLEM A grammar is left-recursive if it has a non-terminal A, such that there is a derivation : + A A , for some . Top-Down parsing can’t reconcile this type of grammar, since it could consistently make choice which wouldn’t allow termination. A A A A … etc. A A | So we have to convert our left-recursive grammar into an equivalent grammar which is not left-recursive.
IMMEDIATE LEFT RECURSION
IMMEDIATE LEFT RECURSION ELIMINATION: EXAMPLE Our Example : E E+T | T T T*F | F F ( E ) | id E TE’ E’ + TE’ | F ( E ) | id T FT’ T’ * FT’ |
LEFT RECURSION IN MORE THAN ONE STEP
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
LEFT RECURSION IN MORE THAN ONE STEP: ELIMINATION
ALGORITHM FOR ELIMINATING LEFT RECURSION
Left Factoring: Common Prefix Problem
Left Factoring : Example
Left Factoring : Example
THE END
- Cross compiler in compiler design
- Equivalence of type expressions in compiler design
- Yet another compiler compiler
- Xkcd regex problems
- Simplyfying rational expressions
- Perl 5 regular expression
- Inductive definition of regular expressions
- Regular expressions wikipedia
- Algebraic properties of regular expression
- I formal
- Primitive regular expressions
- Regular expressions
- Which grammar generates regular language
- Phases of reverse engineering
- Jav adaptation
- What is pure and impure interpreter
- Analysis synthesis model of compilation
- Front end of compiler
- Reverse compilation
- Contoh compilation
- What is data compilation
- Compilation
- Mushaf e usmani
- Work immersion checklist
- The vedic age lasted roughly from
- Bus crash compilation
- Previous ipdb not found, fall back to full compilation.
- Sub division of run time memory
- Simple type checker in compiler design
- Lexemes in compiler design
- The designer express the ideas in terms related to the
- Syntax analysis in compiler design
- Compiler front end and back end
- Cs 473
- Trace scheduling
- Terminal and non terminal in compiler design
- Copy propogation
- Applications of syntax directed translation
- Type checking in compiler design
- Lexical analysis in compiler construction
- Activation record in compiler design
- Synopsys user guide
- Pass one of two pass assembler algorithm
- Global data flow analysis in compiler design
- Very busy
- Transition diagram in compiler design
- Compiler design tutorial
- Compiler type checking
- Advanced compiler design and implementation
- Synopsys design compiler user guide
- Followpos in compiler design
- Flow graph in compiler design
- Induction variable elimination in compiler design
- What is yacc in compiler design
- Attributes in compiler design
- Trace based collection in compiler design
- Automatic library