Beispiel #1
0
        //TODO TESTS
        private static void Command(ListController <TokenModel> lc)
        {
            var beg = lc.GetNext();

            if (TypesTools.IsType(beg.Text))
            {
                lc.SetBack();
                Initialization(lc);
            }
            else if (VarTable.Contains(beg.Text))
            {
                lc.SetBack();
                var node = VariableAssign(lc);
                Commands.Add(node);
            }
            else if (FuncTable.Contains(beg.Text))
            {
                lc.SetBack();
                var node = FuncExecute(lc);
                Commands.Add(node);
            }
            else
            {
                throw new ParseException($"Cannot resolve '{beg.Text}'", beg);
            }

            //todo lately var = Arithmetic Expression
            //todo more lately type func
        }
Beispiel #2
0
        //TODO TESTS
        private static void Initialization(ListController <TokenModel> lc)
        {
            var type = lc.GetNext();
            var name = TryGetNext(lc, "Variable name expected");

            if (!Constants.Alphabet.Contains(name.Text[0]))
            {
                throw new ParseException("Unexpected token", name);
            }

            if (VarTable.Contains(name.Text) || FuncTable.Contains(name.Text))
            {
                throw new ParseException("Member with the same name is already declared", name);
            }

            VarTable.Add(name.Text, type.Text);
        }
Beispiel #3
0
        //TODO TESTS
        private static AssingNode VariableAssign(ListController <TokenModel> lc)
        {
            var variableToken = lc.GetNext();

            CheckEqual(TryGetNext(lc, "= expected"), "=", "= expected");
            var func     = TryGetNext(lc, "Expression expected");
            var res      = new AssingNode();
            var variable = VarTable.Get(variableToken.Text);

            res.Left = variable;
            if (FuncTable.Contains(func.Text))
            {
                lc.SetBack();
                var fn = FuncExecute(lc);
                res.Right = fn;
            }
            else
            {
                throw new ParseException("Function expected", func);
            }

            return(res);
        }