DLP Final
DLP Final
Language processor: A language processor is a software program designed or used to perform tasks such as processing program code
to machine code.
Translator: A translator is a program that takes one form of program as input and converts it into another form.
Types of translators are:
1. Compiler
2. Interpreter
3. Assembler
Compiler: A compiler is a program that reads a program written in source language and translates it into an equivalent program in
target language.
OR Compilers are basically use to convert high level language into low level language , here high level language means source code
that we write in c,c++,java etc. and low level language means assembly language or machine code.
Interpreter: Interpreter is also a program that reads a program written in source language and translates it into an equivalent program
in target language line by line.
Assembler: Assembler is a translator which takes the assembly code as an input and generates the machine code as an output.
Incremental compiler: The compiler which compiles only the changed line from the source code and update the object code.
Cross compiler: It's a compiler that runs on one type of computer system (the host) but produces code that can run on a different type of
computer system (the target).
CHAPTER:2:
Role of the Parser: https://youtu.be/CdC61wH1Zic
In our compiler model, the parser obtains a string of tokens from lexical analyzer,
Grammars: https://youtu.be/ETMcmKtAgBs
Types of Errors:
Lexical error: Lexical errors can be detected during lexical analysis phase.
Typical lexical phase errors are:
- Spelling errors in keywords
- Exceeding length of identifier or numeric constants
- Appearance of illegal characters
Syntax error: Syntax error appear during syntax analysis phase of compiler.
Typical syntax phase errors are:
- Errors in structure
- Missing operators
- Unbalanced parenthesis
Example: printf(“Hello”) so here semicolon is missing
Semantic error: Semantic error detected during semantic analysis phase.
Typical semantic phase errors are:
- Incompatible types of operands
- Undeclared variable
QuestionBank Remaining Questions CH.2:
Error recovery strategies (Ad-Hoc & systematic methods): There are mainly four error recovery strategies:
Panic mode: In this method on discovering error, the parser discards input symbol one at a time. This process is continued until one of a
designated set (like end, semicolon) of synchronizing tokens (are typically the statement or expression terminators) is found.
Synchronizing tokens are delimiters such as semicolon or end.
These tokens indicate an end of the statement.
If there is less number of errors in the same statement then this strategy is best choice.
Phrase level recovery: In this method, on discovering an error parser performs local correction on remaining input. The local correction
can be replacing comma by semicolon, deletion of semicolons or inserting missing semicolon.
This type of local correction is decided by compiler designer.
This method is used in many error-repairing compilers.
Error production: The use of the error production method can be incorporated if the user is aware of common mistakes that are
encountered in grammar in conjunction with errors that produce erroneous constructs. If error production is used then, during parsing
we can generate appropriate error message and parsing can be continued. Example: write 5x instead of 5*x
Global correction: In order to recover from incorrect input, the parser analyzes the whole program and tries to find the closest match for
it, which is error-free. The closest match is one that does not do many insertions, deletions, and changes of tokens. This method is not
practical due to its high time and space complexity.
Draw transition diagram for relational operators.: https://youtu.be/LQNBbajHxfo?si=evXFadpb-cg1F0oP
What is symbol table? For what purpose compiler uses symbol table?
Symbol table is an important data structure created and maintained by compilers in order to store information about the occurrence of
various entities such as variable names, function names, objects, classes, interfaces, etc.
It is used by the compiler to achieve compile-time efficiency.
The symbol table helps the compiler resolve issues related to variable scoping.
During the early stages of compilation, the compiler builds the symbol table by scanning the source code.
The symbol table is used in detecting errors, such as undeclared variables or duplicate declarations. If a variable is referenced but not
found in the symbol table, the compiler can issue an error message.
Explain role of finite automata in the compiler.
Finite automata play a crucial role in the lexical analysis phase of a compiler. Specifically, they are used to implement regular
expressions and to recognize tokens in the source code
Finite automata are used to recognize and extract tokens from the source code in lexical analysis phase.
Lexer (Lexical Analyzer) uses finite automata to implement the regular expressions for various tokens.
Finite automata can also be used to identify and report lexical errors, This assists in early error detection.
CHAPTER:3:
Top down Parsing: https://youtu.be/1rGLFs5pGNM
https://youtu.be/mP6YNYSpZV4
BruteForce in Top Down Parsing / Recursive-Descent Parsing : https://youtu.be/4gKY5GHOMQE
First and follow: https://youtu.be/oCyHux4Ta3k
https://youtu.be/sWiXyhCwnsE
LL(1) grammar: https://youtu.be/BNfNBYnKjp8
NOTE: Remove Left Recursion
In Top Down parser means in LL1 if in production rule if Left Recursion is there then we need to convert it into right recursion then we
can proceed ahead because A top-down parser cannot handle left recursive productions.
So Convert Left Recursion into Right Recursion: https://youtu.be/nJxF9M2lFEw
https://youtu.be/ttplIT5r8OQ
https://youtu.be/T96Jua67drw
QUESTION ON LL1:
Here in Question Left Recursion is there so first remove left recursion then make LL1 table.
CHAPTER:5:
Storage Organization:
The compiler demands for a block of memory to operating system. The compiler utilizes this block of memory executing the compiled
program. This block of memory is called run time storage.
The run time storage is subdivided to hold code and data such as, the generated target code and data objects.
The size of generated code is fixed. Hence the target code occupies the determined area of the memory.
Stack is used to manage the active procedure.Heap area is the area of run time storage in which the other
information is stored.
Syntax Error:
Definition: Syntax errors occur when the compiler encounters code that violates the grammatical rules of the programming language.
The syntax phase of compilation involves analyzing the structure of the code based on the language's grammar rules.
Example: In many programming languages, a common syntax rule is that statements must end with a semicolon. If a semicolon is
missing at the end of a statement, the compiler would report a syntax error.
C code: When you first write the code in the C language, that source code is sent to the Preprocessing section.
Preprocessing: In this section our source code is attached to the preprocessor file. Different types of header files are used like the
studio.h, math.h, etc. Our C source code is attached to these types of files and the final C Source generates. (some of the preprocessor
directives are #include,#define). After generating the preprocessed C source code, the C source code is sent to the compiler section.
Compiler − After generating the preprocessed source code, it moves to the compiler and the compiler generates the assembly level
code after compiling the whole program.
The first thing the C compiler does is to search for any error. If there is no error, the C compiler will report for no error, after that the
compiler will store the file as a .obj file of the same name, which is termed as the object file. Although this .obj file will not be
executable. After the compilation, the process is continued by the assembler section.
Assembler: This part usually generates the Object code, after taking the assembly-level code from the compiler. This object code is
quite similar to the machine code or the set of binary digits. After this assembler part, The Linker continues the process, producing an
executable.exe file at the end.
Linker − Linker is another important part of the compilation process. It takes the object code and link it with other library files, these
library files are not the part of our code, but it helps to execute the total program. After linking the Linker generates the final Machine
code which is ready to execute.
Loader − A program, will not be executed until it is not loaded in to Primary memory. Loader helps to load the machine code to RAM
and helps to execute it. While executing the program is named as Process. So process is (Program in execution).