Exemple #1
0
        private void Import_()
        {
            var s      = this.Pop();
            var stream = s switch
            {
                Value.String x => File.OpenRead(x.Value),
                Value.Stream x => x.Value,
                _ => throw new NotSupportedException(),
            };

            using (var reader = new StreamReader(stream))
            {
                var source = reader.ReadToEnd();
                var tokens = Parser.Tokenizer.Tokenize(source);
                var defs   = Parser.Def.Many().Parse(tokens);
                Array.ForEach(
                    defs.ToArray(),
                    x => this.AddUsrdef(x.Id, x.Body));
            }
        }
Exemple #2
0
        private void Name_()
        {
            new Validator("name")
            .OneParameter()
            .Validate(this.stack);

            var sym  = this.Pop();
            var name = sym switch
            {
                Value.Int x => "int",
                Value.Float x => "float",
                Value.Bool x => "bool",
                Value.Char x => "char",
                Value.String x => "string",
                Value.List x => "list",
                Value.Set x => "set",
                Value.Stream x => "stream",
                Value.Symbol x => x.Value,
                _ => throw new NotSupportedException(),
            };

            this.Push(new Value.String(name));
        }