| class CompilerError(Exception): | |
| """Base class for all compiler errors""" | |
| def __init__(self, message, line=None, column=None): | |
| self.message = message | |
| self.line = line | |
| self.column = column | |
| super().__init__(self.format_message()) | |
| def format_message(self): | |
| if self.line is not None: | |
| return f"Line {self.line}: {self.message}" | |
| return self.message | |
| class LexicalError(CompilerError): | |
| """Lexical analysis error""" | |
| pass | |
| class SyntaxError(CompilerError): | |
| """Syntax analysis error""" | |
| pass | |
| class SemanticError(CompilerError): | |
| """Semantic analysis error""" | |
| pass | |
| class LanguageNotSupportedError(CompilerError): | |
| """Language not supported error""" | |
| pass |