예제 #1
0
        public Analyzer(IoManager.IoManager ioManager, Tokenizer.Tokenizer tokenizer)
        {
            IoManager = ioManager;
            Tokenizer = tokenizer;
            Scopes    = new List <Scope>();
            var fictitiousScope = new Scope();

            fictitiousScope.Types.Add(new Type()
            {
                Identifier = "integer", BaseType = BaseType.Scalar, ScalarType = ScalarType.Integer
            });
            fictitiousScope.Types.Add(new Type()
            {
                Identifier = "real", BaseType = BaseType.Scalar, ScalarType = ScalarType.Real
            });
            fictitiousScope.Types.Add(new Type()
            {
                Identifier = "char", BaseType = BaseType.Scalar, ScalarType = ScalarType.Char
            });
            fictitiousScope.Types.Add(new Type()
            {
                Identifier = "string", BaseType = BaseType.Scalar, ScalarType = ScalarType.String
            });
            fictitiousScope.Types.Add(new Type()
            {
                Identifier = "boolean", BaseType = BaseType.Scalar, ScalarType = ScalarType.Boolean
            });
            Scopes.Add(fictitiousScope);
        }
예제 #2
0
        public Tokenizer(IoManager.IoManager ioManager)
        {
            IoManager = ioManager;

            Names = new HashSet <string>();

            _storedCharacters = new Queue <string>();
            _storedToken      = new Token();
        }
예제 #3
0
        public void GetCharacterTest()
        {
            const string inputFileName  = "input.txt";
            const string outputFileName = "output.txt";
            var          inputText      = string.Join(Environment.NewLine, new[] { "ab1", "qwe2", "asdf4" });

            File.WriteAllText(inputFileName, inputText);

            var inputOutputModule = new IoManager.IoManager(inputFileName, outputFileName);
            var stringBuilder     = new StringBuilder();

            while (!inputOutputModule.IsEndOfFile)
            {
                stringBuilder.Append(inputOutputModule.GetNextCharacter());
            }

            inputOutputModule.Dispose();
        }
예제 #4
0
        public void ScannerTest()
        {
            const string inputFileName  = "input.txt";
            const string outputFileName = "output.txt";
            //var inputText = "*  /  =  ,  ;  :  .  ^  (  )  [  ]  {  }  <  >  <=  >=  <>  +  -  //  (*  *)  :=  .. &";
            var inputText =
//@"function Even(x: integer): boolean;
//begin
//  Result := x mod 2 = 0
//end;

//begin
//  writeln(Even(3.0));
//  writeln(Even(4));
//  writeln(Even(7777777777777777));
//end.";
                @"// comment
(* comments 
 comments 
*)
while";

            File.WriteAllText(inputFileName, inputText);

            var inputOutputModule = new IoManager.IoManager(inputFileName, outputFileName);

            var scanner = new Tokenizer.Tokenizer(inputOutputModule);
            var tokens  = new List <Token>();

            while (!scanner.IsEndOfTokens)
            {
                tokens.Add(scanner.GetNextToken());
            }

            inputOutputModule.OutputStream.WriteLine();

            foreach (var token in tokens)
            {
                inputOutputModule.OutputStream.WriteLine(token.ToString());
            }

            inputOutputModule.Dispose();
        }