コード例 #1
0
        private AstNode ClassDeclaration()
        {
            Token name = Consume(TokenType.IDENTIFIER, "Expect class name.");

            var superClass = default(VarExpr);

            if (Match(TokenType.LESS))
            {
                Consume(TokenType.IDENTIFIER, "Expect base class name.");
                superClass = new VarExpr(Previous());
            }

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

            var methods = new List <FunctionStmt>();

            while (!Check(TokenType.RIGHT_BRACE) && !IsAtEnd())
            {
                methods.Add(FuncDeclaration("method") as FunctionStmt);
            }

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

            return(new ClassStmt(name, superClass, methods));
        }
コード例 #2
0
 public override Null Visit(VarExpr node)
 {
     context = null;
     log.ErrorBadKeyword(node.location, "var");
     node.computedType = new ErrorType();
     return null;
 }
コード例 #3
0
ファイル: Parser.cs プロジェクト: KarbonKitty/nLox
        private ClassStmt ClassDeclaration()
        {
            var name = Consume(TokenType.Identifier, "Expect class name");

            VarExpr superclass = null;

            if (Match(TokenType.Less))
            {
                Consume(TokenType.Identifier, "Expect superclass name.");
                superclass = new VarExpr(Previous());
            }

            Consume(TokenType.LeftBrace, "Expect '{' before class body.");

            var methods = new List <FunctionStmt>();

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

            Consume(TokenType.RightBrace, "Expect '}' after class body.");

            return(new ClassStmt(name, superclass, methods));
        }
コード例 #4
0
        /**
         * Creates the echo statement.
         */
        public ClosureStaticStatement(Location location,
                                      VarExpr var,
                                      Expr initValue)
        {
            super(location);

            _var       = var;
            _initValue = initValue;
        }
コード例 #5
0
        public object VisitVarExpr(VarExpr expr)
        {
            if (_scopes.Count > 0 && !_scopes.Peek()[expr.Name.Lexeme])
            {
                Lox.Error(expr.Name, "Cannot read local variable in its own initializer.");
            }

            ResolveLocal(expr, expr.Name);

            return(null);
        }
コード例 #6
0
        /**
         * Creates the echo statement.
         */
        public ClassStaticStatement(Location location,
                                    StringValue staticName,
                                    VarExpr var,
                                    Expr initValue)
        {
            super(location);

            _staticName = staticName;
            _var        = var;
            _initValue  = initValue;
        }
コード例 #7
0
        /**
         * Creates the echo statement.
         */
        public StaticStatement(Location location,
                               StringValue uniqueStaticName,
                               VarExpr var,
                               Expr initValue)
        {
            super(location);

            _uniqueStaticName = uniqueStaticName;

            _var       = var;
            _initValue = initValue;
        }
コード例 #8
0
ファイル: ps-lang.cs プロジェクト: balkin/playscript-mono
        public override bool Resolve(BlockContext bc)
        {
            if (type_expr == null)
            {
                if (Initializer == null)
                {
                    type_expr = new UntypedTypeExpression(loc);
                }
                else
                {
                    type_expr = new VarExpr(loc);
                }
            }

            return(base.Resolve(bc));
        }
コード例 #9
0
ファイル: Interpreter.cs プロジェクト: CaptainNic/cslox
 public object VisitVarExpr(VarExpr expr)
 {
     return(LookUpVariable(expr.Name, expr));
 }
コード例 #10
0
ファイル: cs-parser.cs プロジェクト: furesoft/NRefactory
void case_864()
#line 5810 "cs-parser.jay"
{ 
		/* Ok, the above "primary_expression" is there to get rid of*/
		/* both reduce/reduce and shift/reduces in the grammar, it should*/
		/* really just be "type_name".  If you use type_name, a reduce/reduce*/
		/* creeps up.  If you use namespace_or_type_name (which is all we need*/
		/* really) two shift/reduces appear.*/
		/* */

		/* So the super-trick is that primary_expression*/
		/* can only be either a SimpleName or a MemberAccess. */
		/* The MemberAccess case arises when you have a fully qualified type-name like :*/
		/* Foo.Bar.Blah i;*/
		/* SimpleName is when you have*/
		/* Blah i;*/
		
		var expr = (ATypeNameExpression) yyVals[-1+yyTop];
		if (yyVals[0+yyTop] == null) {
			if (expr.Name == "var" && expr is SimpleName)
				yyVal = new VarExpr (expr.Location);
			else
				yyVal = yyVals[-1+yyTop];
		} else {
			yyVal = new ComposedCast (expr, (ComposedTypeSpecifier) yyVals[0+yyTop]);
		}
	  }
コード例 #11
0
ファイル: cs-parser.cs プロジェクト: furesoft/NRefactory
void case_400()
#line 3278 "cs-parser.jay"
{
		if (yyVals[0+yyTop] != null) {
			yyVal = new ComposedCast ((ATypeNameExpression) yyVals[-1+yyTop], (ComposedTypeSpecifier) yyVals[0+yyTop]);
		} else {
			var sn = yyVals[-1+yyTop] as SimpleName;
			if (sn != null && sn.Name == "var")
				yyVal = new VarExpr (sn.Location);
			else
				yyVal = yyVals[-1+yyTop];
		}
	  }
コード例 #12
0
        /**
         * Creates the echo statement.
         */
        public GlobalStatement(Location location, VarExpr var)
        {
            super(location);

            _var = var;
        }