Exemple #1
0
    private void LocalPermissionCheck(BlockType currentType, BlockType nighbourType, Direction direction, ref NodeBool nodebool)
    {
        var m_localNeighbour = useCase[nighbourType][direction];

        if (m_localNeighbour != null)
        {
            AddRequiredNighbour(currentType, m_localNeighbour);
            nodebool = new NodeBool(true, m_localNeighbour);
        }
    }
Exemple #2
0
    /// <summary>Chechk if on a Nighbour has the required block</summary>
    /// <param name="grid">Grid in use.</param>
    /// <param name="transform">Gizmo </param>
    /// <param name="neighbour">Wich Nighbour from current Node.</param>
    /// <param name="currentType">Wich BlockType is used.</param>
    /// <param name="nighbourType">Target BlockType</param>
    /// <param name="direction">In Wich Direction the Target Block is Facing.</param>
    /// <param name="nodebool">To pass the same reference through diffrent conditions</param>
    private void StaticPermissionCheck(Grid grid, Transform transform, Neighbour neighbour, BlockType currentType, BlockType nighbourType, Direction direction, ref NodeBool nodebool)
    {
        var m_staticNeighbour = staticNeighbour[neighbour];

        if (m_staticNeighbour != null)
        {
            bool m_inUse = m_staticNeighbour.InUse(nighbourType, direction);

            if (m_inUse)
            {
                var m_requiredNeighbour = m_staticNeighbour.useCase[nighbourType][direction];
                AddRequiredNighbour(currentType, m_requiredNeighbour);
                nodebool = new NodeBool(true, m_requiredNeighbour);
            }
        }
    }
Exemple #3
0
 void ASTVisitor.Accept(NodeBool value)
 {
     Accept(value);
 }
Exemple #4
0
 internal void Accept(NodeBool b)
 {
     builder.currentLineNumber = b.EndLine;
     builder.OpBConst(b.value);
 }
Exemple #5
0
    public NodeBool HasNeighbour(Transform transform, Grid grid, BlockType blocktype)
    {
        var m_sameDirection = transform.GetDirection();

        var      m_oppositDirection = transform.GetOppositDirection();
        NodeBool m_validation       = new NodeBool(false, null);

        switch (blocktype)
        {
        case BlockType.Ramp:
            m_validation = new NodeBool(false, null);

            //check for nighbour Ramps
            //                     local grid, gizmo transform, grid neighbour,current BlockType, Neighbour BlockType, Neighbour Direction, ...
            DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Ramp, BlockType.Ramp, m_oppositDirection, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.ForwardUp, BlockType.Ramp, BlockType.Ramp, m_sameDirection, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.Left, BlockType.Ramp, BlockType.Ramp, m_sameDirection, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Right, BlockType.Ramp, BlockType.Ramp, m_sameDirection, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.BackwardDown, BlockType.Ramp, BlockType.Ramp, m_sameDirection, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Ramp, BlockType.Ramp, m_oppositDirection, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.Up, BlockType.Ramp, BlockType.Ramp, m_oppositDirection, ref m_validation);


            //check for Local walls
            LocalPermissionCheck(BlockType.Ramp, BlockType.Wall, Direction.Right, ref m_validation);
            LocalPermissionCheck(BlockType.Ramp, BlockType.Wall, Direction.Left, ref m_validation);
            LocalPermissionCheck(BlockType.Ramp, BlockType.Wall, Direction.Forward, ref m_validation);
            LocalPermissionCheck(BlockType.Ramp, BlockType.Wall, Direction.Backward, ref m_validation);


            //Check for Nighbour Walls
            DynamicPermissionCheck(grid, transform, Neighbour.Left, BlockType.Ramp, BlockType.Wall, Direction.Left, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Left, BlockType.Ramp, BlockType.Wall, Direction.Right, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Left, BlockType.Ramp, BlockType.Wall, Direction.Forward, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Left, BlockType.Ramp, BlockType.Wall, Direction.Backward, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.Right, BlockType.Ramp, BlockType.Wall, Direction.Left, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Right, BlockType.Ramp, BlockType.Wall, Direction.Right, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Right, BlockType.Ramp, BlockType.Wall, Direction.Forward, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Right, BlockType.Ramp, BlockType.Wall, Direction.Backward, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Ramp, BlockType.Wall, Direction.Left, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Ramp, BlockType.Wall, Direction.Right, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Ramp, BlockType.Wall, Direction.Forward, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Ramp, BlockType.Wall, Direction.Backward, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Ramp, BlockType.Wall, Direction.Left, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Ramp, BlockType.Wall, Direction.Right, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Ramp, BlockType.Wall, Direction.Forward, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Ramp, BlockType.Wall, Direction.Backward, ref m_validation);


            //Check for local Floors
            LocalPermissionCheck(BlockType.Ramp, BlockType.Floor, Direction.Down, ref m_validation);
            //LocalPermissionCheck(BlockType.Ramp, BlockType.Floor, Direction.Up, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.ForwardUp, BlockType.Ramp, BlockType.Floor, Direction.Down, ref m_validation);
            //DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Ramp, BlockType.Floor, Direction.Up, ref m_validation);

            //DynamicPermissionCheck(grid, transform, Neighbour.BackwardDown, BlockType.Ramp, BlockType.Floor, Direction.Up, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Ramp, BlockType.Floor, Direction.Down, ref m_validation);

            return(m_validation);

        case BlockType.Floor:
            m_validation = new NodeBool(false, null);



            //check for nighbour floors => down
            StaticPermissionCheck(grid, transform, Neighbour.Left, BlockType.Floor, BlockType.Floor, Direction.Down, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Right, BlockType.Floor, BlockType.Floor, Direction.Down, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Floor, BlockType.Floor, Direction.Down, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Floor, BlockType.Floor, Direction.Down, ref m_validation);

            //Permission through Ramp
            LocalPermissionCheck(BlockType.Floor, BlockType.Ramp, Direction.Left, ref m_validation);
            LocalPermissionCheck(BlockType.Floor, BlockType.Ramp, Direction.Right, ref m_validation);
            LocalPermissionCheck(BlockType.Floor, BlockType.Ramp, Direction.Forward, ref m_validation);
            LocalPermissionCheck(BlockType.Floor, BlockType.Ramp, Direction.Backward, ref m_validation);

            Direction[] rampDir = new Direction[] { Direction.Left, Direction.Right, Direction.Forward, Direction.Backward };

            for (int i = 0; i < rampDir.Length; i++)
            {
                StaticPermissionCheck(grid, transform, Neighbour.Down, BlockType.Floor, BlockType.Ramp, rampDir[i], ref m_validation);
            }
            //Permission thourgh Nighbour Ramp

            StaticPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Floor, BlockType.Ramp, Direction.Forward, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Left, BlockType.Floor, BlockType.Ramp, Direction.Left, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Right, BlockType.Floor, BlockType.Ramp, Direction.Right, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Floor, BlockType.Ramp, Direction.Backward, ref m_validation);

            StaticPermissionCheck(grid, transform, Neighbour.BackwardDown, BlockType.Floor, BlockType.Ramp, Direction.Forward, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.ForwardDown, BlockType.Floor, BlockType.Ramp, Direction.Backward, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.RightDown, BlockType.Floor, BlockType.Ramp, Direction.Left, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.LeftDown, BlockType.Floor, BlockType.Ramp, Direction.Right, ref m_validation);


            //Wall permission Check
            Direction[] wallDir = new Direction[] { Direction.Left, Direction.Right, Direction.Forward, Direction.Backward };

            for (int i = 0; i < wallDir.Length; i++)
            {
                StaticPermissionCheck(grid, transform, Neighbour.Down, BlockType.Floor, BlockType.Wall, wallDir[i], ref m_validation);
                LocalPermissionCheck(BlockType.Floor, BlockType.Wall, wallDir[i], ref m_validation);
            }
            StaticPermissionCheck(grid, transform, Neighbour.Backward, BlockType.Floor, BlockType.Wall, Direction.Forward, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Floor, BlockType.Wall, Direction.Backward, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Right, BlockType.Floor, BlockType.Wall, Direction.Left, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Left, BlockType.Floor, BlockType.Wall, Direction.Right, ref m_validation);

            return(m_validation);

        case BlockType.Wall:

            m_validation = new NodeBool(false, null);


            //Floor check
            LocalPermissionCheck(BlockType.Wall, BlockType.Floor, Direction.Down, ref m_validation);
            StaticPermissionCheck(grid, transform, Neighbour.Up, BlockType.Wall, BlockType.Floor, Direction.Down, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Wall, BlockType.Floor, Direction.Down, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.ForwardUp, BlockType.Wall, BlockType.Floor, Direction.Down, ref m_validation);

            //Ramp Check
            LocalPermissionCheck(BlockType.Wall, BlockType.Ramp, Direction.Left, ref m_validation);
            LocalPermissionCheck(BlockType.Wall, BlockType.Ramp, Direction.Right, ref m_validation);
            LocalPermissionCheck(BlockType.Wall, BlockType.Ramp, Direction.Backward, ref m_validation);
            LocalPermissionCheck(BlockType.Wall, BlockType.Ramp, Direction.Forward, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Wall, BlockType.Ramp, m_oppositDirection, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.Forward, BlockType.Wall, BlockType.Ramp, m_sameDirection, ref m_validation);
            DynamicPermissionCheck(grid, transform, Neighbour.ForwardDown, BlockType.Wall, BlockType.Ramp, m_oppositDirection, ref m_validation);

            DynamicPermissionCheck(grid, transform, Neighbour.Up, BlockType.Wall, BlockType.Ramp, m_oppositDirection, ref m_validation);

            //Wall Check


            if (transform.GetDirection() == Direction.Forward)
            {
                DynamicPermissionCheck(grid, transform, Neighbour.Left, BlockType.Wall, BlockType.Wall, Direction.Forward, ref m_validation);
                DynamicPermissionCheck(grid, transform, Neighbour.Right, BlockType.Wall, BlockType.Wall, Direction.Forward, ref m_validation);
            }
            if (transform.GetDirection() == Direction.Backward)
            {
                DynamicPermissionCheck(grid, transform, Neighbour.Left, BlockType.Wall, BlockType.Wall, Direction.Backward, ref m_validation);
                DynamicPermissionCheck(grid, transform, Neighbour.Right, BlockType.Wall, BlockType.Wall, Direction.Backward, ref m_validation);
            }

            if (transform.GetDirection() == Direction.Left)
            {
                //Debug.Log("Left");
                DynamicPermissionCheck(grid, transform, Neighbour.Left, BlockType.Wall, BlockType.Wall, Direction.Left, ref m_validation);
                DynamicPermissionCheck(grid, transform, Neighbour.Right, BlockType.Wall, BlockType.Wall, Direction.Left, ref m_validation);
            }
            if (transform.GetDirection() == Direction.Right)
            {
                //Debug.Log("Right");
            }
            StaticPermissionCheck(grid, transform, Neighbour.Down, BlockType.Wall, BlockType.Wall, m_sameDirection, ref m_validation);

            return(m_validation);
        }
        Debug.Log("End");
        return(m_validation);
    }
Exemple #6
0
 private Node PrimaryExpression(bool allowPostfixInvocation = true)
 {
     if (!TokensRemain)
         return null;
     var loc = Location;
     Node node;
     switch (Current.type)
     {
         case WILDCARD:
             // If we aren't in a truly anon function, we ignore this
             if (CurrentFunction != null && CurrentFunction.fullAnon && CurrentFunction.paramNames.Count == 0)
                 CurrentFunction.paramNames.Add(null);
             node = new NodeWildcard(loc);
             Advance();
             break;
         case PARAM_INDEX:
             var index = (uint)Current.intValue;
             // If we aren't in a truly anon function, we ignore this
             if (CurrentFunction != null && CurrentFunction.fullAnon)
                 while (CurrentFunction.paramNames.Count <= index)
                     CurrentFunction.paramNames.Add(null);
             node = new NodeParamIndex(loc, index);
             Advance();
             break;
         case IDENTIFIER:
             node = new NodeIdentifier(loc, Current.image);
             Advance();
             break;
         case SYMBOL:
             node = new NodeSymbol(loc, Current.image);
             Advance();
             break;
         case NULL:
             node = new NodeNull(loc);
             Advance();
             break;
         case TRUE:
         case FALSE:
             node = new NodeBool(loc, Check(TRUE));
             Advance();
             break;
         case ENDL:
             node = new NodeEndL(loc);
             Advance();
             break;
         case THIS:
             node = new NodeThis(loc);
             Advance();
             break;
         case SELF:
             node = new NodeSelf(loc);
             Advance();
             break;
         case INT:
             node = new NodeInt(loc, Current.intValue);
             Advance();
             break;
         case FLOAT:
             node = new NodeFloat(loc, Current.floatValue);
             Advance();
             break;
         case STRING:
             node = new NodeString(loc, Current.image);
             Advance();
             break;
         case OPEN_BRACE:
             Advance();
             if (Check(CLOSE_BRACE))
             {
                 // 0-length tuple:
                 node = new NodeTuple(loc, new List<Node>());
                 node.EndLine = Current.location.line;
                 Advance();
             }
             else
             {
                 var values = CommaExpressions();
                 if (values.Count != 1)
                 {
                     // This is a tuple :D
                     node = new NodeTuple(loc, values);
                     Expect(CLOSE_BRACE, "Closing brace (')') expected to end tuple expression.");
                     node.EndLine = tokens[-1].location.line;
                 }
                 else
                 {
                     Expect(CLOSE_BRACE, "Closing brace (')') expected to surround expression.");
                     // Just an expression, carry on:
                     node = values[0];
                 }
             }
             break;
         case OPEN_SQUARE_BRACE:
             // This is a list :D
             Advance();
             node = new NodeList(loc, (TokensRemain && Current.type != CLOSE_SQUARE_BRACE) ? CommaExpressions() : new List<Node>());
             Expect(CLOSE_SQUARE_BRACE, "Closing square brace (']') expected to end list expression.");
             node.EndLine = tokens[-1].location.line;
             break;
         case OPEN_CURLY_BRACE:
             // This is a code block :D
             Advance();
             var exprs = new List<Node>();
             while (!Check(CLOSE_CURLY_BRACE))
             {
                 if (!TokensRemain)
                 {
                     log.Error(tokens[-1].location, "Unfinished block. A closing curly brace ('}') should be used to end blocks.");
                     break;
                 }
                 var expr = Expression();
                 if (expr != null)
                     exprs.Add(expr);
             }
             Expect(CLOSE_CURLY_BRACE, "Closing curly brace ('}') expected to end block.");
             node = new NodeBlock(loc, exprs);
             node.EndLine = tokens[-1].location.line;
             break;
         case TAILREC:
             Advance();
             Expect(OPEN_BRACE, "Expected an open brace ('(') to begin the tailrec argument list.");
             List<Node> args;
             if (!Check(CLOSE_BRACE))
                 args = CommaExpressions();
             else args = new List<Node>();
             Expect(CLOSE_BRACE, "Expected a close brace (')') to end the tailrec argument list.");
             node = new NodeTailRec(loc, args);
             break;
         // These can't be postfix'd, so we don't allow it.
         case OPERATOR:
             var prefix = Current.image;
             Advance();
             if (!TokensRemain)
                 log.Error(loc, "An expression is expected after prefix operator, but the end of the file was reached.");
             var prefixValue = PrimaryExpression();
             return new NodePrefix(loc, prefix, prefixValue);
         case NOT:
             Advance();
             if (!TokensRemain)
                 log.Error(loc, "An expression is expected after the 'not' keyword, but the end of the file was reached.");
             return new NodeNot(loc, Expression());
         case THROW:
             Advance();
             if (!TokensRemain)
                 log.Error(loc, "An expression is expected after the 'throw' keyword, but the end of the file was reached.");
             return new NodeThrow(loc, Expression());
         case YIELD:
             Advance();
             if (!TokensRemain)
                 log.Error(loc, "An expression is expected after the 'yield' keyword, but the end of the file was reached.");
             return new NodeYield(loc, Expression());
         case RES:
             Advance();
             if (!TokensRemain)
                 log.Error(loc, "An expression is expected after the 'res' keyword, but the end of the file was reached.");
             return new NodeRes(loc, Expression());
         case BREAK:
             Advance();
             string bLabel = null;
             if (Check(IDENTIFIER) && Current.location.line == loc.line)
             {
                 bLabel = Current.image;
                 Advance();
             }
             return new NodeBreak(loc, bLabel);
         case CONT:
             Advance();
             string cLabel = null;
             if (Check(IDENTIFIER) && Current.location.line == loc.line)
             {
                 cLabel = Current.image;
                 Advance();
             }
             return new NodeCont(loc, cLabel);
         case FN: return ParseFn();
         case GEN: return ParseFn(true);
         case VAR: return ParseVar();
         case IF: return ParseIf();
         case WHILE: return ParseWhile();
         case TRY: return ParseTry();
         case ITER: return ParseIter();
         case EACH: return ParseEach();
         // And here, we don't know what they want... oops.
         default:
             log.Error(Location, "Unexpected token '{0}', skipping...", Current.ToString());
             // We don't know what to do with this, let's skip and try to recover.
             Advance();
             // Error saying we couldn't understand the token:
             // return a new primary expression.
             return PrimaryExpression();
     }
     // TODO postfix
     return Postfix(node, allowPostfixInvocation);
 }