これがベトナム大学院の実態だ!

Trường Đại Học Bách Khoa Thành Phố Hồ Chí Minhの大学院修士課程に社会人入学

Nguyên lý ngôn ngữ lập trình Assignment 3

あの悪名高い、に加えて2018年度入学生が最後の犠牲者の枕詞がすっかりおなじみの不評判科目についに3番目の宿題が課された。
番号が2から始まっているのは、1がファイルの説明のためである。

2 Static Checker
静的チェッカーは、最新のコンパイラーで重要な役割を果たします。
プログラムが言語仕様に従ってセマンティック制約に準拠しているかどうかをコンパイル時にチェックします。
この割り当てでは、MC言語の静的チェッカーを実装する必要があります。
チェッカーの入力は、MCプログラムのASTにあります。つまり、割り当て2の出力です。
チェックされた入力が正しい場合、チェッカーの出力は何もありません。そうでない場合、エラーメッセージがリリースされ、静的チェッカーがすぐに停止します。セマンティクスエラーごとに、学生はフォルダーsrc/main/mc/checker/を使用して、期待どおりに印刷されることを確認します。
すべてのテストケースには、多くても1種類のエラーがあります。
この割り当てをチェックインするために必要なセマンティクスの制約は次のとおりです。
A static checker plays an important role in modern compilers.
It checks in the compiling time if a program conforms to the semantic constraints according to the language specification.
In this assignment, you are required to implement a static checker for MC language.
The input of the checker is in the AST of a MC program, i.e. the output of the assignment 2.
The output of the checker is nothing if the checked input is correct, otherwise, an error message is released and the static checker will stop immediately For each semantics error, students should throw corresponding exception given in StaticError.py inside folder src/main/mc/checker/ to make sure that it will be printed out the same as expected.
Every test-case has at most one kind of error.
The semantics constraints required to check in this assignment are as follows.

2.1 Redeclared Variable/Function/Parameter:
識別子は、使用する前に宣言する必要があります。
ただし、宣言はスコープ内で一意である必要があります。
それ以外の場合、例外Redeclareds()がリリースされます。は2番目の宣言のの種類です。
識別子(変数、関数、パラメーター)のスコープは、MC仕様のセクション10のように非公式に説明されています。
An identifier must be declared before used.
However, the declaration must be unique in its scope.
Otherwise, the exception Redeclareds(,) is released, where is the kind of the in the second declaration.
The scope of an identifier (variable, function, parameter) is informally described as in Section 10 of MC specification.

2.2 Undeclared Identifier/Function:
例外「Undeclared()は、が使用されているが、その宣言が見つからない場合に解放されます。
識別子は、変数、パラメータ、または関数にすることができます。
The exception “Undeclared(,) is released when there is an is used but its declaration cannot be found.
The identifier can be a variable or parameter or function.

2.3 Type Mismatch In Statement:
ステートメントは、ステートメントの対応するタイプルールに準拠する必要があります。そうでない場合、例外TypeMismatchInStatement()がリリースされます。
ステートメントのタイプルールは次のとおりです。

それ以外の場合、戻り式の型は、関数の戻り値の型に等しいか、強制される必要があります。
例外は、配列ポインターまたは配列を配列ポインターに返すことができることです。つまり、戻り式の型は配列ポインターまたは配列型にすることができますが、囲まれた関数の戻り型は同じ要素型を持つ配列ポインター型になります。
A statement must conform the corresponding type rules for statements, otherwise the exception TypeMismatchInStatement() is released.
The type rules for statements are as follows:

  • The type of a conditional expression in an if statement must be boolean.
  • The type of expression 1 and expression 3 in a for statement must be integer while the type of expression 2 is boolean.
  • The type of condition expression in do while statement must be boolean.
  • For a return statement, if the return type of the enclosed function is void, the expression in the return statement must be empty.

Otherwise, the type of the return expression must be equal to or be coerced to the return type of the function.
An exception is an array pointer or array can be returned to an array pointer, i.e., the type of return expression can be in array pointer or array type while the return type of the enclosed function is in array pointer type with the same element type.

2.4 Type Mismatch In Expression:
式は式の型規則に準拠する必要があります。そうでない場合、例外TypeMismatchInExpression()がリリースされます。
式の型規則は次のとおりです。

  • E1 [E2]をサブスクライブする配列の場合、E1は配列型または配列ポインター型でなければならず、E2は整数でなければなりません。
  • バイナリおよび単項式の場合、型規則はMC仕様に記述されています。
  • 代入式の場合、左側(LHS)はvoid、配列ポインター型、配列型を除く任意の型にすることができます。

右側(RHS)は、LHSと同じタイプか、LHSタイプに強制できるタイプのいずれかです。
MCでは、整数だけがフロートを強制できます。

  • 関数呼び出し<関数名>(<引数>)の場合、実際のパラメーターの数は、対応する関数の仮パラメーターの数と同じでなければなりません。

割り当てのルールは、仮パラメーターがLHSと見なされ、対応する実際のパラメーターがRHSであるパラメーターの受け渡しに適用されます。
例外は、配列ポインターまたは配列を配列ポインターに渡すことができることです。つまり、実際のパラメーターは配列ポインターまたは配列型であり、対応する仮パラメーターは同じ要素型の配列ポインター型です。
An expression must conform the type rules for expressions, otherwise the exception TypeMismatchInExpression() is released.
The type rules for expression are as follows:

  • For an array subcripting E1[E2], E1 must be in array type or array pointer type and E2 must be integer.
  • For a binary and unary expression, the type rules are described in the MC specification.
  • For an assignment expression, the left-hand side (LHS) can be in any type except void, array pointer type and array type.

The right- hand side (RHS) is either in the same type as that of the LHS or in the type that can coerce to the LHS type.
In MC, just the integer can coerce to the float.

  • For a function call (), the number of the actual parameters must be the same as that of the formal parameters of the corresponding function.

The rule for an assignment is applied to parameter passing where a formal parameter is considered as the LHS and the corresponding actual parameter is the RHS.
An exception is an array pointer or array can be passed to an array pointer, i.e., the actual parameter can be in array pointer or array type while the corresponding formal parameter is in array pointer type with the same element type.

2.5 Function not return:
voidを返さない関数は、すべての実行パスで何かを返さなければなりません。
何も返されないパスが1つ存在する場合、例外FunctionNotReturn()が解放されます。
A function that does not return void must return something in every its execution paths.
If there exists one path where there is nothing returned, the exception FunctionNotReturn() will be released.

2.6 Break/Continue not in loop:
break/continueステートメントは、直接または間接的にループ内にある必要があります。そうでない場合、例外BreakNotInLoop()/ ContinueNotInLoop()が解放されます。
A break/continue statement must be inside directly or indirectly a loop otherwise the exception BreakNotInLoop()/ContinueNotInLoop() will be released.

2.7 No Entry Point:
MCプログラムのどこかに関数void main()が必要です。
そうでない場合、例外NoEntryPoint()が解放されます。
There must be a function void main () somewhere in a MC program.
Otherwise, the exception NoEntryPoint() is released.

2.8 Unreachable function:
メイン関数を除く関数は、別の関数によって呼び出される必要があります。そうでない場合、例外UnreachableFunction(<関数名>)が解放されます。
A function, except main function, must be invoked by another function, otherwise, the exception UnreachableFunction() is released.

2.9 Not Left Value:
例外NotLeftValue()は、代入演算子のLHSがアクセス可能なストレージ、つまり変数またはインデックス式でない場合に発生します。
The exception NotLeftValue() will be raised when the LHS of assignment operator is not accessible storage, i.e. a variable or an index expression.