Esempio n. 1
0
        public static DatSymbol BuildArrOfVariables(string name, DatSymbolType type, uint size,
                                                    DatSymbolLocation location = null)
        {
            object[] content = new object[size];
            for (int i = 0; i < content.Length; ++i)
            {
                switch (type)
                {
                case DatSymbolType.Int:
                    content[i] = 0;
                    break;

                case DatSymbolType.Float:
                    content[i] = 0.0;
                    break;

                case DatSymbolType.String:
                    content[i] = string.Empty;      // TODO shouldn't it be string in some kind of Gothic's format?
                    break;
                }
            }


            var symbol = new DatSymbol
            {
                Name        = name,
                Type        = type,
                ArrayLength = size,
                Content     = content,
                Flags       = 0,
                Location    = location,
                ParentIndex = -1,
            };

            return(symbol);
        }
Esempio n. 2
0
        public static ParamLessInstruction GetInstructionForOperator(
            string operatorVal,
            bool twoArg = true,
            DatSymbolType leftSideType = DatSymbolType.Void)
        {
            ParamLessInstruction instruction = new ParamLessInstruction();

            switch (operatorVal)
            {
            case "=":
                instruction = GetAssignInstructionForDatSymbolType(leftSideType);
                break;

            case "+=":
                instruction = new AssignAdd();
                break;

            case "-=":
                instruction = new AssignSubtract();
                break;

            case "*=":
                instruction = new AssignMultiply();
                break;

            case "/=":
                instruction = new AssignDivide();
                break;


            case "+":
                if (twoArg)
                {
                    instruction = new Add();
                }
                else
                {
                    instruction = new Plus();
                }

                break;

            case "-":
                if (twoArg)
                {
                    instruction = new Subtract();
                }
                else
                {
                    instruction = new Minus();
                }

                break;


            case "<<":
                instruction = new ShiftLeft();
                break;

            case ">>":
                instruction = new ShiftRight();
                break;


            case ">":
                instruction = new Greater();
                break;

            case ">=":
                instruction = new GreaterOrEqual();
                break;

            case "<":
                instruction = new Less();
                break;

            case "<=":
                instruction = new LessOrEqual();
                break;


            case "==":
                instruction = new Equal();
                break;

            case "!=":
                instruction = new NotEqual();
                break;


            case "!":
                instruction = new Not();
                break;

            case "~":
                instruction = new Negate();
                break;


            case "*":
                instruction = new Multiply();
                break;

            case "/":
                instruction = new Divide();
                break;

            case "%":
                instruction = new Modulo();
                break;


            case "&":
                instruction = new BitAnd();
                break;

            case "|":
                instruction = new BitOr();
                break;

            case "&&":
                instruction = new LogAnd();
                break;

            case "||":
                instruction = new LogOr();
                break;
            }

            if (instruction == null)
            {
                throw new Exception($"'{operatorVal}' does't have insctruction");
            }

            return(instruction);
        }
Esempio n. 3
0
 public static DatSymbol BuildParameter(string name, DatSymbolType type, DatSymbolLocation location = null,
                                        int parentIndex = -1)
 {
     return(BuildVariable(name, type, location, parentIndex));
 }