コード例 #1
0
        public IEnumerable <Token> LexFile(SourceCode sourceCode)
        {
            this.sourceCode = sourceCode;
            builder.Clear();
            line   = 1;
            index  = 0;
            column = 0;
            CreateToken(TokenKind.EndOfFile);

            return(LexContents());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            LexerAnaliser  lexer  = new LexerAnaliser();
            SyntaxAnaliser parser = new SyntaxAnaliser(lexer.ErrorSink);

            while (true)
            {
                Console.Write("InsuranceLanguage> ");
                var program    = Console.ReadLine();
                var sourceCode = new SourceCode(program);
                var tokens     = lexer.LexFile(sourceCode).ToArray();

                foreach (var token in tokens)
                {
                    Console.WriteLine($"{token.TokenKind} ( \"{token.Value}\" ) ");
                }

                if (lexer.ErrorSink.Count() > 0)
                {
                    foreach (var error in lexer.ErrorSink)
                    {
                        Console.WriteLine(new string('-', Console.WindowWidth / 3));

                        WriteError(error);
                    }
                    lexer.ErrorSink.Clear();
                }
                else
                {
                    //var ast = parser.ParseFile(sourceCode, tokens, SyntaxAnalizer.OptionalSemicolons);
                    if (lexer.ErrorSink.Count() > 0)
                    {
                        foreach (var error in lexer.ErrorSink)
                        {
                            Console.WriteLine(new string('-', Console.WindowWidth / 3));

                            WriteError(error);
                        }
                        lexer.ErrorSink.Clear();
                    }
                }

                Console.WriteLine(new string('-', Console.WindowWidth / 2));
            }
        }
コード例 #3
0
 public void AddError(string mes, SourceCode sourceCode, Severity severity, SourceSpan sourceSpan)
 {
     errors.Add(new ErrorEntry(mes, sourceCode.GetLines(sourceSpan.Start.Line, sourceSpan.End.Line), severity, sourceSpan));
 }
コード例 #4
0
 public LexerAnaliser(ErrorSink errorSink)
 {
     this.errorSink = errorSink;
     builder        = new StringBuilder();
     sourceCode     = null;
 }