Example #1
0
        protected void addErrorMesage(string message, IToken offendingToken)
        {
            ErrorMessage error = new ErrorMessage();
            error.SourceFile = _driver.SourceFilePath;
            error.Message = message;

            if (offendingToken != null)
            {
                error.Context = offendingToken.InputStream.ToString().Split('\n')[offendingToken.Line - 1].Replace('\t', ' ').TrimEnd();
                error.Line = offendingToken.Line;
                error.Column = offendingToken.Column;
                error.StartToken = offendingToken.StartIndex;
                error.EndToken = offendingToken.StopIndex;
            }

            _driver.Errors.Add(error);
        }
Example #2
0
        public override void SyntaxError(IRecognizer recognizer, IToken offendingSymbol, int line, int charPositionInLine, string msg, RecognitionException e)
        {
            ErrorMessage errorMessage = new ErrorMessage();

            CommonTokenStream tokens = (CommonTokenStream)recognizer.InputStream;

            errorMessage.SourceFile = _driver.SourceFilePath;
            errorMessage.Context = tokens.TokenSource.InputStream.ToString().Split('\n')[line - 1].Replace('\t', ' ').TrimEnd();
            errorMessage.Line = line;
            errorMessage.Column = charPositionInLine;
            errorMessage.Message = msg;
            errorMessage.StartToken = offendingSymbol.StartIndex;
            errorMessage.EndToken = offendingSymbol.StopIndex;

            _driver.Errors.Add(errorMessage);
        }
Example #3
0
        public void SecondPass()
        {
            if (Vectors == null)
            {
                ErrorMessage error = new ErrorMessage();
                error.SourceFile = SourceFilePath;
                error.Message = "Required vectors statement not found.";
                Errors.Add(error);
            }

            ParseTreeWalker walker = new ParseTreeWalker();
            walker.Walk(new SecondCpuPass(this), _rootTree);

            if (Errors.Count > 0)
            {
                throw new CompilerErrorException();
            }
        }
Example #4
0
        private void verifyBranchLength()
        {
            long physicalAddress = 0;

            Scope parentScope = _globalScope;
            foreach (var scope in parentScope.Children)
            {
                foreach (var instruction in scope.Statements)
                {
                    if (instruction is CpuInstructionStatement)
                    {
                        var cpuInstruction = instruction as CpuInstructionStatement;
                        if (cpuInstruction.AddressingMode == CpuAddressingMode.Relative)
                        {
                            int instructionSize = (int)instruction.ComputeSize();

                            if (cpuInstruction.Arguments[0] is LabelInstructionArgument)
                            {
                                var labelArgument = cpuInstruction.Arguments[0] as LabelInstructionArgument;
                                int labelAddress = (int)scope.AddressFor(labelArgument.Label);

                                int branchLength = labelAddress - ((int)physicalAddress + instructionSize);
                                if (branchLength > sbyte.MaxValue || branchLength < sbyte.MinValue)
                                {
                                    ErrorMessage error = new ErrorMessage();
                                    error.SourceFile = SourceFilePath;
                                    error.Message = String.Format("Branch label '{0}' is too far away. Consider reducing the distance or use a jmp.", labelArgument.Label);
                                    error.Line = instruction.Line;
                                    error.Column = instruction.Column;

                                    Errors.Add(error);
                                }
                            }
                        }
                    }

                    physicalAddress += instruction.ComputeSize();
                }
            }
        }
Example #5
0
 static void printErrorMessage(ErrorMessage error)
 {
     Console.Error.WriteLine("{0}({1},{2}): error: {3}", error.SourceFile, error.Line, error.Column, error.Message);
     if (!String.IsNullOrEmpty(error.Context))
     {
         Console.Error.WriteLine(error.Context);
         for (int i = 0; i < error.Column; ++i)
         {
             Console.Error.Write(' ');
         }
         for(int i=error.StartToken; i<=error.EndToken; ++i)
         {
             Console.Error.Write("^");
         }
         Console.Error.WriteLine();
     }
 }