typecheck.txt
来自「一个编译器的例子,基于c语言,在linux下开发 现在了简单的c语言例子」· 文本 代码 · 共 55 行
TXT
55 行
COMP510 04AID: 0130348name: Yinghao QinREPORT ONETYPE ERRORSDescription of the errors in test filethe test program is "c-wrong-cast.c-". There are 6 errors totally. At the line 15, the code is trying to assign a float id "f" to an char type id "name", it is not allowed in my language.At the line 16, it try to assign a char type id "name" to a float id "f", which is not allowed either. At the line 18, assigning an integer id to an array name without index is not allowed.At the line 19, array name without index can not assign to a float id "f".At the line 21, the function "fun" need a char type argument, but the passed is float type id "f", which is not allowed.At the line 28, function return type is char but it returns a string "abc", that is not allowed.Discussing about type checking In my language, integer and float are casted to each other automatically. In calculation, whenever there is an operand which is a float type, the other operand will be casted to a float type if the other operand is not a float type. Integer and char type can be casted to each other as well. Actually, all char type value is treated as integer by its ASCII code. In my language, the name of array represents the address of its first element, therefore, assigning a float, int or char type value to the name of array, which is only an address, does not make any sense at all. Hence, such a assignment is not allowed in my language.The output messege after type checking :cms-gb04-35:[901]~/project>c- c-wrong-cast.c-ERROR: type mismatch-parsing messege@(15,8): can not assign float type value to a char type variableERROR: type mismatch-parsing messege@(16,19): can not assign char type value to a float type variableERROR: type mismatch-parsing messege@(18,9): array or structure name can not involve assignmentERROR: type mismatch-parsing messege@(19,21): array or structure name can not involve assignmentERROR: type mismatch-parsing messege(21,8): identifier "f" is float type,but need char hereERROR: type mismatch-parsing messege@(28,20): return type wrong6 error(s) found totally
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?