コード例 #1
0
ファイル: Resolver.cs プロジェクト: jingle-lang/jingle
        public object visitVariableExpr(Expr.Variable expr)
        {
            if (scopes.Count > 0 && scopes[scopes.Count - 1].ContainsKey(expr.name.lexeme))
            {
                if (scopes[scopes.Count - 1][expr.name.lexeme] == false)
                {
                    Jingle.Error(expr.name, "Cannot read local variable in its own initializer.");
                }
            }

            resolveLocal(expr, expr.name);
            return(null);
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: jingle-lang/jingle
        private Stmt classDeclaration()
        {
            Token name = consume(TokenType.IDENTIFIER, "Expect class name.");

            Expr.Variable superclass = null;
            if (match(TokenType.LESS))
            {
                consume(TokenType.IDENTIFIER, "Expect superclass name.");
                superclass = new Expr.Variable(previous());
            }

            consume(TokenType.COLON, "Expect '{' before class body.");

            List <Stmt.Function> methods = new List <Stmt.Function>();

            while (!check(TokenType.END) && !isAtEnd())
            {
                methods.Add(function("method"));
            }

            consume(TokenType.END, "Expect '}' after class body.");

            return(new Stmt.Class(name, superclass, methods));
        }
コード例 #3
0
ファイル: AstPrinter.cs プロジェクト: jingle-lang/jingle
 public string visitVariableExpr(Expr.Variable expr)
 {
     return("");
 }
コード例 #4
0
 public Class(Token name, Expr.Variable superclass, List <Stmt.Function> methods)
 {
     this.name       = name;
     this.superclass = superclass;
     this.methods    = methods;
 }
コード例 #5
0
 public object visitVariableExpr(Expr.Variable expr)
 {
     return(lookUpVariable(expr.name, expr));
 }