Example #1
0
 void AddWSToken(Token t)
 {
     if (SaveComments)
     {
         if (t.Type() == TokenType.Newline && _triviaList[_triviaList.Count - 1, default(Token)].Kind == TokenKind.Other)
         {
             return;                     // Ignore newline at end of PP token
         }
         _triviaList.Add(t);
     }
 }
Example #2
0
        public void DListAddTest()
        {
            DList <int> list = new DList <int>();

            Assert.IsNotNull(list);
            Assert.AreEqual(0, list.Count);
            list.Add(100);
            Assert.AreEqual(1, list.Count);
            for (int i = 0; i < 10000; ++i)
            {
                list.Add(i);
            }
            Assert.AreEqual(10001, list.Count);
        }
Example #3
0
        /// <summary>
        /// Создает Def цепочку для базового блока
        /// </summary>
        private void BuildDList()
        {
            var code = Block.CodeList;

            // Цикл по всем командам блока
            foreach (var command in code)
            {
                if (command is Assign)
                {
                    var comA = command as Assign;

                    // Добавление Use узлов
                    AddUseVariable(comA.Left, comA.Label);
                    AddUseVariable(comA.Right, comA.Label);

                    // Добавление нового Def узла
                    DList.Add(new DNode(comA.Result, comA.Label));
                }
                else if (command is IfGoto)
                {
                    var comIG = command as IfGoto;
                    AddUseVariable(comIG.Condition, comIG.Label);
                }
                else if (command is Print)
                {
                    var comP = command as Print;
                    AddUseVariable(comP.Data, comP.Label);
                }
            }
        }
Example #4
0
        private void TestLes(string input, string expectOutput, int expectMessages = 0, Severity expectSev = 0)
        {
            using (G.PushTLV(Token.ToStringStrategyTLV, TokenExt.ToString))
            {
                MessageHolder errorList;
                var           input2 = StripInitialNewline(input);
                var           lexer  = new LesLexer(input2, errorList = new MessageHolder());
                var           wrapr  = new LesIndentTokenGenerator(lexer);
                var           output = new DList <Token>();
                for (var t = wrapr.NextToken(); t.HasValue; t = wrapr.NextToken())
                {
                    output.Add(t.Value);
                }
                var expectTokens = new LesLexer(expectOutput, MessageSink.Console).Buffered().Select(t =>
                                                                                                     t.Type() == TokenType.LBrack ? t.WithType((int)TokenType.Indent) :
                                                                                                     t.Type() == TokenType.RBrack ? t.WithType((int)TokenType.Dedent) : t).ToList();

                AreEqual(expectMessages, errorList.List.Count);
                if (expectMessages > 0)
                {
                    AreEqual(expectSev, errorList.List.Max(m => m.Severity));
                }
                ExpectList(output, expectTokens, false);
            }
        }
Example #5
0
        private void Test(string input, string expectOutput, int expectMessages = 0, Severity expectSev = 0)
        {
            // Install token-to-string stategy to aid debugging
            using (G.PushTLV(Token.ToStringStrategyTLV, t => (t.Value ?? ((CalcTokenType)t.TypeInt).ToString()).ToString())) {
                MessageHolder errorList;
                var           input2 = StripInitialNewline(input);
                var           lexer  = new CalculatorLexer(input2)
                {
                    ErrorSink = errorList = new MessageHolder()
                };
                var wrapr = new IndentTokenGenerator(lexer, allIndTrig, new Token((int)CalcTokenType.Semicolon, 0, 0, null))
                {
                    EolIndentTriggers = eolIndTrig,
                    IndentToken       = new Token((int)CalcTokenType.LBrace, 0, 0, null),
                    DedentToken       = new Token((int)CalcTokenType.RBrace, 0, 0, null),
                };
                var output = new DList <Token>();
                for (var t = wrapr.NextToken(); t.HasValue; t = wrapr.NextToken())
                {
                    output.Add(t.Value);
                }
                var expectTokens = new CalculatorLexer(expectOutput).Buffered().ToList();

                AreEqual(expectMessages, errorList.List.Count);
                if (expectMessages > 0)
                {
                    AreEqual(expectSev, errorList.List.Max(m => m.Severity));
                }
                ExpectList(output, expectTokens, false);
            }
        }
Example #6
0
        public void Add()
        {
            var list1 = new DList <DObject>();

            list1.Add(new { value = "1" });

            list1.Single().GetString("value").ShouldBe("1");

            Should.Throw <InvalidCastException>(() => list1.Add(2));

            var list2 = new DList <int>();

            list2.Add(1);

            list2.Single().ShouldBe(1);

            Should.Throw <InvalidCastException>(() => list2.Add(new { value = "2" }));
        }
Example #7
0
 static bool AddIfFarEnough(DList <DragPoint> points, DragPoint dp)
 {
     if (points.Count == 0 || points.Last.Point.Sub(dp.Point).Quadrance() >= MathEx.Square(MinDistBetweenDragPoints))
     {
         points.Add(dp);
         return(true);
     }
     return(false);
 }
Example #8
0
 void OnDisable()
 {
     //Dbg.Log("EData.OnDisable: m_dict: {0}", m_dict.Count);
     m_data.Clear();
     foreach (var pr in m_dict)
     {
         string   id   = pr.Key;
         EDataObj data = pr.Value;
         m_data.Add(new DPair(id, data));
     }
 }
Example #9
0
 internal static void Flatten(DList <Token> input, DList <Token> output, ref bool hasChildren)
 {
     foreach (var token in input)
     {
         output.Add(token);
         var c = token.Children;
         if (c != null && c.Count != 0)
         {
             hasChildren = true;
             Flatten(c, output, ref hasChildren);
         }
     }
 }
Example #10
0
    private void InitDefaultGeneralsInfo()
    {
        int[] skillids = new int[] { 1001, 1002, 1003, 1004, 1201, 1202, 1203 };

        int sid = 0;

        foreach (var genData in GameData.GeneralData.dataMap)
        {
            int         gIdx = genData.Key;
            GeneralInfo info = new GeneralInfo();

            info.id = gIdx;


            //info.level = UnityEngine.Random.Range(1, GeneralInfo.LEVEL_LIMIT + 1);
            info.healthCur = info.propData.hp;
            generals.Add(info);

            foreach (int skid in skillids)
            {
                SkillStateData data = new SkillStateData();
                data.skillID = skid;
                //data.state = (SkillState)(UnityEngine.Random.Range(0, (int)SkillState.Count));
                info.skills.Add(data);
            }

            if (info.gamedata.adviser && mine.advisers.Count < GeneralInfo.ASVISER_COUNT_LIMIT)
            {
                mine.advisers.Add(info.id);
            }

            uint[] equiplist = new uint[1115 - 1109 + 1] {
                1109, 1110, 1111, 1112, 1113, 1114, 1115
            };
            List <uint> elist = new List <uint>();
            elist.AddRange(equiplist);
            for (int i = 0; i < GeneralInfo.EQUIP_COUNT_LIMIT; ++i)
            {
                t_ObjectProto equip = new t_ObjectProto();
                equip.lv = 1;
                //int idex = UnityEngine.Random.Range(0, elist.Count);
                //equip.dwObjectID = equiplist[idex];
                //elist.Remove(equip.dwObjectID);
                //info.equips[i] = equip;
            }

            sid += GeneralInfo.SOLDIER_LIMIT;
        }
    }
Example #11
0
        public static DList <Token> ToNormalTokens(SparseAList <EditorToken> eTokens)
        {
            var output = new DList <Token>();
            int?index  = null;

            for (;;)
            {
                EditorToken eTok = eTokens.NextHigherItem(ref index);
                if (index == null)
                {
                    break;
                }
                output.Add(eTok.ToToken(index.Value));
            }
            return(output);
        }
Example #12
0
        public override Maybe <Token> NextToken()
        {
            do
            {
                Maybe <Token> t_ = Lexer.NextToken();
redo:
                if (!t_.HasValue)
                {
                    break;
                }
                var t = t_.Value;
                if (t.IsWhitespace)
                {
                    if (SaveComments)
                    {
                        _triviaList.Add(t);
                    }
                    continue;
                }
                else if (t.Kind == TokenKind.Other)
                {
                    switch (t.Type())
                    {
                    case TokenType.PPdefine:
                    case TokenType.PPundef:
                        ReadRest(_rest);
                        bool undef = t.Type() == TokenType.PPundef;
                        if (_rest.Count == 1 && _rest[0].Type() == TokenType.Id)
                        {
                            if (undef)
                            {
                                DefinedSymbols.Remove((Symbol)_rest[0].Value);
                            }
                            else
                            {
                                DefinedSymbols.Add((Symbol)_rest[0].Value);
                            }
                        }
                        else
                        {
                            ErrorSink.Error(t.Range(SourceFile), "'{0}' should be followed by a single, simple identifier", undef ? "#undef" : "#define");
                        }
                        continue;

                    case TokenType.PPif:
                        var   tree = ReadRestAsTokenTree();
                        LNode expr = ParseExpr(tree);

                        var cond = Evaluate(expr) ?? false;
                        _ifRegions.Push(Pair.Create(t, cond));
                        t_ = SaveDirectiveAndAutoSkip(t, cond);
                        goto redo;

                    case TokenType.PPelse:
                    case TokenType.PPelif:
                        var tree_ = ReadRestAsTokenTree();

                        if (_ifRegions.Count == 0)
                        {
                            ErrorSink.Error(t.Range(SourceFile),
                                            "Missing #if clause before '{0}'", t);
                            _ifRegions.Push(Pair.Create(t, false));
                        }
                        bool isElif = t.Type() == TokenType.PPelif, hasExpr = tree_.TryGet(0).HasValue;
                        if (hasExpr != isElif)
                        {
                            Error(t, isElif ? "Missing condition on #elif" : "Unexpected tokens after #else");
                        }
                        bool cond_ = true;
                        if (hasExpr)
                        {
                            LNode expr_ = ParseExpr(tree_);
                            cond_ = Evaluate(expr_) ?? false;
                        }
                        if (_ifRegions.Peek().B)
                        {
                            cond_ = false;
                        }
                        t_ = SaveDirectiveAndAutoSkip(t, cond_);
                        if (cond_)
                        {
                            _ifRegions.Push(Pair.Create(_ifRegions.Pop().A, cond_));
                        }
                        goto redo;

                    case TokenType.PPendif:
                        var tree__ = ReadRestAsTokenTree();
                        if (_ifRegions.Count == 0)
                        {
                            Error(t, "Missing #if before #endif");
                        }
                        else
                        {
                            _ifRegions.Pop();
                            if (tree__.Count > 0)
                            {
                                Error(t, "Unexpected tokens after #endif");
                            }
                        }
                        _triviaList.Add(t);
                        continue;

                    case TokenType.PPerror:
                        _triviaList.Add(t);
                        Error(t, t.Value.ToString());
                        continue;

                    case TokenType.PPwarning:
                        _triviaList.Add(t);
                        ErrorSink.Warning(t.Range(SourceFile), t.Value.ToString());
                        continue;

                    case TokenType.PPregion:
                        _triviaList.Add(t);
                        _regions.Push(t);
                        continue;

                    case TokenType.PPendregion:
                        _triviaList.Add(t);
                        if (_regions.Count == 0)
                        {
                            ErrorSink.Warning(t.Range(SourceFile), "#endregion without matching #region");
                        }
                        else
                        {
                            _regions.Pop();
                        }
                        continue;

                    case TokenType.PPline:
                        _triviaList.Add(new Token(t.TypeInt, t.StartIndex, Lexer.InputPosition));
                        var rest = ReadRestAsTokenTree();
                        // TODO: use LineRemapper
                        ErrorSink.Write(Severity.Note, t.Range(SourceFile), "Support for #line is not implemented");
                        continue;

                    case TokenType.PPpragma:
                        _triviaList.Add(new Token(t.TypeInt, t.StartIndex, Lexer.InputPosition));
                        var rest_ = ReadRestAsTokenTree();
                        // TODO
                        ErrorSink.Write(Severity.Note, t.Range(SourceFile), "Support for #pragma is not implemented");
                        continue;
                    }
                }
                return(t_);
            } while (true);
            // end of stream
            if (_ifRegions.Count > 0)
            {
                ErrorSink.Error(_ifRegions.Peek().A.Range(SourceFile), "#if without matching #endif");
            }
            if (_regions.Count > 0)
            {
                ErrorSink.Warning(_regions.Peek().Range(SourceFile), "#region without matching #endregion");
            }
            return(Maybe <Token> .NoValue);
        }
		private void TestLes(string input, string expectOutput, int expectMessages = 0, Severity expectSev = 0)
		{
			using (G.PushTLV(Token.ToStringStrategyTLV, TokenExt.ToString))
			{
				MessageHolder errorList;
				var input2 = StripInitialNewline(input);
				var lexer = new LesLexer(input2, errorList = new MessageHolder());
				var wrapr = new LesIndentTokenGenerator(lexer);
				var output = new DList<Token>();
				for (var t = wrapr.NextToken(); t.HasValue; t = wrapr.NextToken())
					output.Add(t.Value);
				var expectTokens = new LesLexer(expectOutput, MessageSink.Console).Buffered().Select(t =>
					t.Type() == TokenType.LBrack ? t.WithType((int)TokenType.Indent) :
					t.Type() == TokenType.RBrack ? t.WithType((int)TokenType.Dedent) : t).ToList();

				AreEqual(expectMessages, errorList.List.Count);
				if (expectMessages > 0)
					AreEqual(expectSev, errorList.List.Max(m => m.Severity));
				ExpectList(output, expectTokens, false);
			}
		}
		private void Test(string input, string expectOutput, int expectMessages = 0, Severity expectSev = 0)
		{
			// Install token-to-string stategy to aid debugging
			using (G.PushTLV(Token.ToStringStrategyTLV, t => (t.Value ?? ((CalcTokenType)t.TypeInt).ToString()).ToString())) {
				MessageHolder errorList;
				var input2 = StripInitialNewline(input);
				var lexer = new CalculatorLexer(input2) { ErrorSink = errorList = new MessageHolder() };
				var wrapr = new IndentTokenGenerator(lexer, allIndTrig, new Token((int)CalcTokenType.Semicolon, 0, 0, null)) {
					EolIndentTriggers = eolIndTrig, 
					IndentToken = new Token((int)CalcTokenType.LBrace, 0, 0, null),
					DedentToken = new Token((int)CalcTokenType.RBrace, 0, 0, null),
				};
				var output = new DList<Token>();
				for (var t = wrapr.NextToken(); t.HasValue; t = wrapr.NextToken())
					output.Add(t.Value);
				var expectTokens = new CalculatorLexer(expectOutput).Buffered().ToList();
				
				AreEqual(expectMessages, errorList.List.Count);
				if (expectMessages > 0)
					AreEqual(expectSev, errorList.List.Max(m => m.Severity));
				ExpectList(output, expectTokens, false);
			}
		}
Example #15
0
		public static DList<Token> ToNormalTokens(SparseAList<EditorToken> eTokens)
		{
			var output = new DList<Token>();
			int? index = null;
			for (;;) {
				EditorToken eTok = eTokens.NextHigherItem(ref index);
				if (index == null) break;
				output.Add(eTok.ToToken(index.Value));
			}
			return output;
		}
Example #16
0
            void ScanTree(PredictionTree tree, Alts alts, DList <Prematched> path)
            {
                int oldCount = path.Count;

                while (path.Count <= tree.Lookahead)
                {
                    path.Add(new Prematched {
                        Terminals = Anything
                    });
                }
                Prematched pm = path.Last;

                if (tree.IsAssertionLevel)
                {
                    foreach (PredictionBranch b in tree.Children)
                    {
                        var old      = pm.AndPreds.Clone();
                        var verified = Enumerable.Aggregate(b.AndPreds, (set1, set2) => (set1.Union(set2)));                         // usually empty if more than one
                        pm.AndPreds.UnionWith(verified);

                        if (b.Sub.Tree != null)
                        {
                            ScanTree(b.Sub.Tree, alts, path);
                        }
                        else
                        {
                            Debug.Assert(b.Sub.Alt != ErrorAlt);
                            if (b.Sub.Alt == ExitAlt)
                            {
                                _apply.ApplyPrematchData(alts.Next, path);
                            }
                            else
                            {
                                _apply.ApplyPrematchData(alts.Arms[b.Sub.Alt], path);
                            }
                        }
                        pm.AndPreds = old;
                    }
                }
                else                 // !IsAssertionLevel (terminal-matching level)
                {
                    bool needErrorBranch = LLPG.NeedsErrorBranch(tree, alts);

                    for (int i = 0; i < tree.Children.Count; i++)
                    {
                        PredictionBranch b   = tree.Children[i];
                        IPGTerminalSet   set = b.Set;
                        if (!needErrorBranch && i + 1 == tree.Children.Count)
                        {
                            // Add all the default cases
                            set = set.Union(tree.TotalCoverage.Inverted());
                        }
                        pm.Terminals = set;
                        if (b.Sub.Tree != null)
                        {
                            ScanTree(b.Sub.Tree, alts, path);
                        }
                        else
                        {
                            if (b.Sub.Alt == ExitAlt)
                            {
                                _apply.ApplyPrematchData(alts.Next, path);
                            }
                            else if (b.Sub.Alt != ErrorAlt)
                            {
                                _apply.ApplyPrematchData(alts.Arms[b.Sub.Alt], path);
                            }
                        }
                    }
                    path.PopLast();
                }
                path.Resize(oldCount);
            }
Example #17
0
			void ScanTree(PredictionTree tree, Alts alts, DList<Prematched> path)
			{
				int oldCount = path.Count;
				while (path.Count <= tree.Lookahead)
					path.Add(new Prematched { Terminals = Anything });
				Prematched pm = path.Last;

				if (tree.IsAssertionLevel)
				{
					foreach (PredictionBranch b in tree.Children)
					{
						var old = pm.AndPreds.Clone();
						var verified = Enumerable.Aggregate(b.AndPreds, (set1, set2) => (set1.Union(set2))); // usually empty if more than one
						pm.AndPreds.UnionWith(verified);

						if (b.Sub.Tree != null) {
							ScanTree(b.Sub.Tree, alts, path);
						} else {
							Debug.Assert(b.Sub.Alt != ErrorAlt);
							if (b.Sub.Alt == ExitAlt)
								_apply.ApplyPrematchData(alts.Next, path);
							else
								_apply.ApplyPrematchData(alts.Arms[b.Sub.Alt], path);
						}
						pm.AndPreds = old;
					}
				}
				else // !IsAssertionLevel (terminal-matching level)
				{
					bool needErrorBranch = LLPG.NeedsErrorBranch(tree, alts);

					for (int i = 0; i < tree.Children.Count; i++) {
						PredictionBranch b = tree.Children[i];
						IPGTerminalSet set = b.Set;
						if (!needErrorBranch && i + 1 == tree.Children.Count)
							// Add all the default cases
							set = set.Union(tree.TotalCoverage.Inverted());
						pm.Terminals = set;
						if (b.Sub.Tree != null) {
							ScanTree(b.Sub.Tree, alts, path);
						} else {
							if (b.Sub.Alt == ExitAlt)
								_apply.ApplyPrematchData(alts.Next, path);
							else if (b.Sub.Alt != ErrorAlt)
								_apply.ApplyPrematchData(alts.Arms[b.Sub.Alt], path);
						}
					}
					path.PopLast();
				}
				path.Resize(oldCount);
			}
Example #18
0
        public override void HoldStyle(Player player)
        {
            //int dust3 = Dust.NewDust(player.Top+new Vector2(player.direction*-10, 0), 0, 0, 87, 0f, 0f, 25, Color.Goldenrod, 1.5f);
            //Main.dust[dust3].noGravity = true;
            //Main.dust[dust3].velocity = new Vector2(0, 0);
            reloading = Math.Max(reloading, 0);
            //altfire = Math.Min(altfire, reloadspeed-1);
            if (reloading > 0)
            {
                reloading           = reloading = Math.Max(reloading + (reloadspeed - (altfire)), 0);
                player.itemRotation = (reloading / 7.5f) * -player.direction;
                item.holdStyle      = 1;
                int d = Dust.NewDust(player.itemLocation, 1, 1, 159, 0, 0, 0, Color.Goldenrod, 0.5f);
                Main.dust[d].noGravity = true;
                /*item.Center*/ player.itemLocation = ((player.direction > 0?player.Right:player.Left) - new Vector2(16, 8)) - (new Vector2(24, 2).RotatedBy(player.itemRotation) * player.direction);     //player.itemLocation-new Vector2(player.direction>0?16:0,0);
                if (RoundsLeft > 0 && -Math.Abs(player.itemRotation) % 1 <= 0.2f)
                {
                    //int a = (int)(item.damage*1.5f);
                    //GetWeaponDamage(player, ref a);

                    int b = Projectile.NewProjectile(player.itemLocation, new Vector2(4).RotatedBy(player.itemRotation), bullets[0].id == 14?160:bullets[0].id, player.GetWeaponDamage(item), item.knockBack, item.owner);                  //8,
                    if (bullets[0].id != 14)
                    {
                        Main.projectile[b].GetGlobalProjectile <ElementalGlobalProjectile>().extraAI = 8;
                    }
                    if (bullets[0].id == 14)
                    {
                        Main.projectile[b].aiStyle = 8;
                    }
                    RoundsLeft--;
                    if (bullets.Count > 0)
                    {
                        //if(bullets[0].id!=14)Main.projectile[b].aiStyle = bullets[0].id;
                        bullets.RemoveAt(0);
                    }
                }
            }
            if (reloading >= 100)
            {
                item.useAmmo = AmmoID.Bullet;
                for (int i = 0; i < RoundsMax; i++)
                {
                    bool            canShoot = false;
                    ProjectileStats p        = new ProjectileStats();
                    player.PickAmmo(item, ref p.id, ref p.speed, ref canShoot, ref p.damage, ref p.knockback);
                    if (canShoot)
                    {
                        bullets.Add(p);
                        RoundsLeft++;
                    }
                    else
                    {
                        break;
                    }
                    //RoundsLeft = RoundsMax;
                }
                item.useAmmo   = 0;
                reloading      = 0;
                item.holdStyle = 0;
                altfire        = 0;
            }
        }