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

Internet programming

The document covers key concepts in lexical analysis, parsing, and semantic analysis, including definitions of tokens, patterns, and lexemes, as well as error recovery techniques. It discusses various parsing techniques, including top-down and bottom-up parsing, and introduces the structure of YACC files for generating parsers. Additionally, it addresses semantic analysis topics such as type checking, syntax-directed definitions, and three-address code representation.

Uploaded by

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

Internet programming

The document covers key concepts in lexical analysis, parsing, and semantic analysis, including definitions of tokens, patterns, and lexemes, as well as error recovery techniques. It discusses various parsing techniques, including top-down and bottom-up parsing, and introduces the structure of YACC files for generating parsers. Additionally, it addresses semantic analysis topics such as type checking, syntax-directed definitions, and three-address code representation.

Uploaded by

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

Lexical Analysis and Parsing

1. Tokens, Patterns, Lexemes:


o Token: A logical unit, such as keywords, identifiers, operators.

o Pattern: A rule defining tokens, often expressed in regular


expressions.
o Lexeme: Actual text matching a token pattern.

2. Error Recovery in Lexical Analysis:


o Skipping invalid characters, inserting missing characters, and panic
mode recovery.
3. Why Buffering is Used:
o To optimize input operations by reducing the time required for reading
characters.
4. Transition Diagram for Identifier:
o A state diagram where transitions occur on valid identifier characters
(letters, digits after the first letter).
5. Prefix, Suffix, Proper Prefix, Proper Suffix Example:
o String: "abcd"

o Prefix: "ab", Proper Prefix: "abc"

o Suffix: "cd", Proper Suffix: "bcd"

6. Buffer Pair:
o Two buffers are used in lexical analysis for fast reading and sentinel
handling.
7. Interaction Between Lexical Analyzer and Parser:
o Lexical analyzer provides tokens to the parser; the parser requests and
processes tokens.
8. Parse Tree for -(id + id):
9. -
10. /
11. +
12. / \
13. id id
14.Operations on Languages:
o Union, Intersection, Concatenation, Kleene Star.

15.Phases of a Compiler:
 Lexical Analysis, Syntax Analysis, Semantic Analysis, Intermediate Code
Generation, Optimization, Code Generation, Code Optimization.

Parsing Techniques
11.Sentinels in Buffer Pairs:
 They reduce the overhead of checking buffer limits.
12.Handle Pruning:
 A technique in bottom-up parsing for replacing a substring with a non-
terminal.
13.Parser:
 A component that performs syntax analysis by constructing parse trees.
14.Predictive Parsing:
 Uses a lookahead token for making parsing decisions without backtracking.
15.Top-Down vs. Bottom-Up Parsing:
 Top-Down: Constructs parse tree from the root (e.g., LL parsing).
 Bottom-Up: Constructs parse tree from leaves (e.g., LR parsing).
16.Recursive Descent Parsing:
 A top-down parsing method using recursive procedures for non-terminals.
17.Error Recovery in Predictive Parsing:
 Panic mode, phrase-level recovery, and error productions.
18.Algorithm for FOLLOW:
 Initialize FOLLOW(S) for start symbol. Propagate FOLLOW sets iteratively.
19.Left Factoring:
 Transforming grammar to remove common prefixes.
 Example: A → αβ | αγ → A → αX, X → β | γ
20.LL(1) Grammar:
 A grammar where parsing decisions depend on a single lookahead symbol.
21.Ambiguous vs. Unambiguous Grammar:
 Ambiguous: Multiple parse trees (e.g., S → aSb | bSa).
 Unambiguous: Unique parse tree.
22.LR Parsing Advantages/Disadvantages:
 Advantages: Handles wide classes of grammars.
 Disadvantages: Complex tables, hard to implement.
23.Augmented Grammar:
 Extends original grammar with new production rules.
24.Conflicts in Parsing:
 Shift-Reduce and Reduce-Reduce conflicts.
25.Shift-Reduce Parsing Categories:
 Simple LR (SLR), Canonical LR, Lookahead LR (LALR).
26.Input-Output Translator with YACC:
 Define grammar rules and translation functions in the YACC file.
27.LR Parsing Actions:
 Shift, Reduce, Accept, Error.

Semantic Analysis
28.Ambiguous Grammar Example:
 Grammar S → aSbS | bSaS | ε is ambiguous.
29.Dangling Reference:
 Occurs when a pointer references memory that has been deallocated.
30.Types of Recursion:
 Direct, Indirect, Tail, Non-tail recursion.
31.LR Parsers Comparison:
 SLR (simple), LALR (optimized), Canonical LR (complex but powerful).
32.Structure of YACC File:
 Sections for declarations, rules, and functions.
33.Lex vs. YACC:
 Lex generates lexical analyzers, YACC generates parsers.
34.Rules for Type Checking:
 Compatibility and coercion rules.
35.Synthesized vs. Inherited Attributes:
 Synthesized: Pass information upwards.
 Inherited: Pass information downwards.
36.Annotated Parse Tree:
 Parse tree with attributes for each node.
37.Type Checker:
 Ensures type correctness in a program.
38.Syntax Tree:
:=
/ \
a +
/ \
* *
b -c b -c
39.Type Systems:
 Framework defining rules for assigning types.
40.Type Checking Rule for Functions:
 Ensure return types and argument types match.
41.Syntax-Directed Definition:
 Associates semantic rules with grammar productions.
42.Intermediate Representations:
 Syntax tree, Postfix, Three-address code.
43.Syntax-Directed Definitions vs. Translation Schemes:
 SDD has semantic rules; translation schemes interleave actions.
44.Type Expressions:
 Represent types using type constructors.
45.Three-Address Statement Methods:
 Quadruples, Triples, Indirect Triples.
46.S-Attribute vs. L-Attribute Definitions:
 S-attributed use synthesized attributes; L-attributed use inherited attributes.
47.Postfix for a + b * c:
 abc*+
48.Three-Address Code for Conditional:
if a < b
t1 = 1
else
t1 = 0
49.L-Attribute Rules Example:
 Both given rules are L-attributed.
50.Methods for Representing Syntax Tree:
 Pointer-based, Array-based, String-based.
51.Syntax-Directed Definition for If-Else:
if_stmt → if expr then stmt else stmt
52.Usage of Syntax-Directed Definition:
 Attribute evaluation during parsing.
53.Three-Address Code for d=(a-b)+(a-c)+(a-c):
t1 = a - b
t2 = a - c
t3 = t1 + t2
t4 = t3 + t2
d = t4
54.Evaluation Order of SDD:
 Depth-first or dependency-based order.
55.Translation Scheme:
 Combines grammar rules with semantic actions.
56.Evaluating Semantic Rules:
 Attribute computation during syntax analysis.

You might also like