2976 - I2P(II)2024_Kuo_Mini_Project1_Practice Scoreboard

Time

2024/03/26 15:10:00 2024/04/21 23:59:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
14270 I2P(II)2024 Kuo Mini Project 1 (Practice)

14270 - I2P(II)2024 Kuo Mini Project 1 (Practice)   

Description

You need to implement a calculator which prints assembly code.

The input is a list of expressions consisting of:

  • Integers
  • Operators (+, -, *, /, =, &, |, ^, ++, --, +=, -=)
  • Three built-in variables x, y, z (exist in the beginning)
  • Some new local variables

The output is a list of assembly code.

You should merge all your header files and code into a single file to submit.

You should parse the input according to the grammar below:

statement           := ENDFILE | END | assign_expr END
assign_expr         := ID ASSIGN assign_expr | ID ADDSUB_ASSIGN assign_expr | or_expr
or_expr             := xor_expr or_expr_tail
or_expr_tail        := OR xor_expr or_expr_tail | NiL
xor_expr            := and_expr xor_expr_tail
xor_expr_tail       := XOR and_expr xor_expr_tail | NiL
and_expr            := addsub_expr and_expr_tail
and_expr_tail       := AND addsub_expr and_expr_tail | NiL
addsub_expr         := muldiv_expr addsub_expr_tail
addsub_expr_tail    := ADDSUB muldiv_expr addsub_expr_tail | NiL
muldiv_expr         := unary_expr muldiv_expr_tail
muldiv_expr_tail    := MULDIV unary_expr muldiv_expr_tail | NiL
unary_expr          := ADDSUB unary_expr | factor
factor              := INT | ID | INCDEC ID | LPAREN assign_expr RPAREN

Input

The input contains mutiple expressions. Each expression is separated by a newline character ('\n').

The initial value of x, y, and z are stored in memory [0], [4], and [8] respectively.

If a new variable first appear in the left hand side of an assign (=), it is valid and can be use in the future.

If a new variable first appear in the right hand side of an assign (=), it is invalid and the output should be "EXIT 1".

Some test cases contains syntax errors, make sure you handle them properly.

Output

You should output a list of assembly code according to the input.

After printing the assembly code, make sure you have stored the answer of the variables x, y, z in registers r0, r1, and r2 respectively.

If the expression is valid, remember to print "EXIT 0" on the last line.

If the expression is invalid, your final output should contain "EXIT 1". That is, if the expression is invalid, you don't have to store the value of x, y, z into the registers.

There must be a newline character ('\n') at the end of your output.

Note: This time we use special judge, and your answer doesn't need to be as same as the sample output. You just need to ensure the final values which are stored in registers r0, r1, and r2 (the value of variables x, y, and z) are correct.

Sample Input  Download

Sample Output  Download

Tags




Discuss