Exemplo n.º 1
0
 public PascalErrorToken(Source source, PascalErrorCode errorCode,
                         string tokenText) : base(source)
 {
     Text  = tokenText;
     Type  = PascalTokens.TokenTypes[PascalTokenType.Error];
     Value = errorCode;
 }
Exemplo n.º 2
0
        // 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;
 }
Exemplo n.º 4
0
        private static ErrorCodeAttribute GetErrorCodeAttribute(this PascalErrorCode errorCode)
        {
            var type      = errorCode.GetType();
            var attribute = type.GetCustomAttribute <ErrorCodeAttribute>();

            return(attribute);
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        // 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);
            }
        }
Exemplo n.º 8
0
 public PascalErrorToken(Source source, PascalErrorCode errorCode, string tokenText) : base(source)
 {
     this.text  = tokenText;
     this.type  = PascalTokenType.ERROR;
     this.value = errorCode;
 }
Exemplo n.º 9
0
 public static int GetStatus(this PascalErrorCode errorCode)
 {
     return(errorCode.GetErrorCodeAttribute().Status);
 }
Exemplo n.º 10
0
 public static string GetMessage(this PascalErrorCode errorCode)
 {
     return(errorCode.GetErrorCodeAttribute().Message);
 }