0% found this document useful (0 votes)
8 views2 pages

SP Final TA2

The document outlines the differences between compilers, assemblers, and interpreters, highlighting their functions, input/output types, execution speed, and error handling. It also compares top-down and bottom-up parsers, discussing their starting points, implementation ease, and use cases. Additionally, it explains the roles of front-end and back-end parsers in compilers, the process of lexical analysis, and the concept of predictive parsing and canonical LR items.

Uploaded by

dhananjay
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)
8 views2 pages

SP Final TA2

The document outlines the differences between compilers, assemblers, and interpreters, highlighting their functions, input/output types, execution speed, and error handling. It also compares top-down and bottom-up parsers, discussing their starting points, implementation ease, and use cases. Additionally, it explains the roles of front-end and back-end parsers in compilers, the process of lexical analysis, and the concept of predictive parsing and canonical LR items.

Uploaded by

dhananjay
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/ 2

🔹 1.

Difference Between Compiler, Assembler, and Interpreter

Featur
Compiler Assembler Interpreter
e
Translates high-level
Functi Converts assembly Translates and executes
language to machine
on code to machine code code line by line
code
High-level language (e.g., High-level language (e.g.,
Input Assembly language
C, Java) Python, JavaScript)
No intermediate file;
Output Machine code (binary) Machine code
executes directly
Fast execution after Slower due to real-time
Speed Fast execution
compilation translation
Error
Shows all errors after Shows all errors after
Handli Stops at first error
compilation assembling
ng

🔹 2. Difference Between Top Down Parser and Bottom Up Parser

Feature Top Down Parser Bottom Up Parser


Start Point Starts from the start symbol Starts from the input and works backward
Right to left derivation (constructs parse tree
Direction Left to right derivation
bottom up)
Recursive Descent Parser, LL
Types LR Parser, SLR, LALR
Parser
Ease of
Easier but less powerful More complex but more powerful
Implementation
Error Detection May detect errors early Detects errors at a later stage
Use Cases Simpler grammars Complex programming language grammars

3. Explain Front End and Back End Parser


Front End Parser (Syntax Analyzer)
Part of the compiler's front-end
Checks syntax according to grammar rules
Generates parse tree or abstract syntax tree (AST)
Performs semantic analysis, type checking, and error reporting
Deals with language-specific tasks
Example: int x = 5; – checks if the syntax is correct
Back End Parser---Actually, in compiler design, “Back end parser” is not a standard term.
However, the Back End of a Compiler involves:
----Intermediate code generation
---Optimization----Target code generation (machine code
***Lexical analysis?? Definition:Lexical Analysis is the first phase of a compiler,
where the source code is read character by character and grouped into
meaningful sequences called tokens. Main Tasks of Lexical Analyzer:1)
Tokenization: Breaks the input source code into tokens (e.g., keywords) 2) Error
Detection: Detects invalid tokens (e.g., unknown characters) 3) Symbol Table
Management: Adds new identifiers (like variable names) to the symbol table.
Example: sum = a * 20; Lexical analyzer produces: line 1)Token(ID, "sum")
2)Token(ASSIGN, "=") 3)Token(ID, "a") 4)Token(OP_MUL, "*")
5)Token(NUM, "20") 6)Token(SEMICOLON, ";") Tools/Techniques Used:
Finite Automata for recognizing patterns (tokens),Regular Expressions to
define token patterns, Lex/Flex tools to generate lexical analyzers
***predictive parser?? Define:A predictive parser is a type of top-down parser
that uses lookahead tokens to decide which production rule to apply. It's called
predictive because it predicts the correct production based on the current
input token and the top of the parsing stack. Characteristics: 1)Parsing Method
2)Table used 3) backtracking 4)Grammer Type Components:1)Stack: holds
grammar symbols. 2)Parsing Table: guides which production to apply. 3)Parsing
Algo: consults the table and applies rules. How It Works (Algorithm)
Step1)Initialize the stack with the start symbol and $ step 2)Repeat until stack
is empty: Let X be the symbol on top of the stack and a the current input
symbol. If X is a terminal: If X == a, pop X and advance input. Else, error. If X is a
non-terminal: Look up entry M[X, a] in the parsing table: If it contains a
production X → α, replace X with α. Else, error. Step3)If both stack and input
are $, accept.
***What is meant by canonical item?? Definition:A canonical LR item is a
production rule with a dot (•) inserted somewhere on the right-hand side to
indicate how much of the production has been seen (parsed) so far.
Format: A → α • β Examples: E → E + T Ans: canonical LR items derived from
this production are: 1)E → • E + T → nothing seen yet 2)E → E • + T → E seen
3)E → E + • T → E and + seen 4)E → E + T • → complete

You might also like