bc0051(sys software)

Upload: sandeep-sheoran

Post on 02-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 BC0051(Sys Software)

    1/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. (6 marks)

    Answer

    Classification of grammars Grammars are classified on the basis of the nature of productions. Each grammar class has itsown 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 tospecification of programming languages.Type 1 grammar: also known as context sensitive grammarbecause their productionsspecify 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 contextsensitive 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 ascontext 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 | tThese productions also satisfy the requirements of Type -2 grammars. They are also known aslinear grammars orregular grammars. The specific form of the RHS alternatives namely asingle T or a string containing a single T and a single NT gives some practical advantages inscanning. These are further categorized into left linear and right linear grammars

  • 7/27/2019 BC0051(Sys Software)

    2/10

    2

    depending on whether the NT in the RHA alternative appears at the extreme left or extremeright.

    Operator grammars (OG) an operator grammar is a grammar none, of whose productionscontains 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 terminalsymbols 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 thespecification gap and those that bridge the execution gap.

    1. Program generation activities the program generator is a software system whichaccepts the specification of a program to be generated and generated a program in thetarget PL. in effect, the program generator introduces a new domain between theapplication and PL domains known as program generator domain. The specificationgap 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 PLdomain.

    Specification gap (earlier)

    Specification gap

    Application program generator target PL execution domain

    Domain domain 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 orientedlanguage. This is because a problem oriented language suffers a very large executiongap between the PL domain and the execution domain.

    2. Program execution activities is further divided into: Program translation andprogram interpretation activities.

  • 7/27/2019 BC0051(Sys Software)

    3/10

    3

    Program translation model bridges the execution gap by translating a programwritten in a PL, called the source program (SP), into an equivalent program in themachine 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 andperforms actions which implement it. This includes computational and input outputactions. 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 actionto 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 itscorresponding 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, symbolicmnemonic, length (2, 4 or 6 bytes), binary machine opcode and format of instruction.4. a table, thepseudo operation table (POT) that indicates the symbolic mnemonic and actionto be taken for each pseudo operation in pass 2.5. A table, thesymbol table (ST) prepared by pass1 contains each label and its correspondingvalue.

  • 7/27/2019 BC0051(Sys Software)

    4/10

    4

    6. a table, the base table (BT) that indicates which registers are currently specified as baseregisters 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 beingassembled 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 theassembled instructions into the format needed by the loader.10. an output desk of assembled instructions in the format needed by the loader is generated.

    Source program machine operation table target program

    Symbol table

    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 andimplementation point of view. Therefore, the compilation process is partitioned into a seriesof sub processes called phases. A phase is a logically cohesive operation that takes onerepresentation 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 sourceprogram into a sequence of atomic unit called tokens. Each token represents a

    Mnemonic Opcode Length

    ADD 01 1

    SUB 02 1

    AGAIN 104N 113

    Pass 1 Pass 2

  • 7/27/2019 BC0051(Sys Software)

    5/10

    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 itsfollowing phase, the syntax phase analyzer are often grouped together into the samepass. In that pass, the lexical analyzer operates either under the control of the parser orco 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 anothertoken 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 arepermitted by the specification by the source language. It also imposes on the tokens atree like structure that is used by the subsequent phases of the compiler. The secondaspect of syntax analyzer is to make explicitly the hierarchical structure of theincoming token stream by identifying which parts of the token stream should begrouped together.

    Source program

    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

    Intermediate

    code generation

    Lexical analysis

    Syntax analysis

    Code

    optimization

    Code generation

    Table

    management

    Error handling

  • 7/27/2019 BC0051(Sys Software)

    6/10

    6

    transforms this parse tree into an intermediate language representation of the sourceprogram called three address code.Three address code one popular type of intermediate language is three addresscodes. 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 BADD CSTORE ASuch a conversion into machine code usually produces a target program that containsmany redundant loads and stores and that utilizes the resources of the target machineinefficiently. 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 beperformed particularly quickly. A good code generator would therefore attempt toutilize this registers as efficiently as possible. This aspect of code generation is calledregister allocation.

    5. What are macros and macro processors? Explain in brief. (12Marks)

    Answer:

    Macros A macro is a unit of specification for program generation through expansion. A macroname isan abbreviation, which stands for some related lines of code. Macros are useful for thefollowing 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 namewith set of actual parameters is replaced by some code generated by its body. This is calledmacro expansion. Macros allow a programmer to define pseudo operations that are generallydesirable and not implemented as part of the processor instruction and can be implemented asa sequence of instruction.

    Syntax Macro-name MACRO ENDM

  • 7/27/2019 BC0051(Sys Software)

    7/10

    7

    Macros can be defined in any programming language, a name that defines a set of commandsthat are substituted for the macro name wherever the name appears in a program (macroexpansion) when the program is compiled. Macros are similar to functions in that they cantake arguments and are calls to lengthier sets of instructions. But macros can be replaced bythe 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 isreplaced by sequence of assembly statements. Each macro begins with MACRO keyword atthe beginning and ends with the ENDM. Whenever a macro is called the entire code issubstituted in the program where it is called.

    Macro definition user programINITZ MACRO

    MOV AX, @data INITZMOV DS, AX a templateMOV ES, AX (code)MOV ES, AX

    ENDM trailer macro call

    prototype (macro name)

    User program after macro expansion .MOV AX, @dataMOV DS, AXMOV 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 oneline. Parameter names are local symbols, which are known within the macro only. Outside themacro they have no meaning.

    Syntax: MACRO ..

  • 7/27/2019 BC0051(Sys Software)

    8/10

    8

    ENDM

    Valid macro arguments are

    1) Arbitrary sequences of printable characters, not containing blanks, tabs, commas orsemi 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 correspondingformal 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 2nd

    parameter andso on. This is calledsubstitution.

    Example 3MY_SECOND MACRO CONSTANT, REGISTERMOV A, #CONSTANTADD A, REGISTERENDMMY_SECOND 42, R5After 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 andREGISTER have been replaced by the macro arguments 42 and R5. The number ofarguments, passed to a macro, can be less than the number of its formal parameters. If anargument is omitted, the corresponding formal parameter is replaced by an empty string.Macro parameters support code reuse, allowing one macro definition to implement multiplealgorithms.

    Macro parameters

    Instruction

    needed

    Real operations Macro definition Use in program Macro expansion

    Div N Mov Dx, 0Mov Bx, NDiv Bx

    Div Macro NMov Dx, 0Mov Bx, &NDiv BxEndm

    call GetDec$Div 34Call PutDec$

    Call GetDec$Mov Dx, 0Mov Bx, 34Div BxCall PutDec$

  • 7/27/2019 BC0051(Sys Software)

    9/10

    9

    February2010Bachelor 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.

  • 7/27/2019 BC0051(Sys Software)

    10/10

    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 andscope. Type incompatibilities between operators and operands and between formal and actualparameters are another common source of semantic errors that can be detected in manylanguages at compile time.

    Example undetected or multiple declared identifiers.

    Dynamic errors some errors can be detected only during run time. Some type checking forlanguages must be postponed to run time. Another common kind of error detection usuallydone at run time is, range checking for certain values, particularly array subscripts and casestatement 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 unknownmemory location.

    Example languages such as APL and SNOBOL have several types and the type of a namecan change at run time.