Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Compiler Design  >  Overview of Language Processing System Introduction to Compiler Design - Compiler

Overview of Language Processing System Introduction to Compiler Design - Compiler

Overview of Language Processing System

Overview of Language Processing System

The language processing system for high-level programming languages consists of several tools and program modules that together translate source programs into executable machine code, support program development, and manage program execution. Typical components are preprocessors, translators (compilers and interpreters), assemblers, and loader/link-editors. Each component performs specific tasks such as transforming source text, detecting errors, producing object code, resolving references and placing programs into memory for execution.

Preprocessor

A preprocessor produces input for a compiler by transforming or augmenting the source text before compilation begins. Preprocessors are commonly used to provide conveniences and language features that are not part of the core source language.

Common preprocessor functions

  • Macro processing: Allows the definition of macros that act as shorthand for longer constructs. A macro expansion replaces macro invocations with the corresponding expanded code.
  • File inclusion: Includes the contents of header or other source fragments into the program text to enable modularity and reuse.
  • Conditional compilation: Enables compilation of selected portions of code depending on compile-time conditions (useful for platform-specific code or debug builds).
  • Rational preprocessor: Augments older or simpler languages with more modern control-flow and data-structuring facilities by transforming added constructs into the base language constructs.
  • Language extensions: Adds small language features or notational conveniences by translating them into standard language constructs (for example, adding syntactic sugar or domain-specific constructs).

Compiler

A compiler is a translator program that reads a program written in a high-level language (the source program) and translates it into an equivalent program in a lower-level language, typically machine code or an intermediate code (the object program). Compilers also perform error detection and report diagnostic messages to the programmer.

To execute a program written in a high-level language, two broad steps occur:

  • The source program is translated (compiled) into an object program (machine code or intermediate code).
  • The resulting object program is loaded into memory and executed.
Compiler

Typical phases of a compiler

  • Lexical analysis: Converts a stream of characters into a stream of tokens (identifiers, keywords, literals, operators).
  • Syntax analysis (parsing): Analyses the token stream according to the grammar to build a parse tree or abstract syntax tree (AST).
  • Semantic analysis: Checks semantic rules (type checking, scope, declarations) and annotates the AST; builds or consults the symbol table.
  • Intermediate code generation: Produces a language-independent intermediate code (three-address code, syntax-directed translation) representing program behaviour.
  • Optimisation: Improves the intermediate code or target code to make execution faster or use less space while preserving semantics.
  • Code generation: Translates intermediate code into target machine code or assembly.
  • Code emission and assembly: Emits the final object code; may produce relocation information and symbol tables for linking.
  • Error handling and diagnostics: Reports lexical, syntactic and semantic errors and provides useful diagnostics to the programmer.
MULTIPLE CHOICE QUESTION
Try yourself: What is the purpose of a preprocessor in a language processing system?
A

To translate the source program into an object program

B

To include header files into the program text

C

To execute the program written in a high-level programming language

D

To augment older languages with modern flow-of-control and data structuring facilities

Assembler

Programmers found machine language hard to read and write, so symbolic mnemonics were introduced for machine instructions. A program called an assembler automates translation from an assembly language (the mnemonic form) to machine language (the object program).

  • The input to an assembler is called the source program; the output is the machine-language translation (the object program).
  • The assembler typically also generates relocation and symbol information used later by the loader/link-editor.
  • Assemblers may support assembler directives (pseudo-ops) for data allocation, constants, and conditional assembly.

Interpreter

An interpreter is a program that directly executes statements of a source program without producing a separate object program that is later loaded for execution. The interpreter analyses and executes the program representation on the fly, giving the impression that the source program is executed as if it were machine language.

Interpreter

Phases of interpretation

  1. Lexical analysis
  2. Syntax analysis
  3. Semantic analysis
  4. Direct execution (interpretation) of the parsed and analysed constructs

Advantages

  • Modifications to the user program can be quickly tested because changes take effect immediately without a separate compile step.
  • Dynamic typing and dynamic changes of object types are easier to support.
  • Interactive debugging is simplified because the interpreter can execute a program statement by statement.
  • An interpreter can make a language more platform independent by providing a machine-dependent runtime engine while keeping the source code portable.

Disadvantages

  • Execution is usually slower than compiled code because interpretation incurs runtime overhead.
  • Memory consumption can be greater since the interpreter and its runtime structures remain resident during execution.

After translation by an assembler or compiler, the resulting object programs must be placed into memory and prepared for execution. A loader is a program that places object code into memory and prepares it for execution. A link-editor (linker) combines multiple object modules and resolves external references to produce a complete executable.

Why a separate loader/link-editor?

If the assembler or compiler directly placed object code into memory and transferred control to it, the translator would remain in memory and be wasted during execution; retranslation would also be required each run. Separating translation and loading improves efficiency.

Relocation

Relocation is the task of adjusting program addresses so that object code modules can be placed at arbitrary memory locations. A relocation loader or link-editor updates addresses and references so modules can be loaded anywhere in memory.

Typical functions performed by relocation loaders / link-editors

  • Combine object modules from different source files into a single executable or load module.
  • Resolve external references and symbols between object modules (symbol resolution).
  • Adjust addresses and relocate code and data so they reference correct memory locations (relocation).
  • Load the relocated code and data into main memory and transfer control to the program's entry point.

MULTIPLE CHOICE QUESTION
Try yourself: What is the purpose of an assembler in programming?
A

To automate the translation of assembly language into machine language.

B

To execute a source program as if it were machine language.

C

To load programs into memory and prepare them for execution.

D

To interpret high-level programming languages.

Translator

A translator is any program that takes a program written in one language and produces an equivalent program in another language. Translators also perform error detection and report violations of language rules to the programmer.

  • Translators detect and report lexical, syntactic and semantic errors when the source program violates the high-level language's specification.
  • Important roles of a translator include translating the high-level language (HLL) input into an equivalent machine-level (ML) output and providing diagnostic messages for programmer errors.

Types of Translators

  • Interpreter
  • Compiler
  • Preprocessor
  • Assembler

List of Compilers (examples)

  • Ada compilers
  • ALGOL compilers
  • BASIC compilers
  • C# compilers
  • C compilers
  • C++ compilers
  • COBOL compilers
  • Java compilers

The document Overview of Language Processing System Introduction to Compiler Design - Compiler is a part of the Computer Science Engineering (CSE) Course Compiler Design.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
26 videos|92 docs|30 tests

FAQs on Overview of Language Processing System Introduction to Compiler Design - Compiler

1. What is a language processing system?
Ans. A language processing system is a software tool or framework that is used to analyze and process human language. It involves various components such as lexical analysis, syntax analysis, semantic analysis, and code generation. The main purpose of a language processing system is to convert human-readable code or text into machine-readable instructions.
2. What is the role of a compiler in language processing?
Ans. A compiler is a key component of a language processing system. It is responsible for translating high-level programming languages into low-level machine code that can be directly executed by a computer. The compiler performs various tasks such as lexical analysis, syntax analysis, semantic analysis, optimization, and code generation. It helps in improving the efficiency and performance of the code.
3. What are the different phases involved in compiler design?
Ans. Compiler design involves several phases or stages, which are: 1. Lexical Analysis: This phase involves breaking the input code into tokens or lexemes. 2. Syntax Analysis: This phase checks the syntactical correctness of the code and builds a parse tree or an abstract syntax tree. 3. Semantic Analysis: This phase performs semantic checks and assigns meaning to the code. 4. Intermediate Code Generation: This phase generates an intermediate representation of the code. 5. Code Optimization: This phase optimizes the intermediate code to improve performance. 6. Code Generation: This final phase generates the target machine code.
4. What is the importance of compiler design in computer science engineering?
Ans. Compiler design is of great importance in computer science engineering for the following reasons: 1. Efficient Code Execution: Compilers help in translating high-level programming languages to machine code, optimizing it for efficient execution on a computer. 2. Language Development: Compiler design is crucial for developing new programming languages or extending existing ones. 3. Error Detection: Compilers perform various checks during the compilation process, helping in detecting and reporting errors in the code. 4. Performance Optimization: Compilers employ various optimization techniques to improve the performance of the code, resulting in faster execution and reduced resource utilization. 5. Portability: Compilers enable code to be written once and executed on different platforms, making software development more portable and flexible.
5. What is the difference between a compiler and an interpreter?
Ans. The main differences between a compiler and an interpreter are: 1. Execution: A compiler translates the entire source code into machine code before execution, whereas an interpreter translates and executes the code line by line. 2. Output: A compiler generates an executable file or binary code as output, which can be directly executed. An interpreter does not generate an executable file; it directly executes the code. 3. Performance: Compiled code tends to have better performance as it is optimized during the compilation process. Interpreted code may have slower execution due to the need for interpreting each line at runtime. 4. Portability: Compiled code is often platform-dependent, requiring specific versions for different operating systems. Interpreted code is generally more portable as the interpreter can run on different platforms. 5. Debugging: Debugging compiled code can be more challenging as it requires analyzing the machine code. Interpreted code is easier to debug as errors can be reported at the line of code being executed.
Related Searches
ppt, study material, Important questions, past year papers, Overview of Language Processing System Introduction to Compiler Design - Compiler, Semester Notes, Free, Summary, Sample Paper, Extra Questions, Objective type Questions, shortcuts and tricks, Overview of Language Processing System Introduction to Compiler Design - Compiler, Previous Year Questions with Solutions, Overview of Language Processing System Introduction to Compiler Design - Compiler, mock tests for examination, Viva Questions, MCQs, Exam, pdf , video lectures, practice quizzes;