<<

Chapter 5 What is ?

A compiler is a special program that processes statements written in a particular and turns them into language or "code" that a 's processor uses. Typically, a programmer writes language statements in a language such as Pascal or one line at a time using an editor. The file that is created contains what are called the source statements. The programmer then runs the appropriate language compiler, specifying the name of the file that contains the source statements. OR

A compiler is a that translates computer code written in one programming language (the source language) into another language (the target language). The name compiler is primarily used for programs that translate from a high-level programming language to a lower level language (e.g., language, , or ) to create an program.

Role of Compiler

 Compliers reads the source code, outputs executable code  Translates written in a higher-level language into instructions that computer can understand. It converts the text that a programmer writes into a format the CPU can understand.  The process of compilation is relatively complicated. It spends a lot of time analyzing and processing the program.  The executable result is some form of machine-specific binary code.

Memory allocation Memory allocation is primarily a operation but is managed through and software applications. Memory allocation process is quite similar in physical and virtual memory management. Programs and services are assigned with a specific memory as per their requirements when they are executed. Once the program has finished its operation or is idle, the memory is released and allocated to another program or merged within the primary memory.

Memory allocation has two core types;

 Static Memory Allocation: The program is allocated memory at .  Dynamic Memory Allocation: The programs are allocated with memory at run time.

Aspects or Phases of a Compilation

The compilation process is a sequence of various phases. Each phase takes input from its previous stage, has its own representation of source program, and feeds its output to the next phase of the compiler.

We basically have two phases of , namely phase and Synthesis phase. Analysis phase creates an intermediate representation from the given source code. Synthesis phase creates an equivalent target program from the intermediate representation.

Symbol Table – It is a structure being used and maintained by the compiler, consists all the identifier’s name along with their types. It helps the compiler to function smoothly by finding the identifiers quickly. The compiler has two modules namely . Front-end constitutes of the Lexical analyzer, semantic analyzer, syntax analyzer and intermediate code generator. And the rest are assembled to form the back end. 1. Lexical Analyzer – It reads the program and converts it into tokens. It converts a stream of lexemes into a stream of tokens. Tokens are defined by regular expressions which are understood by the lexical analyzer. It also removes white-spaces and comments. 2. Syntax Analyzer – It is sometimes called as parser. It constructs the . It takes all the tokens one by one and uses Context Free Grammar to construct the parse tree. Why Grammar ? The rules of programming can be entirely represented in some few productions. Using these productions we can represent what the program actually is. The input has to be checked whether it is in the desired format or not. can be detected at this level if the input is not in accordance with the grammar.

3.Semantic Analyzer – It verifies the parse tree, whether it’s meaningful or not. It furthermore produces a verified parse tree.It also does type checking, checking and Flow control checking. 4.Intermediate Code Generation- After semantic analysis the compiler generates an intermediate code of the source code for the target machine. It represents a program for some abstract machine. It is in between the high-level language and the machine language. This intermediate code should be generated in such a way that it makes it easier to be translated into the target machine code. 5.Code Optimization The next phase does code optimization of the intermediate code. Optimization can be assumed as something that removes unnecessary code lines, and arranges the sequence of statements in order to speed up the program without wasting resources (CPU, memory). 6.Target Code Generator – The main purpose of Target Code generator is to write a code that the machine can understand and also , etc. The output is dependent on the type of assembler. This is the final stage of compilation.

Code Optimisation The programs represented in the intermediate code form usually contains much scope for optimisation both in terms of storage space as well as run time efficiency of the intended output program. Sometimes the input program itself contains such scope. Besides that, the process of generating the intermediate code representation usually leaves much room for such optimisation. Hence, compilers usually implement explicit steps to optimise the intermediate code. OR Optimization is a technique, which tries to improve the code by making it consume less resources (i.e. CPU, Memory) and deliver high speed. In optimization, high-level general programming constructs are replaced by very efficient low-level programming codes. A code optimizing process must follow the three rules given below:

 The output code must not, in any way, change the meaning of the program.

 Optimization should increase the speed of the program and if possible, the program should demand less number of resources.

 Optimization should itself be fast and should not delay the overall compiling process. Efforts for an optimized code can be made at various levels of compiling the process.

 At the beginning, users can change/rearrange the code or use better algorithms to write the code.

 After generating intermediate code, the compiler can modify the intermediate code by address calculations and improving loops.

 While producing the target machine code, the compiler can use of memory hierarchy and CPU registers. Optimization can be categorized broadly into two types : Machine independent and Machine Dependent. Machine-independent Optimization In this optimization, the compiler takes in the intermediate code and transforms a part of the code that does not involve any CPU registers and/or absolute memory locations.For example do { item = 10; value = value + item; } while(value<100); This code involves repeated assignment of the identifier item, which if we put this way: Item = 10; do { value = value + item; } while(value<100); should not only save the CPU cycles, but can be used on any processor. Machine-dependent Optimization Machine-dependent optimization is done after the target code has been generated and when the code is transformed according to the target machine architecture. It involves CPU registers and may have absolute memory references rather than relative references. Machine- dependent optimizers put efforts to take maximum advantage of memory hierarchy. What Is ? In , an interpreter is a computer program that directly executes instructions written in a programming or , without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution:

1. Parse the source code and perform its behavior directly; 2. Translate source code into some efficient intermediate representation and immediately execute this; 3. Explicitly execute stored precompiled code made by a compiler which is part of the interpreter system. Role of Interpreter

 The interpreter converts the source code line-by-line during RUN Time.  Interpret completely translates a program written in a high-level language into machine level language.  Interpreter allows evaluation and modification of the program while it is executing.  Relatively less time spent for analyzing and processing the program  Program execution is relatively slow compared to compiler

OR

KEY DIFFERENCE BETWEEN COMPILER AND INTERPRETER

 Compiler transforms code written in a high-level programming language into the machine code, at once, before program runs, whereas an Interpreter coverts each high- level program statement, one by one, into the machine code, during program run.  Compiled code runs faster while interpreted code runs slower.  Compiler displays all errors after compilation, on the other hand, the Interpreter displays errors of each line one by one.  Compiler is based on translation linking-loading model, whereas Interpreter is based on Interpretation Method.  Compiler takes an entire program whereas the Interpreter takes a single line of code.

CHAPTER 6 LINKERS

Linker

• A System Software that Combines two or more separate object programs and supplies the information needed to allow references between them .

• Two Types/scheme – Dynamic Linking – Static Linking 1. Static Linking: It is performed during the compilation of source program. Linking is performed before execution in static linking. Static linkers takes input a collection of relocatable object files and command line arguments and generate as output a fully linked executable that can be loaded and run.

Static perform two major task:

 Symbol resolution – It associates each symbol reference with exactly one symbol definition .Every symbol have predefined task.  – It relocate code and data section and modify symbol references to the relocated memory location. 2.Dynamic Linking: Dynamic linking is performed during the run time. This linking is accomplished by placing the name of a shareable in the executable image. There is more chances of error and failure chances. It require less memory space as multiple program can share a single copy of the library.

Loader

Loader is a part of operating system and is responsible for loading executable files into memory and execute them. It calculates the size of a program (instructions and data) and creates memory space for it. It initializes various registers to initiate execution. There are three kinds of loading approaches/scheme: 1. Absolute loading 2. Relocatable loading 3. Dynamic run-time loading

1.Absolute loading: This approach loads the executable file of a program into a same main memory location each time. But it has some disadvantages like a programmer must be aware of the assignment strategy for loading the modules to main memory. In case, the program is to be modified involving some insertion and deletion in the program, then all the addresses of the program have to be altered.

2. Relocatable loading: In this approach, the compiler or assembler does not produce actual main memory address. It produces the relative addresses.

3.Dynamic Run-Time loading: In this approach, the absolute address for a program is generated when an instruction of an executable module is actually executed. It is very flexible, the loadable module/executable module can be loaded into any region of main memory. The executing program can be interrupted in between and can be swapped out to the disk and back to main memory this time at a different main memory address.

Two more types of loading scheme :-

1] Link-And-Go.

2] Link-Load-And-Go.

1. Link-And-Go

In the Link-And-Go scheme the linkage editor actually situated a program its load address perform all other linking function and passes control to the purpose of execution.

Drawbacks of the scheme :-

1) Linkage editor co-exist with the program while perform the linkage task.

2) Linking has to be repeated for execution of program.

Fig: Link-and-Go Scheme

2.Link-Load-And Go:-

The Link-Load-And-Go scheme require less storage because its construct a ready to execute form of a program and push it’s the secondary storage. its necessary to load this program into the main storage without any relocation. such loader is called as absolute loader.

This loader presents :-

1)Text of program which has been link for desired area.

2)The load address origin.

3)Length of the program.

Fig: Link-Load And Go Scheme

Important Terms:

• Translation time address: Translation time address is used at the translation time. This address is assigned by .

• Linked time address: Link time address is used at the link time. This address is assigned by linker. • Load time address: Load time address is used at the load time. This address is assigned by loader.

• Translated origin: Address of origin assumed by the translator.

• Linked origin: Address of origin assumed by the linker while producing a binary program.

• Load origin: Address of origin assumed by the loader while loading the program for execution.

Relocation of linking concept. Program relocation is the process of modifying the addresses used in the address sensitive instruction of a program such that the program can execute correctly from the designated area of memory.

• If linked origin≠ translated origin, relocation must be performed by the linker.

• Let AA be the set of absolute address - instruction or data addresses used in the instruction of a program P.

• AA≠ ф implies that program P assumes its instructions and data to occupy memory words with specific addresses.

• Such a program – called an address sensitive program – contains one or more of the following:

-An address sensitive instruction: an instruction which uses an address a∈AA.

-An address constant: a data word which contains an address a∈AA.

• An address sensitive program P can execute correctly only if the start address of the memory area allocated to it is the same as its translated origin.

• To execute correctly from any other memory area, the address used in each address sensitive instruction of P must be ‘corrected’.If load origin≠ linked origin, relocation must be performed by the loader.

Difference Between Linker And Loader

Chapter 7 Software Tools

Software Tools for Program Development

A or tool is a program or application that software developers use to create, debug, maintain, or otherwise support other programs and applications. The term usually refers to relatively simple programs that can be combined together to accomplish a task, much as one might use multiple hand tools to fix a physical object. The tools began with the first in the early 1950s that used linkers, loaders, and control programs. Tools became famous with in the early 1970s with tools like grep, and make that were meant to be combined flexibly with pipes. The term "software tools" came from the book of the same name by Brian Kernighan and P. J. Plauger.

Software development tools can be roughly divided into the following categories:

1) Performance analysis tools

2) tools

3) Static analysis and formal verification tools

4) Correctness checking tools

5) Memory usage tools

6) Application build tools

7) Integrated development environment

Given below are few uses of the Software Dev Tools:

 Software tools are used to accomplish and investigate the business processes, document the development process of the software and optimize all the processes.  By using these tools in the software development process, the outcome of the projects will be more productive.  Using the development tools, a developer can easily maintain the workflow of the project. Some of the Best latest Software Development Tools

1)Zoho Creator It is a low-code platform that enables rapid development and delivery of web and mobile applications and assists to Build powerful enterprise software applications 10x faster. It also provides key features like , JavaScript, Cloud functions, third- party integrations, multi-language support, offline mobile access, integration with a payment gateway and more.

2) Linx Linx is low code tool to build and automate backend applications and web services. The tool accelerates the design, development and automation of custom business processes, including easy integration of applications, systems and .

3) Atom Atom is an open source and free desktop editor cum source code editor that is up-to-date, friendly and hackable to the core.

4) Cloud 9 Initially in 2010 Cloud 9 was an open source, cloud-based IDE (Integrated Development Environment) that supports various programming languages like C, , Python, JavaScript, PHP etc. Later in 2016, AWS (Amazon Web Service) acquired it for further improvement and made it chargeable as per the usage.

5) GitHub GitHub is a powerful collaboration tool and development platform for and code management. With this GitHub, the users can build applications and software, manage the projects, host the code, review the code etc.

6) NetBeans NetBeans is an open source and a development tool written in that develops world-class web, mobile, and desktop applications easily and quickly. It uses C / C++, PHP, JavaScript, Java etc.

7) Bootstrap Bootstrap is an open source and free framework for developing responsive websites and mobile-first projects using CSS, HTML, and JS. Bootstrap is widely used to design faster and simpler websites.

8) Node.js Node.js is an open source, cross-platform and JavaScript run-time environment that is built to design a variety of web applications and to create web servers and networking tools.

Editors

Editors or text editors are software programs that enable the user to create and edit text files. In the field of programming, the term editor usually refers to source code editors that include many special features for writing and editing code. Notepad, Wordpad are some of the common editors used on Windows OS and vi, emacs, Jed, pico are the editors on UNIX OS. Features of text editors are — moving the cursor, deleting, replacing, pasting, finding, finding and replacing, saving etc. Types of Editors Therre are generally five types of editors as described below: 1. Line editor: In this, you can only edit one line at a time or an integral number of lines. You cannot have a free-flowing sequence of characters. It will take care of only one line. Ex : Teleprinter, edlin, teco 2. Stream editors: In this type of editors, the file is treated as continuous flow or sequence of characters instead of line numbers, which means here you can type paragraphs. Ex : Sed editor in UNIX 3. Screen editors: In this type of editors, the user is able to see the cursor on the screen and can make a copy, cut, paste operation easily. It is very easy to use mouse pointer. Ex : vi, emacs, Notepad 4. Word Processor: Overcoming the limitations of screen editors, it allows one to use some format to insert images, files, videos, use font, size, style features. It majorly focuses on Natural language. 5. : Structure editor focuses on programming languages. It provides features to write and edit source code. Ex : Netbeans IDE, gEdit.

Overview of the editing process:

• An interactive editor is a computer program that allows a user to create an revise a target document.

• The document means an object such as computer programs, text,equations tables, diagrams, photographs etc.

• The document editing process in an interactive user computer dialogue designed to accomplish four tasks:

1)Select the part of the target document to be viewed & manipulated.

2)Determine how to format this view online and how to display it.

3)Specify and execute operations that modify the target document.

4)Update the view appropriately.

Figure below shows the simple editor :

Fig - Editor Structure Debug Monitor

Debug Monitor is a powerful graphical- and console-mode tool for monitoring all activities handled by the Win Driver kernel. we can use this tool to monitor how each command sent to the kernel is executed. It will provide details regarding the target system execution and in case of any error this information will be useful for developers to fix the issue. Some debug monitors records the error event and reproduce it based on the developer’s need.

The Debug Monitor comes in two versions:

 wddebug_gui – a GUI version for Windows 7/Vista/Server 2008/Server 2003/XP/2000 and .  Wddebug – a console-mode version for Windows, Windows CE, and Linux; on Windows CE, wddebug also supports GUI execution.

Both Debug Monitor versions are provided in the WinDriver/util directory. 1.You can Run the Debug Monitor using either of the following methods:

 Run WinDriver/util/wddebug_gui.  Run the Debug Monitor from DriverWizard's Tools menu.  On Windows, run Start | Programs | WinDriver | Debug Monitor.

2.Set the Debug Monitor's status, trace level and debug sections information from the Debug Options dialogue, which is activated either from the Debug Monitor's View | Debug Options menu or the Debug Options toolbar button.

Programming Environment

In computer program and software product development, the development environment is the set of processes and programming tools used to create the program or software product. The environment is quite literally everything installed on your machine which can affect either the development and or testing of your application - that can include :

 The editors/IDEs you are using (can affect how efficiently you can write code).  Which compilers/interpreters you are using, and their exact versions - can affect whether your code will execute at all, or how efficiently it does so.  The operating system installed on your machine - Can well have a significant affect on how your code is written.  The environment variables set on your machine, especially relevant during testing as these can dramatically affect certain functions of some applications.  The extra libraries installed on your machine (including potentially any installed by other programs); can effect how well your code will run on other people’s (with potentially different library versions installed)  Other programs running on your machine, especially during load and performance testing.  The available RAM and Disk space on your machine: can affect how well your code performs especially under load/stress test conditions  The local network capacity and connectivity: can directly affect how well some programs function.

User Interfaces (UI)

A , also called a "UI" or simply an "interface," is the means in which a person controls a software application or hardware device. A good user interface provides a "user- friendly" experience, allowing the user to interact with the software or hardware in a natural and intuitive way.

Nearly all software programs have a graphical user interface, or GUI. A typical GUI of a software program includes a menu bar, toolbar, windows, buttons, and other controls.

Most hardware devices also include a user interface, though it is typically not as complex as a software interface.

OR

The user interface (UI) is the point of human-computer interaction and in a device. This can include display screens, keyboards, a mouse and the appearance of a desktop. It is also the way through which a user interacts with an application or a website. The growing dependence of many businesses on web applications and mobile applicationshas led many companies to place increased priority on UI in an effort to improve the user's overall experience.

Types of user interfaces: The various types of user interfaces include:

 graphical user interface (GUI)

 command line interface (CLI)

 menu-driven user interface

 touch user interface

 voice user interface (VUI)

 form-based user interface

 natural language user interface

Examples of user interfaces Some examples of user interfaces include:

 computer mouse

 remote control

 ATMs

 speedometer

 the old iPod click wheel