예제 #1
0
 public BoundFunctionLiteral(FunctionLiteral prototype, Scope scopeAtPrototype)
 {
     this.prototype = prototype;
     this.scopeAtPrototype = scopeAtPrototype;
 }
예제 #2
0
 public IStatement Bind(ref Scope scope)
 {
     // This thing would be full declared
     scope = new Scope(scope, this);
     return this;
 }
예제 #3
0
 public IExpression Bind(Scope scope)
 {
     return new IntegerRange(min, max);
 }
예제 #4
0
        static void Main(string[] args)
        {
            string file = @"D:\VS\Programs\InabaScript\InabaScript\basicExpressions.is";
            string[] lines = File.ReadAllLines(file);
            Parser p = new Parser(new Scanner(file));

            try
            {
                p.Parse();
            }
            catch (Exception e)
            {
                for (int i = Math.Max(0, p.la.line - 3); i < Math.Min(p.scanner.lines.Count, p.la.line + 2); i++)
                {
                    WriteColoredLine(lines, p, i);
                    if (i == p.la.line - 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(Enumerable.Range(1, p.la.col - 1).Aggregate("", (x, y) => x + " ") + "^");
                    }
                }

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(e.Message);
            }

            //for (int i = 0; i < lines.Length; i++)
            //{
            //    WriteColoredLine(lines, p, i);
            //}

            List<IStatement> boundStatements = new List<IStatement>();
            Scope s = new Scope();

            foreach (var statement in p.statements)
            {
                if (statement is MultiVariableDeclaration)
                {
                }
            }

            Console.ReadKey();
        }
예제 #5
0
 public static void Scopify(ref Scope scope, List<VariableDeclaration> declarations)
 {
     foreach (var decl in declarations)
     {
         scope = new Scope(scope, decl);
     }
 }
예제 #6
0
 public IExpression Bind(Scope scope)
 {
     return (IExpression)scope.GetDeclarationFor(Name);
 }
예제 #7
0
        public static VariableDeclaration Find(ref Scope scope, VariableDeclaration vardecl, string name, bool isDeclaration)
        {
            if (vardecl != null)
            {
                return vardecl;
            }

            IDeclaration decl = scope.GetDeclarationForOrNull(name);
            if (decl == null && isDeclaration)
            {
                var vd = new VariableDeclaration(name, new UnknownType());
                scope = new Scope(scope, vd);
                return vd;
            }
            if (decl is VariableDeclaration)
            {
                return (VariableDeclaration)decl;
            }
            throw new Exception(name + " not a variable");
        }
예제 #8
0
        public Scope(Scope parent, IDeclaration decl)
        {
            this.name = decl.Name;
            this.parent = parent;
            this.scopeTable = parent.scopeTable;
            this.funcTypeToLiterals = parent.funcTypeToLiterals;

            if (scopeTable.ContainsKey(decl.Name))
            {
                throw new Exception("already has " + decl);
            }
            this.typeTable = parent.typeTable;
            scopeTable.Add(decl.Name, decl);
            if (decl is IType)
            {
                this.typeTable.Add(decl.Name, (IType)decl);
            }
        }
예제 #9
0
 public Scope(Scope parent)
 {
     this.scopeTable = new Dictionary<string, IDeclaration>(parent.scopeTable);
     this.typeTable = new Dictionary<string, IType>(parent.typeTable);
     this.funcTypeToLiterals = new Dictionary<string, List<BoundFunctionLiteral>>(parent.funcTypeToLiterals);
 }
예제 #10
0
 public IExpression Bind(Scope scope)
 {
     BoundFunctionLiteral bfl = new BoundFunctionLiteral(this, scope);
     scope.RegisterFuncLiteral(bfl);
     return bfl;
 }
예제 #11
0
 public IExpression Bind(Scope scope)
 {
     return this;
 }