Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 public object VisitVariableExpr(Expr.Variable expr)
 {
     return(LookUpVariable(expr.Name, expr));
 }
Ejemplo n.º 4
0
 public string VisitVariableExpr(Expr.Variable expr)
 {
     return(expr.Name.Lexeme);
 }