public PascalErrorToken(Source source, PascalErrorCode errorCode, string tokenText) : base(source) { Text = tokenText; Type = PascalTokens.TokenTypes[PascalTokenType.Error]; Value = errorCode; }
// Parse a statement list. protected internal void ParseList(Token token, ICodeNode parentNode, PascalTokenType terminator, PascalErrorCode errorCode) { // Loop to parse each statement until the END token or the end of the source file. while (!(token is EofToken) && (token.type != terminator)) { // Parse a statement. The parent node adopts the statement node. ICodeNode statementNode = Parse(token); parentNode.AddChild(statementNode); token = CurrentToken(); TokenType tokenType = token.type; // Look for semicolon between statements. if (tokenType == PascalTokenType.SEMICOLON) token = NextToken(); // If at the start of the next assignment statement, then missing a semicolon. else if (tokenType == PascalTokenType.IDENTIFIER) errorHandler.flag(token, PascalErrorCode.MISSING_SEMICOLON, this); else if (tokenType != terminator) { errorHandler.flag(token, PascalErrorCode.UNEXPECTED_TOKEN, this); token = NextToken(); } } if (token.type == terminator) token = NextToken(); else errorHandler.flag(token, errorCode, this); }
public PascalErrorToken(Source source, PascalErrorCode errorCode, string tokenText) : base(source) { this.text = tokenText; this.type = PascalTokenType.ERROR; this.value = errorCode; }
private static ErrorCodeAttribute GetErrorCodeAttribute(this PascalErrorCode errorCode) { var type = errorCode.GetType(); var attribute = type.GetCustomAttribute <ErrorCodeAttribute>(); return(attribute); }
public void AbortTranslation(PascalErrorCode errorCode, Parser parser) { var fatalText = $"FATAL ERROR: " + errorCode.ToString(); parser.SendMessage(new Message(MessageType.SyntaxError, new object[] { 0, 0, "", fatalText })); Environment.Exit(errorCode.GetStatus()); }
public void Flag(Token token, PascalErrorCode errorCode, Parser parser) { parser.SendMessage(new Message(MessageType.SyntaxError, new object[] { token.LineNumber, token.Position, token.Text, errorCode.ToString() })); ErrorCount++; if (ErrorCount > MaxErrors) { AbortTranslation(PascalErrorCode.TooManyErrors, parser); } }
// Parse a statement list. protected internal void ParseList(Token token, ICodeNode parentNode, PascalTokenType terminator, PascalErrorCode errorCode) { // Loop to parse each statement until the END token or the end of the source file. while (!(token is EofToken) && (token.type != terminator)) { // Parse a statement. The parent node adopts the statement node. ICodeNode statementNode = Parse(token); parentNode.AddChild(statementNode); token = CurrentToken(); TokenType tokenType = token.type; // Look for semicolon between statements. if (tokenType == PascalTokenType.SEMICOLON) { token = NextToken(); } // If at the start of the next assignment statement, then missing a semicolon. else if (tokenType == PascalTokenType.IDENTIFIER) { errorHandler.flag(token, PascalErrorCode.MISSING_SEMICOLON, this); } else if (tokenType != terminator) { errorHandler.flag(token, PascalErrorCode.UNEXPECTED_TOKEN, this); token = NextToken(); } } if (token.type == terminator) { token = NextToken(); } else { errorHandler.flag(token, errorCode, this); } }
public static int GetStatus(this PascalErrorCode errorCode) { return(errorCode.GetErrorCodeAttribute().Status); }
public static string GetMessage(this PascalErrorCode errorCode) { return(errorCode.GetErrorCodeAttribute().Message); }