Esempio n. 1
0
        public FactorNode Factor()
        {
            var factor = new FactorNode();

            if (token.value == "not")
            {
                factor.not = true;
                Match(TokenTypes.ID, "not");
            }
            if (token.type == TokenTypes.ID)
            {
                factor.value = token.value;
                factor.type  = TokenTypes.ID;
                Match(TokenTypes.ID);
                if (token.type == TokenTypes.LPAR)
                {
                    Match(TokenTypes.LPAR);
                    bool end;
                    do
                    {
                        factor.expressionList.Add(Expression());
                        end = token.value == ")";
                        if (!end)
                        {
                            Match(TokenTypes.COMMA);
                        }
                    } while (!end);
                }
                else if (token.type == TokenTypes.LBRACKET)
                {
                    Match(TokenTypes.LBRACKET);
                    factor.arrayExpression = Expression();
                    Match(TokenTypes.RBRACKET);
                }
            }
            else if (token.type == TokenTypes.NUM)
            {
                factor.value = token.value;
                Match(TokenTypes.NUM);
                factor.type = TokenTypes.NUM;
            }
            else if (token.type == TokenTypes.LPAR)
            {
                Match(TokenTypes.LPAR);
                factor.parExpression = Expression();
                Match(TokenTypes.RPAR);
            }

            return(factor);
        }
Esempio n. 2
0
        private string Factor(FactorNode node)
        {
            string output = "";

            //needs to address various froms of NUM
            if (node.type == TokenTypes.ID)
            {
                output += "ldloc." + program.Declarations.variableList.FindIndex(x => node.value == x.variableName) + "\n";
            }
            if (node.type == TokenTypes.NUM)
            {
                output += "ldc.i4." + node.value + "\n";
            }


            if (node.not)
            {
                output += "not\n";
            }
            return(output);
        }