Sei sulla pagina 1di 6

What are the cousins of compiler?

Improve In: Computer Software and Applications, Microprocessors [Edit categories] DATA Processing www.ibm.com/DataServices Discover How To Build A Data Center Effectively. Start Here! BASIC for Windows www.libertybasic.com Liberty BASIC gives you a power toolkit for Windows programming! Ads

Answers.com > Wiki Answers > Categories > Technology > Computers > Computer Software and Applications > What are the cousins of compiler? Answer: Improve THE COUSINS OF THE COMPILER ARE Preprocessor. Assembler. Loader and Link-editor. PREPROCESSOR

A preprocessor is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers. The preprocessor is executed before the actual compilation of code begins, therefore the preprocessor digests all these directives before any code is generated by the statements. They may perform the following functions 1. Macro processing 2. File Inclusion 3."Rational Preprocessors

4. Language extension 1. Macro processing: A macro is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to an output sequence (also often a sequence of characters) according to a defined procedure. The mapping process that instantiates (transforms) a macro into a specific output sequence is known as macro expansion.

macro definitions (#define, #undef)


To define preprocessor macros we can use #define. Its format is: #define identifier replacement When the preprocessor encounters this directive, it replaces any occurrence of identifier in the rest of the code by replacement. This replacement can be an expression, a statement, a block or simply anything. The preprocessor does not understand C++, it simply replaces any occurrence of identifier by replacement. #define TABLE_SIZE 100 int table1[TABLE_SIZE]; int table2[TABLE_SIZE]; After the preprocessor has replaced TABLE_SIZE, the code becomes equivalent to: int table1[100]; int table2[100]; 2.File Inclusion: Preprocessor includes header files into the program text. When the preprocessor finds an #include directive it replaces it by the entire content of the specified file. There are two ways to specify a file to be included:

#include "file" #include <file> The only difference between both expressions is the places (directories) where the compiler is going to look for the file. In the first case where the file name is specified between double-quotes, the file is searched first in the same directory that includes the file containing the directive. In case that it is not there, the compiler searches the file in the default directories where it is configured to look for the standard header files. If the file name is enclosed between angle-brackets <> the file is searched directly where the compiler is configured to look for the standard header files. Therefore, standard header files are usually included in angle-brackets, while other specific header files are included using quotes.

3."Rational Preprocessors: These processors augment older languages with more modern flow of control and data structuring facilities. For example, such a preprocessor might provide the user with builtin macros for constructs like while-statements or if-statements,where none exist in the programming language itself. 4.Language extension : These processors attempt to add capabilities to the language by what amounts to built-in macros. For example, the language equal is a database query language embedded in C. Statements begging with ## are taken by the preprocessor to be database access statements unrelated to C and are translated into procedure calls on routines that perform the database access. The behavior of the compiler with respect to extensions is declared with the #extension directive: #extension extension_name : behavior #extension all : behavior extension_name is the name of an extension. The token all means that the specified behavior should apply to all extensions supported by the compiler. ASSEMBLER Typically a modern assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities. The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. Most assemblers also include macro facilities for performing textual substitution-e.g., to generate common short sequences of instructions as inline, instead of called subroutines, or even generate entire programs or program suites. There are two types of assemblers based on how many passes through the source are needed to produce the executable program. One-pass assemblers go through the source code once and assumes that all symbols will be defined before any instruction that references them. Two-pass assemblers create a table with all symbols and their values in the first pass, then use the table in a second pass to generate code. The assembler must at least be able to determine the length of each instruction on the first pass so that the addresses of symbols can be calculated.

The advantage of a one-pass assembler is speed, which is not as important as it once was with advances in computer speed and capabilities. The advantage of the two-pass assembler is that symbols can be defined anywhere in the program source. As a result, the program can be defined in a more logical and meaningful way. This makes two-pass assembler programs easier to read and maintain

LINKERS AND LOADERS A linker or link editor is a program that takes one or more objects generated by a compiler and combines them into a single executable program. Three tasks 1. Searches the program to find library routines used by program, e.g. printf(), math routines. 2. Determines the memory locations that code from each module will occupy and relocates its instructions by adjusting absolute references 3. Resolves references among files Loader A loader is the part of an operating system that is responsible for loading programs, one of the essential stages in the process of starting a program. Loading a program involves reading the contents of executable file, the file containing the program text, into memory, and then carrying out other required preparatory tasks to prepare the executable for running. Once loading is complete, the operating system starts the program by passing control to the loaded program code. All operating systems that support program loading have loaders, apart from systems where code executes directly from ROM or in the case of highly specialized computer systems that only have a fixed set of specialised programs. In many operating systems the loader is permanently resident in memories, although some operating systems that support virtual memory may allow the loader to be located in a region of memory that is pageable. In the case of operating systems that support virtual memory, the loader may not actually copy the contents of executable files into memory, but rather may simply declare to the virtual memory subsystem that there is a mapping between a region of memory allocated to contain the running program's code and the contents of the associated executable file. The virtual memory subsystem is then made aware that pages with that region of memory need to be filled on demand if and when program execution actually hits those areas of unfilled memory. This may mean parts of a program's code are not actually copied into memory until they are actually used, and unused code may never be loaded into memory at all. Steps for loaders : - Read executable file's header to determine the size of text and data segments - Create a new address space for the program - Copies instructions and data into address space - Copies arguments passed to the program on the stack - Initializes the machine registers including the stack ptr - Jumps to a startup routine that copies the program's arguments from the stack to

registers and calls the program's main routine [http://wiki.answers.com/Q/What_are_the_cousins_of_compiler (20-11-11)]

// A structure editor, also structured editor or projectional editor, is any document editor that is cognizant of the documents underlying structure. Structure editors can be used to edit hierarchical or marked up text, computer programs, diagrams, chemical formulas, and any other type of content with clear and well-defined structure. In contrast, a text editor is any document editor used for editing plain text files. Typically, the benefits of text and structure editing are combined in the user interface of a single hybrid tool. For example, Emacs is fundamentally a text editor, but supports the manipulation of words, sentences, and paragraphs as structures that are inferred from the text. Conversely, Dreamweaver is fundamentally a structure editor for marked up web documents, but supports the display and manipulation of raw HTML text as well. Similarly, molecule editors typically support both graphical and textual input. Structure editing predominates when content is graphical and textual representations are awkward, e.g., CAD systems and PowerPoint. Text editing predominates when content is largely devoid of structure, e.g., text fields in web forms. WYSIWYG word processing systems such as Word, which appear to edit formatted text directly, are essentially structure editors for the underlying marked-up text.
[http://en.wikipedia.org/wiki/Structure_editor (20-11-11)]

Prettyprint (or pretty-print) is the application of any of various stylistic formatting conventions to text, source code, markup, and other similar kinds of content. These formatting conventions usually consist of changes in positioning, spacing, color, contrast, size and similar modifications intended to make the content easier for people to view, read, and understand. Prettyprinters for programming language source code are sometimes called code beautifiers or syntax highlighters.
[http://en.wikipedia.org/wiki/Prettyprint (20-11-11)]

In computer programming, a one-pass compiler is a compiler that passes through the source code of each compilation unit only once. In other words, a one-pass compiler does not "look back" at code it previously processed. Another term sometimes used is narrow compiler, which emphasizes the limited scope a one-pass compiler is obliged to use. This is in contrast to a multi-pass compiler which traverses the source code and/or the abstract syntax tree several times, building one or more intermediate representations that can be arbitrarily refined. While one-pass compilers may be faster than multi-pass compilers, they are unable to

generate as efficient programs, due to the limited scope available. (Many optimizations require multiple passes over a program, subroutine, or basic block.) In addition, some programming languages simply cannot be compiled in a single pass, as a result of their design. In contrast, some programming languages have been designed specifically to be compiled with one-pass compilers, and include special constructs to allow one-pass compilation. An example of such a construct is the forward declaration in Pascal. Normally Pascal requires that procedures be fully defined before use. This helps a one-pass compiler with its type checking: calling a procedure that hasn't been defined is a clear error. However, this requirement makes mutually recursive procedures impossible to implement:
{http://en.wikipedia.org/wiki/One-pass_compiler (20-11-11)}

A multi-pass compiler is a type of compiler that processes the source code or abstract syntax tree of a program several times. This is in contrast to a one-pass compiler, which traverses the program only once. Each pass takes the result of the previous pass as the input, and creates an intermediate output. In this way, the (intermediate) code is improved pass by pass, until the final pass emits the final code. Multi-pass compilers are sometimes called wide compilers,[citation needed] referring to the greater scope of the passes: they can "see" the entire program being compiled, instead of just a small portion of it. The wider scope thus available to these compilers allows better code generation (e.g. smaller code size, faster code) compared to the output of onepass compilers, at the cost of higher compiler time and memory consumption. In addition, some languages cannot be compiled in a single pass, as a result of their design.
[http://en.wikipedia.org/wiki/Multi-pass_compiler (20-11-11)]

Potrebbero piacerti anche