KEMBAR78
SS Chapter 2 Overview of Language Processor | PDF | Assembly Language | Variable (Computer Science)
0% found this document useful (0 votes)
20 views15 pages

SS Chapter 2 Overview of Language Processor

The document provides an overview of programming languages and language processors, explaining their roles in converting human-readable code into machine code. It details types of language processors, including compilers, assemblers, and interpreters, and discusses the differences between them. Additionally, it addresses concepts like semantic, execution, and specification gaps, as well as the fundamentals of language processing and specification.

Uploaded by

phs
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)
20 views15 pages

SS Chapter 2 Overview of Language Processor

The document provides an overview of programming languages and language processors, explaining their roles in converting human-readable code into machine code. It details types of language processors, including compilers, assemblers, and interpreters, and discusses the differences between them. Additionally, it addresses concepts like semantic, execution, and specification gaps, as well as the fundamentals of language processing and specification.

Uploaded by

phs
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/ 15

Apollo Institute of Engineering and Technology

SYSTEM SOFTWARE - UNIT – II – OVERVIEW OF LANGAUGE PROCESSORS

Q. WHAT IS PROGRAMMING LANGUAGE? EXPLAIN LANGUAGE PROCESSORS.


• A "programming language" is a set of rules and syntax.
• It is used to write instructions that a computer can understand and execute.
• It allows developer to create software applications by writing code in a human-
readable format.
• A language processor, or language translator, is a computer program that
convert source code from one programming language to another language or
to machine code (also known as object code).
• They also find errors during translation.
• A "language processor" is a software tool that translates this human-readable
code (written in a programming language) into machine code that the
computer can directly understand and run.
• It acts like as a bridge between the programmer and the computer's hardware.
• Computer programs are generally written in high-level languages (like C++,
Python, and Java).
• Compilers translate programs written in high-level languages into machine code
that a computer understands and assemblers translate programs written in low-
level or assembly language into machine code.
• The programs are written mostly in high-level languages
like Java, C++, Python etc. and are called source code.
• These source code cannot be executed directly by the computer and must be
converted into machine language to be executed.
• Hence, a special translator system software is used to translate the program
written in a high-level language into machine code is called Language Processor
and the program after translated into machine code (object program/object
code).

TYPES OF LANGUAGE PROCESSORS (MOST MOST IMP)


The language processors can be any of the following three types:

1. Compiler
• The language processor that reads the complete source program written in high-
level language as a whole in one go and translates it into an equivalent program
in machine language is called a Compiler. Example: C, C++, C#.
MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 1
• In a compiler, the source code is translated to object code successfully if it is free
of errors.
• The compiler specifies the errors at the end of the compilation with line numbers
when there are any errors in the source code.
• The errors must be removed before the compiler can successfully recompile the
source code again the object program can be executed number of times without
translating it again.

2. Assembler
• The Assembler is used to translate the program written in Assembly language
into machine code.
• The source program is an input of an assembler that contains assembly language
instructions.
• The output generated by the assembler is the object code or machine code
understandable by the computer.
• Assembler is basically the 1st interface that is able to communicate humans with
the machine.
• We need an assembler to fill the gap between human and machine so that they
can communicate with each other.
• Code written in assembly language is some sort of mnemonics(instructions) like
ADD, MUL, MUX, SUB, DIV, MOV and so on. and the assembler is basically able
to convert these mnemonics in binary code.
• Here, these mnemonics also depend upon the architecture of the machine.
• For example, the architecture of intel 8085 and intel 8086 are different.

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 2


3. Interpreter
• The translation of a single statement of the source program into machine code
is done by a language processor and executes immediately before moving on to
the next line is called an interpreter.
• If there is an error in the statement, the interpreter terminates its translating
process at that statement and displays an error message.
• The interpreter moves on to the next line for execution only after the removal
of the error.
• An Interpreter directly executes instructions written in a programming without
previously converting them to an object code or machine code. An interpreter
translates one line at a time and then executes it.
• Example: Perl, Python and Matlab.

Q. WHAT IS THE DIFFERENCE BETWEEN COMPILER AND INTERPRETER? (MOST IMP)

Compiler Interpreter

• A compiler is a program that • An interpreter takes a source


converts the entire source code program and runs it line by line,
of a programming language into translating each line as it comes to
executable machine code for a it.
CPU.

• The compiler takes a large • An interpreter takes less amount


amount of time to analyze the of time to analyze the source code
entire source code but the but the overall execution time of
overall execution time of the the program is slower.
program is comparatively faster.

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 3


Compiler Interpreter

• The compiler generates the error • Its Debugging is easier as it


message only after scanning the continues translating the program
whole program, so debugging is until the error is met.
hard as the error can be present
anywhere in the program.

• The compiler requires a lot of • It requires less memory than a


memory for generating object compiler because no object code
codes. is generated.

• Generates intermediate object • No intermediate object code is


code. generated.

• For Security purpose compiler is • The interpreter is a little


more useful. vulnerable in case of security.

• Examples: C, C++, C# • Examples: Python, Perl, Ruby.

Q. EXPLAIN SEMANTIC GAP, EXECUTION GAP AND SPECIFICATION GAP. (MOST IMP)
• A "semantic gap" refers to the difference between how humans understand
high-level concepts and how computers understand data, essentially the gap
between human language and machine language.
• An "execution gap" is the difference between the program written in a
programming language and its actual execution on a computer, meaning how
the code translates to machine instructions.
• A "specification gap" is the difference between a high-level description of a task
in a user's language and the detailed specifications needed to implement it in a
programming language, essentially the gap between user and technical details.
EXAMPLE:
Semantic Gap:
• A user searching for "pictures of cats" on a search engine might expect images of cute
but the computer might return results based on technically match the word "cat" but
could include less proper relevant cat images.
• So that this gap highlights the difficulty of translating complex human meaning into
machine-readable code.
MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 4
Execution Gap:
• Writing a program to calculate the average of a list of numbers in Python might look
simply, but the actual execution on the computer involves complex machine
instructions to perform arithmetic operations, memory management, and data
management.
• The execution gap is bridged by a compiler which translates the high-level code into
machine language that the computer can understand.

Specification Gap:
• A user might ask to "find the best restaurant near me" on a mobile app, but the
developer needs to define specific criteria like location, area, rating, and price range
to translate this request into a query that the app can execute.
• This gap is addressed by carefully defining requirements and translating them into
exact instructions for the software.

Q. WHAT IS THE DIFFERENCE BETWEEN PROBLEM ORIENTED LANGUAGE AND


PROCEDURE ORIENTED LANGUAGE?
• Problem-oriented languages are designed for specific types of problems, allowing
programmers to solve them with fewer statements.
• procedure-oriented languages are general-purpose and can be used for various tasks,
often requiring more code.
• Here's a more detailed breakdown:
Problem-Oriented Languages:
• Focus:
These languages are designed to solve specific types of problems, such as scientific
simulations, business data processing, or compiler development.
• Approach:
They focus on describing the desired outcome rather than the exact steps to achieve
it.
• Examples:
GPSS (for simulation), SQL (for database queries), and specialized languages used in
specific domains.
• Strengths:
Allow programmers to solve problems with fewer statements and can be more
efficient for the specific problem area.
• Weaknesses:
Their use is limited to the particular problem areas for which they were designed.

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 5


Procedure-Oriented Languages:
• Focus: These languages emphasize the procedures or functions that manipulate data
to solve problems.
• Approach: They follow a top-down approach, breaking down problems into smaller,
manageable procedures or functions.
• Data and Functions: Data and functions are treated separately.
• Examples: C, Pascal, FORTRAN, COBOL.
• Strengths: Can be easier to understand and maintain for smaller projects.
• Weaknesses: Can become complex and harder to manage in larger projects, and code
may not be easily reusable.

Q. WHICH ACTIVITY REDUCE SPECIFICATION GAP? EXPLAIN IT WITH EXAMPLE.

• Specification gap refers to the difference between the customer’s expectations and
the product or service specifications defined by the organization.
• To reduce the specification gap, activities that align customer expectations with
product or service design are necessary.
• Requirement analysis is the process of gathering, documenting, and managing
customer requirements to ensure that the final product or service meets customer
expectations.
• This activity helps reduce the specification gap by ensuring that the customer's needs
and expectations are clearly understood and reflected in the product specifications.

Example: Consider a company developing a mobile application for online food


delivery.

1. Customer Expectation:
o Customers expect a user-friendly interface, quick loading time, and secure
payment options.
2. Requirement Analysis:
o The development team conducts detailed interviews and surveys with potential
customers to identify key expectations like:
▪ Simple navigation and user interface
▪ Payment gateway integration with security features
▪ Real-time order tracking
3. Defined Specification:
o The development team creates a detailed specification document including:
▪ Use of a minimalist design for ease of use
▪ Integration with secure payment services like PayPal, UPI, and credit cards
▪ Order tracking feature using GPS.

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 6


Q. WHICH ACTIVITY REDUCE EXECUTION GAP? EXPLAIN IT WITH SUITABLE EXAMPLE.

• Execution gap refers to the difference between the defined product or service
specifications and the actual product or service delivered.
• It occurs when there is a failure to execute the planned design or specifications
correctly during the production or delivery process.
• Quality control (QC) and monitoring involve checking and verifying that the
actual product or service matches the defined specifications during the
production or service delivery process.
• This activity helps identify and correct deviations, ensuring that the final output
meets the intended design.

Example:
Consider a company manufacturing smartphones.

1. Defined Specification:
o The smartphone should have:
▪ 6.5-inch display, 128 GB storage, 5000 mAh battery
2. Production (Potential Execution Gap):
o During production, some phones are mistakenly installed with a 4000
mAh battery instead of 5000 mAh.
o This creates an execution gap since the delivered product does not meet
the defined specification.
3. Quality Control and Monitoring:
o The company conducts regular quality checks:
▪ Testing battery capacity in the production line.
▪ Randomly selecting samples for quality verification.
o The quality control team identifies the battery issue and corrects it before
shipment.

Q. EXPLAIN LANGUAGE PROCESSING ACTIVITIES.

Phase Activity Description


Lexical Analysis Tokenizing source code
Syntax Analysis Building parse tree
Semantic Analysis Type checking and logic checking
Program
Intermediate Code Generation Low-level code representation
Generation
Code Optimization Optimized code
Code Generation Generating machine code
Error Handling Detecting compile-time errors

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 7


Phase Activity Description
Loading Loading program
Program Linking Linking program
Execution Execution Running instructions
Runtime Error Handling Handling runtime issues

Example:
#include <stdio.h>
int main() {
int a, b = 10;
a = b + 5;
printf("%d", a);
return 0;
}

Step Activity Output/Action


Lexical Analysis Tokenizing the code int, a, b, =, 10, +, 5
Syntax Analysis Checking structure Valid
Semantic Analysis Type checking Valid
Intermediate Code Generation Convert to low-level code T1 = b + 5; a = T1
Optimization Remove redundancy No optimization needed
Code Generation Generate machine code LOAD R1, b
Loading Load into memory Code loaded into RAM
Linking Link standard library printf() linked
Execution Run instructions Output = 15
Runtime Error Handling Handle issues No error

Q. EXPLAIN FUNDAMENTAL OF LANGUAGE PROCESSING.

Language processing involves transforming human-readable code or language into a


format that a computer can understand and execute.

This process follows three fundamental rules:

1. Lexical Rules – Specify the information of valid lexical units in source language.
2. Syntax Rules – Specify the information of valid statements in source language.
3. Semantic Rules – Specify the logical valid statements
MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 8
1. Lexical Rules (Tokenization)

Lexical rules define how the input text or code is broken down into the smallest
meaningful units called tokens.

Key Components of Lexical Rules:


• Keywords
• Identifiers
• Constants
• Operators
• Special characters (punctuation, brackets, etc.)

Activities in Lexical Analysis:

✅ Removing whitespace and comments.


✅ Identifying tokens (keywords, identifiers, literals).
✅ Handling delimiters (semicolons, parentheses).

Example:
int a = b + 5;

Lexical Analysis Output (Tokens):

• int → Keyword
• a → Identifier
• = → Assignment operator
• b → Identifier
• + → Operator
• 5 → Integer literal
• ; → Terminator

Lexical Rule Example:


✅ int x = 10; → Valid identifier
❌ int 1x = 10; → Invalid identifier (starts with a number)

2. Syntax Rules (Grammar)

Syntax rules define the correct structure and order of tokens based on the language’s
grammar.

Key Components of Syntax Rules:

• Operator precedence
• Statement termination

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 9


• Conditional and loop structure
• Function definitions and calls

Activities in Syntax Analysis:

✅ Constructing a Parse Tree or Syntax Tree.


✅ Checking if the token sequence follows the defined grammar.
✅ Detecting syntax errors.

Syntax Rule Example:

✅ int x = 5; → Correct
❌ x int = 5; → Incorrect order

3. Semantic Rules (Meaning)

Semantic rules define the meaning and logical consistency of the statement. Even if
the syntax is correct, the statement may be semantically incorrect.

Key Components of Semantic Rules:


• Type compatibility
• Scope rules
• Function overloading and polymorphism
• Logical correctness

Activities in Semantic Analysis:

✅ Type checking.
✅ Function and variable scope validation.
✅ Operator compatibility checking.

Semantic Rule Example:


✅ int a = 5;
❌ int a = "hello"; (type mismatch)

Q. EXPLAIN THE FUNDAMENTALS OF LANGUAGE SPECIFICATION.

Language specification defines the formal structure, rules, and meaning of a


programming language. It serves as a blueprint that describes how programs written
in the language should be interpreted and executed by a compiler or an interpreter.

A language specification consists of three key components:

1. Lexical Specification – Defines the valid tokens (smallest units) in the language.
MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 10
2. Syntax Specification – Defines the structure (grammar) of valid statements in
the language.
3. Semantic Specification – Defines the meaning and behaviour of valid
statements.

1. Lexical Specification (Token Definition)

Lexical specification defines the basic building blocks of the language known as tokens.
Tokens are the smallest meaningful units in a program.

Components of Lexical Specification:


• Keywords – Reserved words (e.g., int, if, while)
• Identifiers – Names used for variables, functions, etc.
• Literals – Constant values (e.g., 5, "hello")
• Operators – Mathematical or logical symbols (+, -, &&)
• Separators – Characters used to separate tokens (;, ,, {, })

Example:
int sum = a + 5;

Tokens:
• int → Keyword
• sum → Identifier
• = → Assignment operator
• a → Identifier
• + → Operator
• 5 → Literal
• ; → Terminator

Lexical Rules:
• An identifier must start with a letter or underscore.
• Keywords cannot be used as identifiers.
• A literal value must match the specified type.

✅ Example:
• int x = 5; → Correct
• int 5x = 5; → ❌ Lexical Error (Identifier cannot start with a digit)

2. Syntax Specification (Grammar Rules)

Syntax specification defines the rules of statement formation in the language using a
formal grammar (like Context-Free Grammar (CFG)). It ensures that the code follows
a valid structural pattern.

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 11


Syntax Specification Includes:
• Grammar Rules – Defines how tokens are combined into valid statements.
• Operator Precedence and Associativity – Defines the order in which operators
are evaluated.
• Control Structures – Rules for if, else, for, while statements.

Syntax Rules Example:


✅ int x = 5; → Valid
❌ x int = 5; → Syntax Error

3. Semantic Specification (Meaning)

Semantic specification defines the meaning and logic of a valid program. Even if the
code is lexically and syntactically correct, it may still be semantically wrong.

Semantic Specification Includes:


• Type Checking – Ensures that operations are compatible with data types.
• Scope Rules – Defines the visibility and lifetime of variables.
• Function Calls – Ensures that functions are called with the correct arguments.
• Memory Allocation – Handles dynamic memory usage and validity.

Semantic Rules Example:


✅ int a = 5; → Correct
❌ int a = "text"; → Semantic Error

Q. WHICH TYPE OF GAP MAKES THE SOFTWARE BUGGY OR UNRELIABLE?


• An "execution gap" is the difference between the program written in a
programming language and its actual execution on a computer, meaning how
the code translates to machine instructions.
• A "specification gap" is the difference between a high-level description of a task
in a user's language and the detailed specifications needed to implement it in a
programming language, essentially the gap between user and technical details.
Q. EXPLAIN LANGUAGE PROCESSOR DEVELOPMENT TOOLS.

• Language Processor Development Tools are software tools used to create,


design, and implement programming languages and their processors (such as
compilers, interpreters, and assemblers).
• These tools help in analyzing, translating, and executing programs written in a
specific programming language.

Types of Language Processor Development Tools

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 12


1. Compiler Construction Tools
2. Interpreter Construction Tools
3. Assembler Construction Tools
4. Macro Processor Tools
5. Linker and Loader Tools
6. Debugger Tools

Tool Type Purpose Example Tools

Compiler It is used to convert source code to


Lex, Yacc
Construction Tools machine code

Interpreter
It is used to direct execution of code Python, Node.js
Construction Tools

Assembler It is used to convert assembly to


NASM, MASM
Construction Tools machine code

Macro Processor It is used to define and replace


M4, MASM
Tools macros

Linker and Loader It is used to link object files and load GNU Linker, Dynamic
Tools into memory Linker

It is used to monitor and fix runtime


Debugger Tools GDB, WinDbg
errors

Q. EXPLAIN MEMORY ALLOCATION IN BLOCK STRUCTURED LANGAUGE.


• In block-structured languages (e.g., C, C++, Java, Python), memory allocation
refers to the process of reserving and managing memory for variables, functions,
and objects during program execution. A block-structured language allows the
creation of nested blocks (scopes), where each block can have its own set of local
variables and definitions.
• Memory allocation is divided into three main types:

1. Static Allocation – Memory is allocated at compile time.


2. Stack Allocation – Memory is allocated at runtime using a stack.
3. Heap Allocation – Memory is dynamically allocated at runtime using a heap.

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 13


1. Static Memory Allocation
• Memory is allocated at compile time and assigned a fixed address.
• The allocated memory size and type remain fixed throughout the program’s
execution.
• Global variables and static variables are examples of static memory allocation.
• The allocated memory is not freed until the program terminates.

✅ Example:
int a = 10; // Static allocation

In this example, a is allocated at compile time, and memory is reserved for a until the
program ends.

✅ Characteristics:
✔️ Fixed size and location.
✔️ Fast access.
❌ Not suitable for dynamic data structures (e.g., linked lists).

2. Stack Memory Allocation

• Memory is allocated at runtime using a stack.


• The stack follows a Last In, First Out (LIFO) structure.
• Memory is allocated when a function is called and released when the function
exits.
• Local variables, function parameters, and return addresses are stored in the
stack.

✅ Example:

void func() {
int x = 5; // Stack allocation
}
When func() is called, memory for x is allocated on the stack.
When func() finishes execution, memory for x is automatically freed.

✅ Characteristics:
✔️ Fast allocation and deallocation.
✔️ Automatically managed.
❌ Size of the stack is limited (Stack Overflow error).

3. Heap Memory Allocation


• Memory is allocated at runtime using a heap.
• The heap is used for dynamic memory allocation.

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 14


• Unlike stack memory, heap memory is manually allocated and manually freed
using memory management functions.
• If not properly managed, it can lead to memory leaks.

✅ Example (in C):

int *ptr = (int *)malloc(sizeof(int));


*ptr = 10;
free(ptr);

1. malloc allocates memory on the heap.


2. Memory remains allocated until free() is called.

✅ Characteristics:
✔️ Flexible size and lifetime.
✔️ Suitable for large and dynamic data structures.
❌ Slower than stack allocation.

Q. WHAT IS FORWARD REFERENCE?

• A forward reference occurs when a program refers to a symbol (such as a


variable, function, or label) before it is defined or declared in the code.
• In simple terms, it means using an identifier (like a variable or function) before
the compiler or assembler has encountered its definition.

Example in C:

#include <stdio.h>
void func(); // Forward declaration
int main() {
func(); // Forward reference (calling before definition)
}
void func() {
printf("Hello, World!\n");
}

✅ Explanation:
1. func() is called in main() before it is defined.
2. A forward declaration (void func();) is used to inform the compiler about the
function before it is called.
3. Without the forward declaration, the compiler would generate an error.

MANISH GOHEL – ASST. PROFESSOR – CE DEPT. 15

You might also like