Você está na página 1de 10

1

February2010 Bachelor of Computer Application (BCA) Semester 4 BC0051 System Software 4 Credits
(Book ID: B0900)

Assignment Set 1 (60 Marks)

Answer All Questions

1. Give the classification of grammars. Answer

(6 marks)

Classification of grammars Grammars are classified on the basis of the nature of productions. Each grammar class has its own characteristics and limitations. Type 0 grammars: these grammars are also known as phrase structure grammars and contain productions of the form: - :: = Where both and can be strings of Ts and NTs. Such productions permit arbitrary substitution of strings during derivations or reduction, hence they are not relevant to specification of programming languages. Type 1 grammar: also known as context sensitive grammar because their productions specify that derivation or reduction of strings can take place only in specific contexts. A type 1 production has the from: - A :: = Thus, a string in a sentential form can be replaced A and vice versa, only when it is enclosed by the strings . These grammars are also not particularly relevant for programming language (PL) specification since recognition of PL constructs is not context sensitive in nature. Type -2 grammars: they impose no context requirements on derivations or reductions. A typical Type -2 production is of the form: - A:: = Which can be applied independent of its context. These grammars are therefore known as context free grammars (CFG). CFGs are ideally suited for PL specification. Type -3 grammars: are characterized by productions of the form: A:: = tB | t or A:: = Bt | t These productions also satisfy the requirements of Type -2 grammars. They are also known as linear grammars or regular grammars. The specific form of the RHS alternatives namely a single T or a string containing a single T and a single NT gives some practical advantages in scanning. These are further categorized into left linear and right linear grammars

2 depending on whether the NT in the RHA alternative appears at the extreme left or extreme right. Operator grammars (OG) an operator grammar is a grammar none, of whose productions contains two or more consecutive NTs in any RHS alternative. Thus, non - terminals occurring in an RHS string are separated by one or more terminal symbols. All terminal symbols occurring in the RHS strings are called operators of the grammar.

2. Explain language processing activities with suitable diagrams (10 Marks)

Answer The fundamental language processing activities can be divided into those that bridge the specification gap and those that bridge the execution gap. 1. Program generation activities the program generator is a software system which accepts the specification of a program to be generated and generated a program in the target PL. in effect, the program generator introduces a new domain between the application and PL domains known as program generator domain. The specification gap is now the gap between the application domain and the program generator domain. This gap is smaller than the gap between the application domain and the target PL domain. Specification gap (earlier) Specification gap

Application Domain

program generator domain

target PL domain

execution domain

Reduction in specification gap increases the reliability of the generated program. The harder task of bridging the gap to the PL domain is performed by the generator. This arrangement also reduces the testing effort. It is economical to develop a program generator than to develop a problem oriented language. This is because a problem oriented language suffers a very large execution gap between the PL domain and the execution domain. 2. Program execution activities is further divided into: Program translation and program interpretation activities.

3 Program translation model bridges the execution gap by translating a program written in a PL, called the source program (SP), into an equivalent program in the machine or assembly language of the computer system, called the target program (TP). Characteristics of the program translation model are i. A program must be translated before it can be executed. ii. The translated program may be saved in a file. The saved program may be executed repeatedly. iii. A program must be retranslated following modifications. Program interpretation the interpreter reads the source program and stores it in its memory. During interpretation it takes a source statement, determines its meaning and performs actions which implement it. This includes computational and input output actions. Interpretation cycle consists of a: fetch statement. b: analyze the statement and determine its meaning. c: execute the meaning of the statement. 3. Write pass1 and pass2 data structures in detail. (10 Marks) Answer: Data structures are of two types: Pass 1 data structures 1. Input source program. 2. A location counter (LC), used to keep track of each instructions location. 3. A table, the machine operation table (MOT) that indicated the symbolic mnemonic for each instruction and its length (2, 4, or 6 bytes). 4. A table, the pseudo operation table (POT) that indicates the symbolic mnemonic and action to be taken for each pseudo operation in pass 2. 5. A table, the symbol table (ST) that is used to store each label and its corresponding value. 6. A table, the literal table (LT) that is used to store each literal encountered and its corresponding assignment location. 7. A copy of the input to be used by pass 2. Pass 2 data structures 1. Copy of source program input to pass 1. 2. Location counter (LC). 3. a table, the machine operation table (MOT) that indicates for each instruction, symbolic mnemonic, length (2, 4 or 6 bytes), binary machine opcode and format of instruction. 4. a table, the pseudo operation table (POT) that indicates the symbolic mnemonic and action to be taken for each pseudo operation in pass 2. 5. A table, the symbol table (ST) prepared by pass1 contains each label and its corresponding value.

4 6. a table, the base table (BT) that indicates which registers are currently specified as base registers by USING pseudo ops and what are specified contents of these registers. 7. a work space INST, that is used to hold each instruction as its various parts are being assembled together. 8. a work space, PRINT LINE is used to produce a printed listing. 9. a work space, PUNCH CARDS was used prior to actual outputting for converting the assembled instructions into the format needed by the loader. 10. an output desk of assembled instructions in the format needed by the loader is generated.

Mnemonic ADD SUB

Opcode 01 02

Length 1 1

Source program Pass 1

machine operation table

target program Pass 2

Symbol table AGAIN N

104 113

4. Explain the phases of compiler in detail. (10 Marks) Answer: Phases of compiler a compiler takes as input a source program and produces an equivalent sequence of machine instructions as output. It is a very complex process from logical and implementation point of view. Therefore, the compilation process is partitioned into a series of sub processes called phases. A phase is a logically cohesive operation that takes one representation of the source program as input and generates another representation as output. Lexical analysis it is the interface between the source program and the complier. This analysis reads the source program one character at a time, carving the source program into a sequence of atomic unit called tokens. Each token represents a

5 sequence of characters that can be treated as a single logical entity, identifiers, keywords, operators, commas etc are typical tokens. The lexical analyzer and its following phase, the syntax phase analyzer are often grouped together into the same pass. In that pass, the lexical analyzer operates either under the control of the parser or co routine with the parser. The parser asks the lexical analyzer to return a code for the token that it found to the parser. In the case if that token is an identifier or another token with a value, the value is also passed to the parser. Syntax analyzer the parser has two functions. It checks that the tokens appearing in its input, which is the output of the lexical analyzer, occur in patterns that are permitted by the specification by the source language. It also imposes on the tokens a tree like structure that is used by the subsequent phases of the compiler. The second aspect of syntax analyzer is to make explicitly the hierarchical structure of the incoming token stream by identifying which parts of the token stream should be grouped together. Source program

Lexical analysis

Syntax analysis

Table management

Intermediate code generation

Error handling

Code optimization

Code generation

Target program Intermediate code generation on a logical level the output of the syntax analyzer is some representation of a parse tree. The intermediate code generation phase

6 transforms this parse tree into an intermediate language representation of the source program called three address code. Three address code one popular type of intermediate language is three address codes. A typical three address code statement is: A: = B op C Where A, B and C are operands and op is a binary operator. Code generation this phase converts the intermediate code into a sequence of machine instructions. A simple minded code generator might map the statement: A: = B+C into the machine code sequence: LOAD B ADD C STORE A Such a conversion into machine code usually produces a target program that contains many redundant loads and stores and that utilizes the resources of the target machine inefficiently. To avoid this problem, a code generator might keep track of the run time contents of registers. Many computers have only a few high speed registers in which competitions can be performed particularly quickly. A good code generator would therefore attempt to utilize this registers as efficiently as possible. This aspect of code generation is called register allocation.

5. What are macros and macro processors? Explain in brief. Answer:

(12Marks)

Macros A macro is a unit of specification for program generation through expansion. A macro name is an abbreviation, which stands for some related lines of code. Macros are useful for the following purposes: To simplify and reduce the amount of repetitive coding. To reduce errors caused by repetitive coding. To make an assembly program more readable. A macro consists of name, set of formal parameters and body of code. The use of macro name with set of actual parameters is replaced by some code generated by its body. This is called macro expansion. Macros allow a programmer to define pseudo operations that are generally desirable and not implemented as part of the processor instruction and can be implemented as a sequence of instruction. Syntax Macro-name MACRO <formal parameters> <macro body> ENDM

7 Macros can be defined in any programming language, a name that defines a set of commands that are substituted for the macro name wherever the name appears in a program (macro expansion) when the program is compiled. Macros are similar to functions in that they can take arguments and are calls to lengthier sets of instructions. But macros can be replaced by the actual commands they represents when the program is prepared for execution, which doesnt happen in functions. Whenever a macro is called it leads to macro expansion. During this, the macro statement is replaced by sequence of assembly statements. Each macro begins with MACRO keyword at the beginning and ends with the ENDM. Whenever a macro is called the entire code is substituted in the program where it is called.

Macro definition user program INITZ MACRO MOV AX, @data INITZ MOV DS, AX a template MOV ES, AX (code) MOV ES, AX ENDM trailer macro call prototype (macro name) User program after macro expansion . MOV AX, @data MOV DS, AX MOV ES, AX

6. Explain macro parameters sequence. (12 Marks) Answer: Parameters in macro macros may have any number of parameters, as long as they fir on one line. Parameter names are local symbols, which are known within the macro only. Outside the macro they have no meaning. Syntax: <macro name> MACRO <parameter 1>..<parameter n> <body line 1>

8 <body line 2> <body line m> ENDM Valid macro arguments are 1) Arbitrary sequences of printable characters, not containing blanks, tabs, commas or semi colons. 2) Quoted strings (in single or double quotes). 3) Single printable characters, produced by ! as an escape character. 4) Character sequences, enclosed in literal brackets <.>, which may be arbitrary sequences of valid macro blanks, commas and semicolons. 5) Arbitrary sequences of valid macro argument. 6) Expressions preceded by a % character. During macro expansion, these actual arguments replace the symbols of the corresponding formal parameters, wherever they are recognized in the macro body. The 1st argument replaces the symbol of the 1st parameter, the 2nd argument replace the symbol of the 2 nd parameter and so on. This is called substitution. Example 3 MY_SECOND MACRO CONSTANT, REGISTER MOV A, #CONSTANT ADD A, REGISTER ENDM MY_SECOND 42, R5 After calling the macro MY_SECOND, the body lines. MOV A, #42 ADD A, R5 Are inserted into the program and assembled. The parameter names CONSTANT and REGISTER have been replaced by the macro arguments 42 and R5. The number of arguments, passed to a macro, can be less than the number of its formal parameters. If an argument is omitted, the corresponding formal parameter is replaced by an empty string. Macro parameters support code reuse, allowing one macro definition to implement multiple algorithms. Macro parameters Instruction Real operations needed Div N Mov Dx, 0 Mov Bx, N Div Bx Macro definition Div Macro N Mov Dx, 0 Mov Bx, &N Div Bx Endm Use in program call GetDec$ Div 34 Call PutDec$ Macro expansion Call GetDec$ Mov Dx, 0 Mov Bx, 34 Div Bx Call PutDec$

February2010 Bachelor of Computer Application (BCA) Semester 4 BC0051 System Software 4 Credits
(Book ID: B0900)

Assignment Set 2 (60 Marks)

Answer All Questions and Each Question Carries Equal Marks (6 x 10 =60) 1. Write an algorithm for absolute loader. 2. What is JVM? How does it work? 3. What is real-time operating system? Explain in brief. 4. What is process? Differentiate between a process and program? 5. What are the major components of operating system? 6. Explain Syntactic Error, Semantic Error and Dynamic Errors with suitable examples. Answer: Syntactic errors there are different types of syntactic errors: 1) Deletion error missing right parenthesis.

10

Example MIN (A, 2*(3+B) 2) Insertion error extraneous comma Example DO 10, l = 1,100 3) Replacement error colon in place of semicolon. Example l=1: j=2; 4) Transposition error misspelled keyword. Example F: PROCEDURE OPTIONS (MAIN) 5) Insertion error extra blank Example - /* COMMENT * / Semantic errors they can be detected both at compile time and at run time. The most common semantic errors that can be detected at compile time are errors of declaration and scope. Type incompatibilities between operators and operands and between formal and actual parameters are another common source of semantic errors that can be detected in many languages at compile time. Example undetected or multiple declared identifiers. Dynamic errors some errors can be detected only during run time. Some type checking for languages must be postponed to run time. Another common kind of error detection usually done at run time is, range checking for certain values, particularly array subscripts and case statement selections. A subscript out of range could cause an arbitrary memory location to be overwritten. An arbitrary value in a case statement could cause a jump to an unknown memory location. Example languages such as APL and SNOBOL have several types and the type of a name can change at run time.

Você também pode gostar