0% found this document useful (0 votes)
6 views81 pages

Translation Software Assignment

The document consists of a series of questions and answers related to translation software, focusing on expression evaluation, code optimization, syntax analysis, and error reporting. It emphasizes the importance of stack operations in Reverse Polish Notation (RPN) and the need for valid syntax in programming. Additionally, it discusses the significance of reducing execution time and memory usage through optimized code and proper syntax structure.

Uploaded by

Hassaan Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views81 pages

Translation Software Assignment

The document consists of a series of questions and answers related to translation software, focusing on expression evaluation, code optimization, syntax analysis, and error reporting. It emphasizes the importance of stack operations in Reverse Polish Notation (RPN) and the need for valid syntax in programming. Additionally, it discusses the significance of reducing execution time and memory usage through optimized code and proper syntax structure.

Uploaded by

Hassaan Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Translation Software

Question 1

PQ+PQ - *

2 1
2 4 4 6 6 5
10 5 5 5 5 5 5 25

Sir Taha Ali Papersdock +92 318 2248934


((P+Q) * M) - (R-P)

Expressions are always evaluated left to right

Each operator uses the two previous values on the stack (except unary minus)

Question 2

Sir Taha Ali Papersdock +92 318 2248934


0 61 Constant
Password 62 Variable
"Cambridge" 63 Variable
1 64 Constant

61 51 62 4E 4A 62 04 63 4B 51 62 4C 60 01 60 02 64 4F 62 03 63 52 60

Sir Taha Ali Papersdock +92 318 2248934


LDD 236

ADD 237

STO 236

ADD 236

STO 238

This means that the code will have fewer instructions

Optimized code occupies less space in memory

Fewer instructions reduce the execution time of program

Sir Taha Ali Papersdock +92 318 2248934


Question 3

Working from left to right in the expression

If element is number push that onto the stack

If element is a operator then POP the first two numbers from stack and perform

that operation on those numbers.

Push result back onto the stack

End once the last in the expression has been dealt with

2 2 2 6

5 3 30 30 30 30 5

8 8 8 24 24 24 24 24 24 19

Sir Taha Ali Papersdock +92 318 2248934


Question 4

Sir Taha Ali Papersdock +92 318 2248934


35 is not a variable

:= is not a operator

9 is not a digit

== | >|<

<digit><digit>

<letter> | <letter><variable>

<variable><operator><number> | <variable><operator><variable>

Sir Taha Ali Papersdock +92 318 2248934


Question 5

The reserved words used

The operators used

Keywords/operators are looked up in keyword table

Keywords/operators are represented by tokens

Identifiers are looked up in symbol table

Identifiers are converted to addresses/locations

Removal of white spaces

Sir Taha Ali Papersdock +92 318 2248934


Redundant code is removed

Program requires less memory

Code is recognized to make it more efficient

Question 6

Sir Taha Ali Papersdock +92 318 2248934


c4 is not a signed integer

0 is not a digit

:= is not a operator

Sir Taha Ali Papersdock +92 318 2248934


<variable> = <variable><operator><signed integer>

<letter><letter>

+<digit> | - <digit>

^ | \

<letter> | <letter><variable>

Sir Taha Ali Papersdock +92 318 2248934


Question 7

Sir Taha Ali Papersdock +92 318 2248934


5 is not a variable

D is not a letter

only one operator can be used

<variable> = <variable><operator><variable>;

<letter> | <letter><unsigned integer>

<digit> | <digit><unsigned integer>

+ | - | * | /

variable
letter unsigned integer

Sir Taha Ali Papersdock +92 318 2248934


Question 8

Sir Taha Ali Papersdock +92 318 2248934


Number 62 Variable

Counter 63 Variable

12 64 Constant

61 51 62 4E 63 01 60 50 64 52 62 02 63 53

Constructing parse tree

Producing an error report

execution time of program decreases

Sir Taha Ali Papersdock +92 318 2248934


LDD 236

ADD 237

STO 512

ADD 238

STO 513

ADD 239

STO 514

Sir Taha Ali Papersdock +92 318 2248934


Question 9

Sir Taha Ali Papersdock +92 318 2248934


Answer 62 Variable

10 63 Constant

0 64 Constant

51 61 51 62 4A 62 03 60 02 61 4B 52 63 4D 52 64 4C

Code Optimization

Sir Taha Ali Papersdock +92 318 2248934


LDD 236

ADD 237

ADD 238

SUB 239

STO 235

Reduces the execution time of program

Occupies less storage space

2
1 1 3 3 2
2 2 2 6 6 9 9 7

Sir Taha Ali Papersdock +92 318 2248934


Question 10

Sir Taha Ali Papersdock +92 318 2248934


= is not the correct operator. := should be there

B2 is a variable it should be unsigned integer

A32 is not a correct variable

<variable> := <variable><operator><unsigned integer>

<letter><digit>

<digit> | <digit><unsigned integer>

A | B | C

+ | - | * | ^

Sir Taha Ali Papersdock +92 318 2248934


Letter Digit Digit

<variable> := <variable><operator><real>

<unsigned_integer> . <unsigned_integer>

Sir Taha Ali Papersdock +92 318 2248934


Question 11

A valid unsigned integer can be two digits

so both 3 and 2 are digits

Sir Taha Ali Papersdock +92 318 2248934


A valid unsigned number can be a unsigned integer followed by a decimal

point and then followed by a unsigned integer.

32 and 5 are unsigned integers and there is a decimal point between them.

<unsigned_integer> | <unsigned_integer> . <unsigned_integer>

<digit> | <digit><unsigned_integer>

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0

<unsigned_integer> | <unsigned_integer> . <unsigned_integer>

Sir Taha Ali Papersdock +92 318 2248934


Question 12

Sir Taha Ali Papersdock +92 318 2248934


AB+CD- *

A-B/4*CD-/

4 3

1 1 5 5 2

2 2 2 2 2 4

x * (w+z) - y

Sir Taha Ali Papersdock +92 318 2248934


No need for rules of precedence (BODMAS)

No need for brackets

In RPN evaluation of operator is always left to right

Question 13

PQ+RS/-

Sir Taha Ali Papersdock +92 318 2248934


2

3 3 5

2 1 1 1 1 6
2 4 4 4 4 4 4 -2

(b*a) - (c+d+a)

Rules of precedence means different operators have different priorities.

In RPN evaluation of operators is left to right.

No need for brackets

Sir Taha Ali Papersdock +92 318 2248934


Question 14

; should be there after c

2 is not a variable

e is not a valid letter

Sir Taha Ali Papersdock +92 318 2248934


<variable> = <variable><operator><variable> ;

<letter> | <letter><letter> | <letter><letter><letter>

a | b | c | d

+ | - | * |

<letter> | <letter><variable>

Debuging is faster

Compiler produces executable version not readable

Sir Taha Ali Papersdock +92 318 2248934


Question 15

Sir Taha Ali Papersdock +92 318 2248934


Num1 62 Variable

5.0 63 Constant

61 51 62 4A 60 03 62 4B 62 01 62 02 63 4C

Code Optimization

Sir Taha Ali Papersdock +92 318 2248934


LDD 234

ADD 235

ADD 236

STO 233

Code occupies less space in memory as there are less instructions

Reduces the execution time of the program

Sir Taha Ali Papersdock +92 318 2248934


Question 16

Sir Taha Ali Papersdock +92 318 2248934


Counter 62 Variable

10 63 Constant

61 4E 62 01 60 50 63 52 62 02 60 53

Syntax Analysis

Constructs parse tree

Produces error report

Execution time of program reduces

Sir Taha Ali Papersdock +92 318 2248934


It should calculate the value of 2*6 and write it instead

LDD 436

ADD 437

STO 612

ADD 437

ADD 438

STO 613

Sir Taha Ali Papersdock +92 318 2248934


Question 17

No need for rules of precedence

No need for brackets

In RPN evaluation of operator is always left to right

Structure: STACK

Reason: Two operands are popped from the stack in the reverse order to

how they were pushed

Sir Taha Ali Papersdock +92 318 2248934


a b - a c + * 7 /

a / b * 4 - ( a + b )

(a + b) / ( c / d )

(17 + 3) / ( 48 / 12)

20 / 4

5 final answer

Sir Taha Ali Papersdock +92 318 2248934


Question 18

<character> : := $ | % | & | * | #

Sir Taha Ali Papersdock +92 318 2248934


$CS9618

<password> : := <character><code>

<code> : := <digit> | <digit><code> | <capital_letter> | <capital_letter><code>

Sir Taha Ali Papersdock +92 318 2248934


Question 19

jk+jk-/

3 3 6

10 10 10 10 4

10 10 10 10 10 10 40

Working from left to right in the expression

Pushing the values onto the stack

when the first operator is reached pop the first two values

then apply the operation

Continue till the end of the expression

Sir Taha Ali Papersdock +92 318 2248934


Question 20

Sir Taha Ali Papersdock +92 318 2248934


12 is not a variable

z is not a correct variable

<letter><unsigned_integer>

<digit> | <digit> <digit>

1 | 2 | 3

+ | - | *

<variable> = <variable><operator><variable>

Sir Taha Ali Papersdock +92 318 2248934


unsigned_integer unsigned_integer

variable
= variable operator variable

<assignment_statement><variable> : := <variable><operator><variable> |

<variable><operator><unsigned_integer> | <unsigned_integer><operator>

<variable> | <unsigned_integer><operator><unsigned_integer>

Sir Taha Ali Papersdock +92 318 2248934


Question 21

Sir Taha Ali Papersdock +92 318 2248934


Question 22

ab* b+d-15+

( a - b ) * ( c + d ) / a

-39

Question 23

Code Generation

Optimization

It checks that the code matches the grammar of the language

Syntax errors are reported

Parse tree is produces

Sir Taha Ali Papersdock +92 318 2248934


Question 24

Sir Taha Ali Papersdock +92 318 2248934


Valid
Everything is according to syntax

InValid

digits should be before # symbol

InValid

Invalid symbol is used. ? is not a valid symbol

$ | % | & | @ | #

A | D | P | R | Y

Sir Taha Ali Papersdock +92 318 2248934


letter digit

Sir Taha Ali Papersdock +92 318 2248934


Question 25

Sir Taha Ali Papersdock +92 318 2248934


InValid

Incorrect syntax. 9 should be after digits

InValid

there should be a digit after letters

<letter> | <letter><word>

<word> | <word><digit>

AC12

Sir Taha Ali Papersdock +92 318 2248934


letter letter digit digit digit

Sir Taha Ali Papersdock +92 318 2248934


Question 26

( 5 - 2 ) * ( 5 + 4 ) / 9

4
2 5 5 9 9
5 5 3 3 3 3 27 27 3

Working from left to right in the expression

Pushing the values onto the stack

when the first operator is reached pop the first two values

then apply the operation

Continue till the end of the expression

Sir Taha Ali Papersdock +92 318 2248934


Question 27

5
3 2 10 10 2

20 20 60 60 30 30 30 30 60

Working from left to right in the expression

Pushing the values onto the stack

when the first operator is reached pop the first two values

then apply the operation

Continue till the end of the expression

Sir Taha Ali Papersdock +92 318 2248934


Question 28

( 5 + 2 ) / ( 9 - 3 ) * 3

7 3 + 2 8 * - 6 /

3
5 7 7 10 10

17 17 12 12 12 12 120 12

Sir Taha Ali Papersdock +92 318 2248934


Question 29

7 2 - 8 + 9 5 - /

3 7

9 6 6 9 9 2

6 6 15 15 15 15 15 15 30

( a - c + b) * ( d + b ) / c

Sir Taha Ali Papersdock +92 318 2248934


Answer
Answer 1

Answer 2

Sir Taha Ali Papersdock +92 318 2248934


Answer 3

Sir Taha Ali Papersdock +92 318 2248934


Answer 4

Answer 5

Sir Taha Ali Papersdock +92 318 2248934


Answer 6

Sir Taha Ali Papersdock +92 318 2248934


Answer 7

Sir Taha Ali Papersdock +92 318 2248934


Answer 8

Sir Taha Ali Papersdock +92 318 2248934


Answer 9

Sir Taha Ali Papersdock +92 318 2248934


Answer 10

Answer 11

Sir Taha Ali Papersdock +92 318 2248934


Sir Taha Ali Papersdock +92 318 2248934
Answer 12

Sir Taha Ali Papersdock +92 318 2248934


Answer 13

Sir Taha Ali Papersdock +92 318 2248934


Answer 14

Sir Taha Ali Papersdock +92 318 2248934


Answer 15

Sir Taha Ali Papersdock +92 318 2248934


Answer 16

Sir Taha Ali Papersdock +92 318 2248934


Answer 17

Sir Taha Ali Papersdock +92 318 2248934


Answer 18

Sir Taha Ali Papersdock +92 318 2248934


Answer 19

Answer 20

Sir Taha Ali Papersdock +92 318 2248934


Answer 21

Answer 22

Sir Taha Ali Papersdock +92 318 2248934


Answer 23

Sir Taha Ali Papersdock +92 318 2248934


Answer 24

Sir Taha Ali Papersdock +92 318 2248934


Answer 25

Sir Taha Ali Papersdock +92 318 2248934


Answer 26

Sir Taha Ali Papersdock +92 318 2248934


Answer 27

Sir Taha Ali Papersdock +92 318 2248934


Answer 28

Sir Taha Ali Papersdock +92 318 2248934


Answer 29

Sir Taha Ali Papersdock +92 318 2248934

You might also like