📄 errormanager.java
字号:
/*
* @(#)ErrorManager.java 1.0.0 05/13/2007
*
* Copyright 2007 Xuxt@buaa, No.34060520 All rights reserved.
*/
package com.king4solomon.homework.compiler.core;
import com.king4solomon.homework.compiler.gui.*;
/**
* 用于记录和生成错误与警告信息的类
*
* @author Xuxt@buaa
* @version 1.0.0
*/
public class ErrorManager {
/**
* 打印错误信息方法
*
* @param errorNum
* 错误编号
*/
public static void error(int errorNum) {
errCount += 1;
ProblemPane.write(errors[errorNum] + " line " + Lexer.lineNo + ", row "
+ Lexer.cCount + '\n');
}
/**
* 打印警告信息方法
*
* @param warNum
* 警告编号
*/
public static void warning(int warNum) {
warCount += 1;
ProblemPane.write(warnings[warNum] + " line " + Lexer.lineNo + ", row "
+ Lexer.cCount + '\n');
}
/**
* 错误信息数组
*/
private static String[] errors = {
"ERROR E00: Fatal error, incomplete program!",
"ERROR E01: Fetal error, symbol problems!", "ERROR E02: ",
"ERROR E03: ", "ERROR E04: ",
"ERROR E05: Invalid evaluation for different in type!",
"ERROR E06: Invalid symbol type in input statement!",
"ERROR E07: Invalid quantity of parameters!",
"ERROR E08: Invalid function reference before declaration!",
"ERROR E09: Missing type before identifier declaration!",
"ERROR E10: Different return type with declaration!",
"ERROR E11: Unrecognizable structure at beginning of the program!",
"ERROR E12: Missing ':' in case statement!",
"ERROR E13: Missing value after \"case\"!",
"ERROR E14: Invalid key word after identifier!",
"ERROR E15: Invalid key word after \"void\"!",
"ERROR E16: Missing '{' after ')'!",
"ERROR E17: Missing ')' after '('!",
"ERROR E18: Missing '(' after \"main\"!",
"ERROR E19: Missing ';' after statement!",
"ERROR E20: Invalid symbol after \"const\"!",
"ERROR E21: Invalid character type!",
"ERROR E22: Invalid character after '.'!",
"ERROR E23: Too long for a type of character!",
"ERROR E24: Too long for a type of String!",
"ERROR E25: Invalid character after '!'!",
"ERROR E26: Missing identifier after type!",
"ERROR E27: Invalid symbol in function defination!",
"ERROR E28: Unknown character in source program!",
"ERROR E29: Invalid key word at beginning of sentence!",
"ERROR E30: Missing type before identifier!",
"ERROR E31: Missing '(' after identifier!",
"ERROR E32: Missing ')' after parameters!",
"ERROR E33: Missing '}' after compound statement!",
"ERROR E34: Missing value after '='!",
"ERROR E35: Missing '=' after identifier!",
"ERROR E36: Missing \"main\" after \"void\"!",
"ERROR E37: Missing identifier after ','!",
"ERROR E38: Missing '(' after \"scanf\"!",
"ERROR E39: Missing identifier after \"void\"!",
"ERROR E40: Missing '(' after \"if\"!",
"ERROR E41: Missing ')' after condition!",
"ERROR E42: Missing ')' after expression!",
"ERROR E43: Invalid symbol in factor!",
"ERROR E44: Missing '(' after \"while\"!",
"ERROR E45: Missing '(' after \"printf\"!",
"ERROR E46: Invalid symbol in outLine!",
"ERROR E47: Missing '(' after \"switch\"!",
"ERROR E48: Missing '}' after cases!",
"ERROR E49: Invalid symbol at beginning of case!",
"ERROR E50: Invalid type in program!",
"ERROR E51: Invalid redeclaration!",
"ERROR E52: Undeclared identifier referred!",
"ERROR E53: Invalid reference before evaluation!",
"ERROR E54: The function has not returned a value!",
"ERROR E55: The function has not returned!",
"ERROR E56: Invalid reference before evaluation!",
"ERROR E57: The function should not return a value!",
"ERROR E58: The function has not returned!",
"ERROR E59: Invalid referrence before evaluation!",
"ERROR E60: Invalid evaluation to constant!" };
/**
* 警告信息数组
*/
static String[] warnings = {
"WARNING W00: Redundant zero at begining of a number!",
"WARNING W01: The function quit without a return statement!" };
/**
* 错误计数器
*/
public static int errCount = 0;
/**
* 警告计数器
*/
public static int warCount = 0;
/**
* 词法错误跳读数组
*/
static char[][] lexErrSet = {
{ ' ', ';', '\n' },// 0
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },// 10
{ ' ', ';', '\n' }, { ' ', ';', '\n' }, { ' ', ';', '\n' },
{ ' ', ';', '\n' }, { ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },
{ ' ', ';', '\n' },// 20
{ ' ', ';', '\n' }, { ' ', ';', '\n' }, { ' ', ';', '\n' },
{ ' ', ';', '\n' }, { ' ', ';', '\n' }, { ' ', ';', '\n' },
{ ' ', ';', '\n' }, { ' ', ';', '\n' }, { ' ', ';', '\n' },
{ ' ', ';', '\n' },// 30
};
/**
* 语法错误跳读数组
*/
static int[][] symErrSet = {
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },// 10
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON, ConstSet.TYPE_IDEN,
ConstSet.RESERVED_WORD },
{ ConstSet.RESERVED_WORD, ConstSet.STOP },
{ ConstSet.RESERVED_WORD, ConstSet.STOP, ConstSet.RESERVED_WORD,
ConstSet.TYPE_IDEN },
{ ConstSet.LEFT_CURLY, ConstSet.RIGHT_CURLY, ConstSet.STOP },
{ ConstSet.RIGHT_PRENTHESES, ConstSet.LEFT_CURLY,
ConstSet.RIGHT_CURLY, ConstSet.STOP },
{ ConstSet.STOP, ConstSet.SEMICOLON, ConstSet.TYPE_IDEN },
{ ConstSet.STOP, ConstSet.SEMICOLON },// 20
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.TYPE_IDEN, ConstSet.RESERVED_WORD,
ConstSet.IDENTIFIER },
{ ConstSet.STOP, ConstSet.SEMICOLON, ConstSet.RIGHT_CURLY, },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },// 30
{ ConstSet.STOP, ConstSet.SEMICOLON, ConstSet.TYPE_IDEN,
ConstSet.RIGHT_PRENTHESES },
{ ConstSet.STOP, ConstSet.SEMICOLON, ConstSet.LEFT_CURLY,
ConstSet.TYPE_IDEN, ConstSet.RESERVED_WORD },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },// 40
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },// 50
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON, ConstSet.RIGHT_CURLY },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON, ConstSet.RIGHT_CURLY },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON },
{ ConstSet.STOP, ConstSet.SEMICOLON } // 60
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -