0% found this document useful (0 votes)
53 views4 pages

Compiler vs Interpreter: Key Differences

The document discusses the differences between compilers and interpreters. It provides 8 key differences: 1. Compilers take the entire program as input while interpreters take single instructions as input. 2. Compilers generate intermediate object code while interpreters do not. 3. Compilers are faster at mapping inputs to outputs than interpreters. 4. Compilers execute conditional control statements faster than interpreters. 5. Compilers require more memory since they generate object code while interpreters require less memory. 6. With compilers, programs do not need to be compiled every time while with interpreters, programs must be converted each time. 7. Compilers provide less detailed error diagn

Uploaded by

Mahmudul Hasan
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)
53 views4 pages

Compiler vs Interpreter: Key Differences

The document discusses the differences between compilers and interpreters. It provides 8 key differences: 1. Compilers take the entire program as input while interpreters take single instructions as input. 2. Compilers generate intermediate object code while interpreters do not. 3. Compilers are faster at mapping inputs to outputs than interpreters. 4. Compilers execute conditional control statements faster than interpreters. 5. Compilers require more memory since they generate object code while interpreters require less memory. 6. With compilers, programs do not need to be compiled every time while with interpreters, programs must be converted each time. 7. Compilers provide less detailed error diagn

Uploaded by

Mahmudul Hasan
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

Compiler Mahmudul Hasan ( Moon)

*Difference between Compiler and Interpreter:


No Compiler Interpreter

1 Compiler Takes Entire program as input Interpreter Takes Single instruction as input .

2 Intermediate Object Code is Generated No Intermediate Object Code is Generated

3 Compiler is faster at mapping inputs to outputs. Interpreter is slower than a compiler.

4 Conditional Control Statements are Executes faster Conditional Control Statements are Executes slower

Memory Requirement : More(Since Object Code is


5 Memory Requirement is Less
Generated)

Every time higher level program is converted into lower


6 Program need not be compiled every time
level program

7 Error diagnostics is less than a compiler. Error diagnostics is better than a compiler.

8 Example : C Compiler Example : BASIC

[Link] compiler and interpreter. Write the difference between them. (page 2)
[Link] Preprocessor, Assembler, Linker, Loader, Byte code, lexical analysis, lexical analyzer,
Intermediate code generation
In computer science, a preprocessor is a program that processes its input data to produce output that is
used as input to another program.

An assembler translates the assembly program into machine code (object).

A linker tool is used to link all the parts of the program together for execution.

In computer systems a loader is the part of an operating system that is responsible for loading programs
and libraries.

Byte code is program code that has been compiled from source code into low-level code for a software
interpreter. It may be executed by a virtual machine (such as a JVM) or further compiled into machine
code, which is recognized by the processor.

Lexical analysis is the first phase of a compiler. It takes the modified source code from language
preprocessors that are written in the form of sentences.
The lexical analyzer breaks these syntaxes into a series of tokens, by removing any whitespace or
comments in the source code.

Intermediate code generation is the process by which a compiler's code generator converts
some intermediate representation of source code into a form that can be readily executed by a machine.

[Link] Java use both compiler and interpreter? (page 2 ex:1.1)


4. Write the names of the different phases of a Compiler. (page 5 figure:1.6)
[Link] 1.7 er process ta practice korte hobe different equation dia.

Chapter 2

[Link] the model of a compiler front end . (page 41er figure 2.3 draw and discribe)

[Link] context free grammar, describe the four component of a context free grammer.(page 42 er
2.2.1 er point 4 ta)
A context-free grammar (CFG) is a set of recursive rules (or productions) used to generate patterns of
strings. or
A context-free grammar (CFG) is a certain type of formal grammar, a set of production rules that
describe all possible strings in a given formal language.

[Link] parse tree. Write the properties of a parse tree. (page 43 er 2.2.3 er point 4 ta)
A parse is an ordered, rooted tree that represents the syntactic structure of a string according to some
context-free grammar. Or
A parse tree is an entity which represents the structure of the derivation of a terminal string from some
non-terminal symbol.

[Link] is ambiguity of a grammar? How can we remove the ambiguity of a grammar?


In computer science, an ambiguous grammar is a context-free grammar for which there exists a string
that can have more than one leftmost derivation or parse tree.

An unambiguous grammar is a context-free grammar for which every valid string has a unique
leftmost derivation or parse tree.

How can we remove ambiguity from an ambiguous grammar:


In an ambiguous grammar it has more than one left most derivation or parse tree. So, when we derive the
language from a grammar, we should be aware about ambiguity that’s means we choose that grammar
which can make the grammar unambiguous. When we make a parse tree, we must aware about the
precedence of the operator. If there is any scope to give associativity we must apply this. After giving
precedence and associativity we can make one left most tree that’s means the ambiguity is removed.

[Link] associativity and precedence of operators.


The associativity of an operator is a property that determines how operators of the same precedence are
grouped in the absence of parentheses.
When several operations are in an expression, which operator is executed first this order is
called operator precedence.

Chapter 3

[Link] between lexical analysis and parsing (Syntax analysis).


Lexical Analysis Syntax analysis
[Link] analysis is the first phase of a compiler [Link] start after lexical analysis is completed.
[Link] takes the modified source code from language 2. A syntax analyzer or parser takes the input from a
preprocessors that are written in the form of sentences. lexical analyzer in the form of token streams.
[Link] determines the individual tokens in a program. [Link] determine the phase of a program.
4. Token structure can be described by regular 4. Phrase structure must be described using a context-
expressions free grammar

[Link] tokens, patterns, lexemes. (page 111)


[Link] is lexical errors? Write the error recovery action. (page 113,114 sec: 3.1.4)
[Link] is input buffer?
Input buffer is the process…..
• To ensure that a right lexeme is found or not.
• Hence a two-buffer scheme is introduced to handle large look ahead safely.
• Techniques for speeding up the process of lexical analyzer.
[Link] the terms for parts of strings. (page 119)
[Link] much operation can be done in a language? (page 120 er uporer 4 ta operation)
[Link] the figure of different transition diagram.
[Link] finite automata. Write the term that consist of a NFA. (page 147)
Finite automata is a state machine that takes a string of symbols as input and changes its state
accordingly.
[Link] the NFA of a string and convert it to DFA. (155 er exercise)
[Link] 3.23 er description (same as automata)

Chapter 4

[Link] Panic mode recovery, Phrase level recovery, Error Production, Global Correction.
Panic Mode Recovery
 In this method, successive characters from input are removed one at a time until a designated set of
synchronizing tokens is found. Synchronizing tokens are deli-meters such as ; or }
 Advantage is that it’s easy to implement and guarantees not to go to infinite loop
 Disadvantage is that a considerable amount of input is skipped without checking it for additional
errors
Error production
 If user has knowledge of common errors that can be encountered then, these errors can be
incorporated by augmenting the grammar with error productions that generate erroneous
constructs.
 If this is used then, during parsing appropriate error messages can be generated and parsing can
be continued.
 Disadvantage is that it’s difficult to maintain.

Global Correction
 The parser examines the whole program and tries to find out the closest match for it which is error
free.
 The closest match program has less number of insertions, deletions and changes of tokens to
recover from erroneous input.
 Due to high time and space complexity, this method is not implemented practically.

[Link] a grammar, construct the lest most and right most derivation.
[Link] a grammar, eliminate its left recursion.
4. Given a grammar, eliminate its left factoring.

Common questions

Powered by AI

Java uses a compiler to translate the source code into bytecode which is platform-independent. The bytecode is then executed by an interpreter, the Java Virtual Machine (JVM), enabling Java applications to run on any device with the JVM installed. This dual approach balances the portability of interpretation with the performance benefits of compilation .

Lexical analysis is the first phase of the compilation process where the source code is converted into tokens by the lexical analyzer. It removes whitespace and comments from the source code, thus preparing the input for the syntax analysis phase. This phase effectively transforms orderly text into sets of tokens, which will be used to construct the program's structure in parsing .

A finite automaton is a theoretical machine that processes input strings to change states according to defined rules. An NFA is a specific type that allows for multiple possible state transitions from a single state with the same input symbol. NFAs simplify the representation of lexical analyzers by managing transitions in matching token patterns, which can then be converted into deterministic finite automata (DFA) for implementation .

A compiler takes the entire program as input and generates intermediate object code, making it faster at execution but requiring more memory. It provides less effective error diagnostics. An interpreter processes one instruction at a time without generating object code, which requires less memory and provides better error diagnostics, but it is slower than a compiler .

Ambiguity in a grammar allows for multiple leftmost derivations or parse trees for a single string, creating confusion in parsing. To resolve ambiguity, grammars can be rewritten to enforce operator precedence and associativity rules, ensuring a single valid parse tree for each string. This may involve restructuring the grammar to manage precedence and left associative or right associative operations .

A parse tree is a tree structure representing the syntactic structure of a string as per a context-free grammar. Its properties include being ordered, rooted, and representing the hierarchical structure of the derivation of terminal symbols from non-terminal symbols. It allows one to visualize the application of grammar rules to generate the syntax of the program .

Lexical analysis is the initial phase that segments the source code into tokens, handling basic syntactic elements without understanding their hierarchical structure. Syntax analysis, or parsing, follows and takes these tokens to generate a parse tree according to grammar rules, thereby comprehending the nested hierarchical structure of the source code .

Error recovery strategies in syntax analysis include panic mode, which quickly skips over input to synchronize parsing, error productions that anticipate common errors, and global correction which analyses the entire input. Panic mode is easy to implement but skips a significant chunk of input data, error productions are complex to maintain, and global correction, though theoretically ideal, is impractically resource-intensive .

Left recursion in a grammar causes infinite loops in top-down parsers like LL parsers and must be eliminated to ensure termination. This is done by restructuring the grammar rules to remove left recursion, typically by introducing new non-terminal symbols to handle recursive patterns without infinite leftward growth .

A CFG is a formal grammar where every production rule's left-hand side consists of a single non-terminal symbol. Its components include a set of non-terminal symbols, terminal symbols, production rules, and a start symbol, allowing for the generation of non-deterministic language patterns by recursive rule application .

You might also like