CC
Unit 1Introduction Q. 1) Write the phases of compilers ?Ans : Phases of Compiler The method of compilation includes the sequence of different stages. Each phase takes a source programme in one representation and produces output in another representation. From its previous stage, each process takes input. The various stages of the compiler take place :Lexical Analysis Syntax Analysis Semantic Analysis Intermediate Code Generation Code Optimization Code Generation
Fig : phases of compiler Lexical Analysis : The first phase of the compilation process is the lexical analyzer phase. As input, it takes source code. One character at a time, it reads the source programme and translates it into meaningful lexemes. These lexemes are interpreted in the form of tokens by the Lexical analyzer. 2. Syntax Analysis : Syntax analysis is the second step of the method of compilation. Tokens are required as input and a parse tree is generated as output. The parser verifies that the expression made by the tokens is syntactically right or not in the syntax analysis process.3. Semantic Analysis : The third step of the method of compilation is semantic analysis. This tests whether the parse tree complies with language rules. The semantic analyzer keeps track of identifiers, forms, and expressions of identifiers. The output step of semantic analysis is the syntax of the annotated tree. 4. Intermediate Code Generation : The compiler generates the source code into an intermediate code during the intermediate code generation process. Between high-level language and machine language, intermediate code is created. You can produce the intermediate code in such a way that you can convert it easily into the code of the target computer. 5. Code Optimization : An optional step is code optimization. It is used to enhance the intermediate code so that the program's output can run quicker and take up less space. It eliminates redundant code lines and arranges the sequence of statements to speed up the execution of the programme. 6. Code Generation : The final stage of the compilation process is code generation. It takes as its input the optimised intermediate code and maps it to the language of the target computer. The code generator converts the intermediate code to the required computer's machine code. Q. 2) Write short notes on compilers ?Ans : Compiler● A compiler is a translator that translates the language at the highest level into the language of the computer. ● A developer writes high-level language and the processor can understand machine language. ● The compiler is used to display a programmer's errors. ● The main objective of the compiler is to modify the code written in one language without altering the program's meaning. ● When you run a programme that is written in the language of HLL programming, it runs in two parts.
Fig : Execution process of Compiler Q. 3) Describe single one pass compilers ?Ans : Single one pass compilers Pass is a full source software traversal. The programmer has two passes through the source program to traverse it. One - pass compiler - ● The one-pass compiler is only used once to access the programme. The one-pass compiler passes through the components of each compilation unit only once.This translates every component into its final machine code. ● In the single pass parser, it is scanned and the token is extracted when the line source is processed. ● The syntax of each line is then evaluated and the structure of the tree is constructed. The code is created after the semantic portion. ● For every line of code, the same procedure is repeated until the whole programme is compiled. ● Compiler source code is directly translated into computer code in a single pass. For example : The Pascal language.
Fig : single pass compiler Problem with single pass compiler ● Due to the context of expressions that are constrained, we can not optimise very well.● Since we can not backup and process it again, it should be constrained or simplified by grammar.● Command interpreters such as bash/sh/tcsh can be regarded as a single pass parser, but as soon as they are processed, they also execute the entry. Q. 4) Write the different compilers construction tools ?Ans : Compiler Construction Tools As computer-related technology spread all over the world, compiler construction instruments were added. They are also known as compilers, generators of compilers, or translators.These tools use a particular language or algorithm for the compiler portion to be specified and implemented. The tools for compiler construction are below. Parser Generator It generates an input syntax analyzer (parser) based on a grammatical programming language description or context-free grammar. It is beneficial because the process of syntax analysis is extremely complex and takes more manual and compilation time. Example : PIC, EQM
Fig : parser generator 2. Scanner Generator It produces lexical analyzers based on tokens of a language from the input that consists of a periodic expression description. To understand the periodic expression, it generates a finite automaton. Example : LEX
Fig : scanner generator 3. Automatic Code Generator It produces the language of the computer for the target machine. Each intermediate language operation is interpreted using a series of rules and is then taken by the code generator as an input. A method of template matching is used. Using templates, an intermediate language statement is replaced by its corresponding machine language statement. 4. Syntax directed translation engines This produces a three address format intermediate code from the input consisting of a parse tree. These engines have routines for traversing the parse tree and creating the intermediate code afterwards. In this, one or more translations are connected with each node of the parse tree. 5. Data- flow analysis enginesFor code optimization, this method is helpful. Here, the user provides details and the intermediate code is compared to evaluate any relationship. It is also known as the analysis of data-flow. It allows you to figure out how values are transferred to another part from one part of the programme. 6. Compiler construction toolkit It offers an integrated collection of routines that assist in building compiler components or building different compiler phases. Q. 5) What are the features of a compiler ?Ans : Features of Compilers● Maintaining the right interpretation of the code● The speed of the target code● Understand prototypes for legal and illegal systems● Good documentation / management of errors
● Correctness
● Speed of compilation
● Code debugging help
Q. 6) Write the task of compilers ?Ans : Task of Compilers Tasks which are performed by compilers :● Divides the source programme into parts and imposes on them a grammatical structure.● Allows you from the intermediate representation to construct the desired.● target programme and also create the symbol table.● Compiles and detects source code errors.● Storage of all variables and codes is handled.● Separate compilation support.● Learn, interpret, and translate the entire programme to a semantically equivalent.● Depending on the computer sort, conversion of the source code into object code Q. 7) Write the classification of compilers ?Ans : Classification of Compilers ● Single pass● Multi pass● Load and go● Debugging or optimizing Q. 8) Describe how a language is processed diagrammatically ?Ans : Processed Language Skeletal source program↓Preprocessor↓Source program↓Compiler↓Target assembly program↓Assembler↓Relocatable machine code↓Loader/ link editor ←library, relocatable object files↓Absolute machine codeQ. 9) What are these two components of a compilation? Briefly clarify.Ans : components of compilersThe two parts of the compilation are Interpretation and Synthesis. The portion of the analysis splits the source programme into constituent parts and provides an intermediate representation of the source programme. From the intermediate representation, the synthesis part constructs the desired target programme. Q. 10) List the study portion of the subparts or stages ?Ans : The study is composed of three stages:● Linear Analysis.
● Hierarchical Analysis.
● Semantic Analysis.
0 matching results found