You are on page 1of 7

SYSTEM SOFTWARE MID-SEM

1. Define compiler. List the different types of compiler.


Ans. A compiler is a program that translates code written in one programming language
(the source language) into another language (the target language), typically machine code
that can be executed by a computer. Compilers are used to convert high-level programming
languages, such as C or Java, into machine code that can be run on a specific type of
There are different types of compilers, including:
i. Single-pass compilers: These process the source code in a single pass and are
typically simpler.
ii. Multi-pass compilers: These process the source code in multiple passes and
have more advanced features.
iii. Interpreter-based compilers: These execute the source code instead of
generating machine code and can be more flexible and easier to debug.
iv. Just-In-Time (JIT) compilers: These execute the source code at runtime and
adapt to the specific environment.
v. Hybrid compilers: These combine features of multiple types of compilers.
vi. Cross-compilers: These generate code for different platforms than the one
they are running on.
vii. Static compilers: These generate machine code that can be executed without
an interpreter and are useful for systems with limited resources.
viii. Dynamic compilers: These generate machine code on the fly during execution
and are useful for systems with more resources.

2. What kind of errors can be detected during synthesis phase?


Ans. During the synthesis phase, a variety of errors can be detected, including:
Syntax errors: These occur when the source code does not conform to the rules of
the programming language. This can include things like missing semicolons,
mismatched parentheses, or incorrect variable types.
Type errors: These occur when a variable or expression is used in a way that is not
consistent with its type. For example, trying to perform a mathematical operation on
a string variable.
Logic errors: These occur when the source code is syntactically correct but does not
produce the desired results. This can include things like off-by-one errors, infinite
loops, or incorrect use of control flow statements.
Resource errors: These occur when the source code tries to access a resource that is
not available, such as a file or a network connection.
Constraint errors: These occur when the source code violates design constraints such
as timing, area and power consumption.
Uninitialized variables: These occur when a variable is used before it has been
assigned a value.
Unsupported constructs: These occur when the source code uses constructs or
features that are not supported by the target platform or device.
Deprecated features: These occur when the source code uses features that have
been deprecated or removed from the target platform or device.
It is worth noting that not all errors will be found during the synthesis phase, and some
may only be detected during the implementation phase or during testing.

3. What are Compiler construction tools?

Ans. Compiler construction tools are software programs or libraries that aid in the
development of compilers. They can include a variety of different types of tools,
including:
i. Lexers (or scanners): These are used to break down the source code into a series
of tokens, which can then be easily parsed by the compiler.
ii. Parsers: These are used to analyse the structure of the source code and ensure
that it is syntactically correct.
iii. Symbol tables: These are used to store information about the variables, functions,
and other symbols used in the source code.
iv. Code generators: These are used to generate machine code or assembly code
from the intermediate representation of the source code.
v. Optimizers: These are used to improve the performance of the generated code by
making it more efficient.
vi. Debuggers: These are used to help locate and fix errors in the source code.
vii. IDEs: These are integrated development environments that provide a more user-
friendly interface to the compiler construction process and allow developers to
write, test and debug code more efficiently.
viii. Libraries: These are pre-written code that can be used as a building block for
compilers.
Some popular compiler construction tools include lex and yacc, ANTLR, Bison, and Flex.
4. What is lexeme?
Ans. A lexeme is the basic unit of meaning in a programming language. It is the sequence of
characters in the source code that form a recognizable token, such as a keyword, an
identifier, a number, or a symbol. The process of breaking down the source code into a
series of lexemes is known as lexical analysis, and is typically the first step in the
compilation process.
For example, in the statement "x = x + 1;", the lexemes would be "x", "=", "x", "+", "1", and
";". These lexemes are then passed to the next phase of the compiler, known as parsing,
where the structure of the program is analyzed and an intermediate representation of the
code is created.
The lexical analyzer (also known as lexer or scanner) is the component of the compiler that
performs lexical analysis and generates a stream of lexemes from the source code. It uses a
set of rules called regular expressions or state machines to recognize the different types of
lexemes in the source code.

5. Explain symbol table.


Ans. A symbol table is a data structure used by compilers to store information about the
variables, functions, and other symbols used in a program. It is typically created during the
parsing phase of the compilation process and is used throughout the remainder of the
compilation process to resolve references to symbols and to check for semantic errors.
Symbol table entries include information such as symbol name, type, scope, and memory
location. They are often implemented as hash tables for fast lookup and insertion. Symbol
tables are an essential tool for the compiler to keep track of the different elements of the
program and to perform semantic checking and code generation. They are also used during
runtime for resolving references to symbols and implementing features such as dynamic
linking and garbage collection.

6. What is parser? What are the types of Parser?


Ans. A parser is a software component that is used to analyze the structure of a program
and ensure that it is syntactically correct. It is typically the second step in the compilation
process, following lexical analysis. The parser takes the stream of lexemes generated by the
lexer and constructs an intermediate representation of the source code, such as an abstract
syntax tree (AST) or a control flow graph (CFG).
There are two main types of parsers: top-down and bottom-up.
Top-down parsers, such as recursive descent parsers, start with the highest-level construct
in the source code and work their way down to the individual lexemes.
Bottom-up parsers, such as shift-reduce parsers, start with the individual lexemes and work
their way up to the highest-level construct.
The parser checks for any syntax errors in the source code and generates an intermediate
representation of the code that can be easily understood by the subsequent phases of the
compiler, such as the code generator and optimizer.
It is worth noting that not all errors will be found during the parsing phase, some may only
be detected during the semantic analysis phase or during testing.

7. What is assembler?
Ans. An assembler is a type of system software that translates assembly language code into
machine code, which can be executed by a computer's central processing unit (CPU).
Assembly language is a low-level programming language that uses mnemonics
(abbreviations) to represent the basic operations of a CPU, such as moving data, performing
arithmetic, and controlling the flow of the program.
The assembler reads the assembly language code, one instruction at a time, and translates
it into the corresponding machine code instructions. It also handles tasks such as allocating
memory, resolving symbol references, and generating object files or executable files.
An assembly language program is typically written for a specific type of CPU, and the
assembler must be tailored to that CPU's instruction set. However, some assemblers can
generate code for multiple instruction sets, which is called a cross-assembler.
An assembler is considered a type of system software because it is used to create
executable code that runs on the computer's hardware. It is a low-level software that
operates close to the hardware level and is typically used to write operating systems,
device drivers, and other system-level programs.

8. Differentiate Tokens, Patterns, and Lexeme.


Ans. Token: A token is the smallest unit of a programming language that has a specific
meaning. It can be a keyword, an operator, a punctuation mark, or an identifier. For
example, in the statement "x = x + 1", the tokens are "x", "=", "x", "+", and "1". Tokens are
the output of the lexical analysis phase of a compiler.
Pattern: A pattern is a set of rules or regular expressions that define the structure of a
token. For example, a pattern for an identifier token might be a combination of letters,
digits, and underscores, starting with a letter. Patterns are used by the lexical analyzer to
identify and extract tokens from the source code.
Lexeme: A lexeme is the specific sequence of characters that make up a token. For example,
in the statement "x = x + 1", the lexemes for the identifier token are "x" and "x". A lexeme is
the actual sequence of characters that the pattern defines.
In short, Tokens are the smallest unit of a language, Patterns are the set of rules that define
the structure of a token, and Lexemes are the sequence of characters that make up a token.

9. List the operations on languages.


Ans. In the context of system software, the following operations are commonly performed
on languages:
i. Lexical analysis: The process of breaking down the source code into a stream of
tokens, which are the smallest units of the language that have a specific meaning.
ii. Syntax analysis (or parsing): The process of checking the source code for
grammatical correctness and building a parse tree, which represents the structure
of the source code in a hierarchical fashion.
iii. Semantic analysis: The process of checking the source code for semantic
correctness and adding meaning to the parse tree, such as type checking and
symbol table creation.
iv. Intermediate code generation: The process of creating an intermediate
representation of the source code, such as three-address code or an abstract
syntax tree, which can be used for further processing or optimization.
v. Code optimization: The process of making the intermediate code more efficient,
such as by removing redundant operations, reordering instructions, or inlining
function calls.
vi. Code generation: The process of converting the intermediate code into machine
code or object code, which can be executed by a computer.
vii. Assembly: The process of converting assembly language into machine code, which
can be executed directly by a computer's central processing unit (CPU)
viii. Linking: The process of combining multiple object files into a single executable file,
which can then be run on a computer.
ix. Loading: The process of copying the executable code from the disk into memory
so that it can be executed by the computer's CPU.
x. Execution: The process of running the code on a computer, performing the
operations specified in the source code.
These operations are typically performed by a compiler, interpreter or an assembler which
are types of system software.
10. What is Line Editor?
Ans. A line editor is a type of text editor that allows the user to edit one line of text at
a time. It is typically used in a command-line interface and is often built into the
operating system. Line editors are less common than full-screen text editors, but they
can be useful for certain types of tasks, such as editing configuration files or writing
scripts. Examples of line editors include ed, ex, and sed.

11.List the properties of LR parser.


Ans.
i. Deterministic: LR parsers are deterministic, meaning that they make parsing
decisions based on a fixed set of rules.
ii. Table-driven: LR parsers use tables to determine which actions to take during
parsing. These tables are generated by a separate program called a parser
generator.
iii. Left-to-right scanning: LR parsers read the input from left to right and construct
the parse tree incrementally.
iv. Bottom-up parsing: LR parsers construct the parse tree from the leaves
(terminals) to the root (start symbol) using a set of reduction rules.
v. Capable of handling context-free grammars: LR parsers can handle any context-
free grammar, making them more powerful than some other types of parsers such
as LL parsers.
vi. Error recovery: LR parsers can recover from errors in the input by using special
error-handling rules.
vii. More memory efficient: LR parsers use less memory than other types of parsers,
such as Earley parsers or Tomita parsers.
viii. Handle ambiguous grammars: LR parser can handle the ambiguous grammars and
can choose the correct parse tree among them.
ix. Generates the parse tree or abstract syntax tree: LR parser can generate parse
tree or abstract syntax tree.

12.Define Ambiguous Grammar.


Ans. An ambiguous grammar is a grammar for which there exists at least one string
that has more than one parse tree. This means that there are different ways to
interpret the structure of the string based on the grammar rules. This can be
problematic because it can lead to multiple and potentially conflicting interpretations
of the input. An ambiguous grammar can lead to unexpected behaviour in the parser
and can make it difficult to understand the meaning of the input. Ambiguity can be
resolved by rewriting the grammar to remove the ambiguity, or by using a parsing
algorithm that can handle ambiguous grammars.

13.What is the purpose of Debugger?


Ans. A debugger is a software tool that is used to identify and fix errors, also known as
bugs, in computer programs. It allows developers to step through the execution of a
program, line by line, and to inspect the values of variables and the state of the program at
each step. This allows developers to identify the source of errors, such as logical errors or
memory leaks, and to fix them.
Some of the main features of debuggers include:
 Breakpoints: allow the developer to pause the execution of the program at
specific points, so that the state of the program can be inspected.
 Step-by-step execution: allows the developer to execute the program one line at a
time, so that the effect of each instruction can be observed.
 Watch points: allow the developer to monitor the value of specific variables, and
to pause the execution of the program when the value of a variable changes.
 Stack trace: displays the sequence of function calls that led to the current point in the
execution of the program, so that the developer can understand the context in which
an error occurred.
 Memory inspection: allows the developer to inspect the contents of memory,
including the values of variables, to identify memory leaks or other problems.
In summary, the purpose of a debugger is to aid software developers to find and fix errors
in their code, to improve the quality and reliability of the software.

You might also like