コード例 #1
0
        private Stmt ClassDeclaration()
        {
            var name = Consume(IDENTIFIER, "Expected class name.");

            Expr superclass = null;

            if (Match(LESS))
            {
                Consume(IDENTIFIER, "Expected superclass.");
                superclass = new Expr.Variable(Previous());
            }

            Consume(LEFT_BRACE, "Expected '{' before class body.");

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

            while (!Check(RIGHT_BRACE) && !IsAtEnd())
            {
                methods.Add(Function("method"));
            }

            Consume(RIGHT_BRACE, "Expected '}' after class body.");

            return(new Stmt.Class(name, superclass, methods));
        }
コード例 #2
0
        public object VisitVariableExpr(Expr.Variable expr)
        {
            if (IsDeclaredExact(expr.Name.Lexeme, false) == true)
            {
                _logger.Error(expr.Name,
                              "Cannot read local variable in its own initializer.");
            }

            ResolveLocal(expr, expr.Name);
            return(null);
        }
コード例 #3
0
ファイル: Interpreter.cs プロジェクト: loqix/CSharpLox
 public object VisitVariableExpr(Expr.Variable expr)
 {
     return(LookUpVariable(expr.Name, expr));
 }
コード例 #4
0
 public string VisitVariableExpr(Expr.Variable expr)
 {
     return(expr.Name.Lexeme);
 }