當前位置: 首頁>>代碼示例>>C#>>正文


C# Execution.ScriptLoadingContext類代碼示例

本文整理匯總了C#中MoonSharp.Interpreter.Execution.ScriptLoadingContext的典型用法代碼示例。如果您正苦於以下問題:C# ScriptLoadingContext類的具體用法?C# ScriptLoadingContext怎麽用?C# ScriptLoadingContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ScriptLoadingContext類屬於MoonSharp.Interpreter.Execution命名空間,在下文中一共展示了ScriptLoadingContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateSubTree

        /// <summary>
        ///     Creates a sub tree of binary expressions
        /// </summary>
        private static Expression CreateSubTree(LinkedList list, ScriptLoadingContext lcontext)
        {
            var opfound = list.OperatorMask;

            var nodes = list.Nodes;

            if ((opfound & POWER) != 0)
                nodes = PrioritizeRightAssociative(nodes, lcontext, POWER);

            if ((opfound & MUL_DIV_MOD) != 0)
                nodes = PrioritizeLeftAssociative(nodes, lcontext, MUL_DIV_MOD);

            if ((opfound & ADD_SUB) != 0)
                nodes = PrioritizeLeftAssociative(nodes, lcontext, ADD_SUB);

            if ((opfound & STRCAT) != 0)
                nodes = PrioritizeRightAssociative(nodes, lcontext, STRCAT);

            if ((opfound & COMPARES) != 0)
                nodes = PrioritizeLeftAssociative(nodes, lcontext, COMPARES);

            if ((opfound & LOGIC_AND) != 0)
                nodes = PrioritizeLeftAssociative(nodes, lcontext, LOGIC_AND);

            if ((opfound & LOGIC_OR) != 0)
                nodes = PrioritizeLeftAssociative(nodes, lcontext, LOGIC_OR);


            if (nodes.Next != null || nodes.Prev != null)
                throw new InternalErrorException("Expression reduction didn't work! - 1");
            if (nodes.Expr == null)
                throw new InternalErrorException("Expression reduction didn't work! - 2");

            return nodes.Expr;
        }
開發者ID:eddy5641,項目名稱:moonsharp,代碼行數:38,代碼來源:BinaryOperatorExpression.cs

示例2: LiteralExpression

        public LiteralExpression(ScriptLoadingContext lcontext, Token t)
            : base(lcontext)
        {
            switch (t.Type)
            {
                case TokenType.Number:
                case TokenType.Number_Hex:
                case TokenType.Number_HexFloat:
                    Value = DynValue.NewNumber(t.GetNumberValue()).AsReadOnly();
                    break;
                case TokenType.String:
                case TokenType.String_Long:
                    Value = DynValue.NewString(t.Text).AsReadOnly();
                    break;
                case TokenType.True:
                    Value = DynValue.True;
                    break;
                case TokenType.False:
                    Value = DynValue.False;
                    break;
                case TokenType.Nil:
                    Value = DynValue.Nil;
                    break;
                default:
                    throw new InternalErrorException("type mismatch");
            }

            if (Value == null)
                throw new SyntaxErrorException(t, "unknown literal format near '{0}'", t.Text);

            lcontext.Lexer.Next();
        }
開發者ID:eddy5641,項目名稱:moonsharp,代碼行數:32,代碼來源:LiteralExpression.cs

示例3: ReturnStatement

		public ReturnStatement(ScriptLoadingContext lcontext, Expression e, SourceRef sref)
			: base(lcontext)
		{
			m_Expression = e;
			m_Ref = sref;
			lcontext.Source.Refs.Add(sref);
		}
開發者ID:eddy5641,項目名稱:LuaSharp,代碼行數:7,代碼來源:ReturnStatement.cs

示例4: ForLoopStatement

		public ForLoopStatement(ScriptLoadingContext lcontext, Token nameToken, Token forToken)
			: base(lcontext)
		{
			//	for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end | 

			// lexer already at the '=' ! [due to dispatching vs for-each]
			CheckTokenType(lcontext, TokenType.Op_Assignment);

			m_Start = Expression.Expr(lcontext);
			CheckTokenType(lcontext, TokenType.Comma);
			m_End = Expression.Expr(lcontext);

			if (lcontext.Lexer.Current.Type == TokenType.Comma)
			{
				lcontext.Lexer.Next();
				m_Step = Expression.Expr(lcontext);
			}
			else
			{
				m_Step = new LiteralExpression(lcontext, DynValue.NewNumber(1));
			}

			lcontext.Scope.PushBlock();
			m_VarName = lcontext.Scope.DefineLocal(nameToken.Text);
			m_RefFor = forToken.GetSourceRef(CheckTokenType(lcontext, TokenType.Do));
			m_InnerBlock = new CompositeStatement(lcontext);
			m_RefEnd = CheckTokenType(lcontext, TokenType.End).GetSourceRef();
			m_StackFrame = lcontext.Scope.PopBlock();

			lcontext.Source.Refs.Add(m_RefFor);
			lcontext.Source.Refs.Add(m_RefEnd);
		}		
開發者ID:eddy5641,項目名稱:LuaSharp,代碼行數:32,代碼來源:ForLoopStatement.cs

示例5: BinaryOperatorExpression

 private BinaryOperatorExpression(Expression exp1, Expression exp2, Operator op, ScriptLoadingContext lcontext)
     : base(lcontext)
 {
     m_Exp1 = exp1;
     m_Exp2 = exp2;
     m_Operator = op;
 }
開發者ID:eddy5641,項目名稱:moonsharp,代碼行數:7,代碼來源:BinaryOperatorExpression.cs

示例6: CreateLambdaBody

		private Statement CreateLambdaBody(ScriptLoadingContext lcontext)
		{
			Token start = lcontext.Lexer.Current;
			Expression e = Expression.Expr(lcontext);
			Token end = lcontext.Lexer.Current;
			SourceRef sref = start.GetSourceRefUpTo(end);
			Statement s = new ReturnStatement(lcontext, e, sref);
			return s;
		}
開發者ID:eddy5641,項目名稱:LuaSharp,代碼行數:9,代碼來源:FunctionDefinitionExpression.cs

示例7: CheckVar

		private IVariable CheckVar(ScriptLoadingContext lcontext, Expression firstExpression)
		{
			IVariable v = firstExpression as IVariable;

			if (v == null)
				throw new SyntaxErrorException(lcontext.Lexer.Current, "unexpected symbol near '{0}' - not a l-value", lcontext.Lexer.Current);

			return v;
		}
開發者ID:eddy5641,項目名稱:LuaSharp,代碼行數:9,代碼來源:AssignmentStatement.cs

示例8: SymbolRefExpression

		public SymbolRefExpression(ScriptLoadingContext lcontext, SymbolRef refr)
			: base(lcontext)
		{
			m_Ref = refr;

			if (lcontext.IsDynamicExpression)
			{
				throw new DynamicExpressionException("Unsupported symbol reference expression detected.");
			}
		}
開發者ID:eddy5641,項目名稱:LuaSharp,代碼行數:10,代碼來源:SymbolRefExpression.cs

示例9: CheckTokenType

        protected static Token CheckTokenType(ScriptLoadingContext lcontext, TokenType tokenType1, TokenType tokenType2)
        {
            var t = lcontext.Lexer.Current;
            if (t.Type != tokenType1 && t.Type != tokenType2)
                return UnexpectedTokenType(t);

            lcontext.Lexer.Next();

            return t;
        }
開發者ID:eddy5641,項目名稱:moonsharp,代碼行數:10,代碼來源:NodeBase.cs

示例10: StructField

        private void StructField(ScriptLoadingContext lcontext)
        {
            Expression key = new LiteralExpression(lcontext, DynValue.NewString(lcontext.Lexer.Current.Text));
            lcontext.Lexer.Next();

            CheckTokenType(lcontext, TokenType.Op_Assignment);

            var value = Expr(lcontext);

            m_CtorArgs.Add(new KeyValuePair<Expression, Expression>(key, value));
        }
開發者ID:eddy5641,項目名稱:moonsharp,代碼行數:11,代碼來源:TableConstructor.cs

示例11: LabelStatement

		public LabelStatement(ScriptLoadingContext lcontext)
			: base(lcontext)
		{
			CheckTokenType(lcontext, TokenType.DoubleColon);
			NameToken = CheckTokenType(lcontext, TokenType.Name);
			CheckTokenType(lcontext, TokenType.DoubleColon);

			SourceRef = NameToken.GetSourceRef();
			Label = NameToken.Text;

			lcontext.Scope.DefineLabel(this);
		}
開發者ID:eddy5641,項目名稱:LuaSharp,代碼行數:12,代碼來源:LabelStatement.cs

示例12: GotoStatement

        public GotoStatement(ScriptLoadingContext lcontext)
            : base(lcontext)
        {
            GotoToken = CheckTokenType(lcontext, TokenType.Goto);
            var name = CheckTokenType(lcontext, TokenType.Name);

            SourceRef = GotoToken.GetSourceRef(name);

            Label = name.Text;

            lcontext.Scope.RegisterGoto(this);
        }
開發者ID:eddy5641,項目名稱:moonsharp,代碼行數:12,代碼來源:GotoStatement.cs

示例13: CreateStatement

		protected static Statement CreateStatement(ScriptLoadingContext lcontext, out bool forceLast)
		{
			Token tkn = lcontext.Lexer.Current;

			forceLast = false;

			switch (tkn.Type)
			{
				case TokenType.DoubleColon:
					return new LabelStatement(lcontext);
				case TokenType.Goto:
					return new GotoStatement(lcontext);
				case TokenType.SemiColon:
					lcontext.Lexer.Next();
					return new EmptyStatement(lcontext);
				case TokenType.If:
					return new IfStatement(lcontext);
				case TokenType.While:
					return new WhileStatement(lcontext);
				case TokenType.Do:
					return new ScopeBlockStatement(lcontext);
				case TokenType.For:
					return DispatchForLoopStatement(lcontext);
				case TokenType.Repeat:
					return new RepeatStatement(lcontext);
				case TokenType.Function:
					return new FunctionDefinitionStatement(lcontext, false, null);
				case TokenType.Local:
					Token localToken = lcontext.Lexer.Current;
					lcontext.Lexer.Next();
					if (lcontext.Lexer.Current.Type == TokenType.Function)
						return new FunctionDefinitionStatement(lcontext, true, localToken);
					else
						return new AssignmentStatement(lcontext, localToken);
				case TokenType.Return:
					forceLast = true;
					return new ReturnStatement(lcontext);
				case TokenType.Break:
					return new BreakStatement(lcontext);
				default:
					{
						Token l = lcontext.Lexer.Current;
						Expression exp = Expression.PrimaryExp(lcontext);
						FunctionCallExpression fnexp = exp as FunctionCallExpression;

						if (fnexp != null)
							return new FunctionCallStatement(lcontext, fnexp);
						else
							return new AssignmentStatement(lcontext, exp, l);
					}
			}
		}
開發者ID:eddy5641,項目名稱:LuaSharp,代碼行數:52,代碼來源:Statement.cs

示例14: CreateElseBlock

		IfBlock CreateElseBlock(ScriptLoadingContext lcontext)
		{
			Token type = CheckTokenType(lcontext, TokenType.Else);

			lcontext.Scope.PushBlock();

			var ifblock = new IfBlock();
			ifblock.Block = new CompositeStatement(lcontext);
			ifblock.StackFrame = lcontext.Scope.PopBlock();
			ifblock.Source = type.GetSourceRef();
			lcontext.Source.Refs.Add(ifblock.Source);
			return ifblock;
		}
開發者ID:cyecp,項目名稱:moonsharp,代碼行數:13,代碼來源:IfStatement.cs

示例15: FunctionCallExpression

		public FunctionCallExpression(ScriptLoadingContext lcontext, Expression function, Token thisCallName)
			: base(lcontext)
		{
			Token callToken = thisCallName ?? lcontext.Lexer.Current;

			m_Name = thisCallName != null ? thisCallName.Text : null;
			m_DebugErr = function.GetFriendlyDebugName();
			m_Function = function;

			switch (lcontext.Lexer.Current.Type)
			{
				case TokenType.Brk_Open_Round:
					Token openBrk = lcontext.Lexer.Current;
					lcontext.Lexer.Next();
					Token t = lcontext.Lexer.Current;
					if (t.Type == TokenType.Brk_Close_Round)
					{
						m_Arguments = new List<Expression>();
						SourceRef = callToken.GetSourceRef(t);
						lcontext.Lexer.Next();
					}
					else
					{
						m_Arguments = ExprList(lcontext);
						SourceRef = callToken.GetSourceRef(CheckMatch(lcontext, openBrk, TokenType.Brk_Close_Round, ")"));
					}
					break;
				case TokenType.String:
				case TokenType.String_Long:
					{
						m_Arguments = new List<Expression>();
						Expression le = new LiteralExpression(lcontext, lcontext.Lexer.Current);
						m_Arguments.Add(le);
						SourceRef = callToken.GetSourceRef(lcontext.Lexer.Current);
					}
					break;
				case TokenType.Brk_Open_Curly:
				case TokenType.Brk_Open_Curly_Shared:
					{
						m_Arguments = new List<Expression>();
						m_Arguments.Add(new TableConstructor(lcontext, lcontext.Lexer.Current.Type == TokenType.Brk_Open_Curly_Shared));
						SourceRef = callToken.GetSourceRefUpTo(lcontext.Lexer.Current);
					}
					break;
				default:
					throw new SyntaxErrorException(lcontext.Lexer.Current, "function arguments expected")
					{
						IsPrematureStreamTermination = (lcontext.Lexer.Current.Type == TokenType.Eof)
					};
			}
		}
開發者ID:eddy5641,項目名稱:LuaSharp,代碼行數:51,代碼來源:FunctionCallExpression.cs


注:本文中的MoonSharp.Interpreter.Execution.ScriptLoadingContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。