Exemple #1
0
 internal void InitGenerator(Expr expr)
 {
     ProgramDeclBlock pdb = expr as ProgramDeclBlock;
     string name = pdb.FunctionName;
     this.expr = expr;
     Generate(name, "exe");
 }
Exemple #2
0
        /// <summary>
        /// Generates the static main function and parameters.
        /// </summary>
        /// <returns>a type array</returns>
        private Expr GenerateMainMethod(
            TypeBuilder typeBuilder, 
            BlockDeclExpr functionDecl, 
            List<Expr> parameters, 
            Expr mainFunctionParameters,
            out MethodBuilder methodBuilder)
        {
            methodBuilder = null;
            if (parameters != null && parameters.Count == 1)
            {
                mainFunctionParameters = parameters[0];
                Type[] t = GetFunctionParameterTypes(mainFunctionParameters);

                methodBuilder =
                    typeBuilder.DefineMethod(functionDecl.FunctionName,
                                             MethodAttributes.HideBySig |
                                             MethodAttributes.Static |
                                             MethodAttributes.Public, typeof(void),
                                             t);
                //new Type[] { typeof(string[]) });

                // generate the IL for the Main method
                ILGenerator ilGenerator = methodBuilder.GetILGenerator();
                ilGenerator.EmitWriteLine("this is the main method");
                ilGenerator.Emit(OpCodes.Ret);
            }

            return mainFunctionParameters;
        }
Exemple #3
0
        private Type[] GetFunctionParameterTypes(Expr expr)
        {
            if (expr != null)
            {
                if ( expr is ArrayDeclExpr)
                {
                    if ( ((ArrayDeclExpr)expr).TokenType.IdentiferName.Equals("string",StringComparison.OrdinalIgnoreCase))
                    {
                        return new Type[] { typeof(string[]) };
                    }

                    if (((ArrayDeclExpr)expr).TokenType.IdentiferName.Equals("int", StringComparison.OrdinalIgnoreCase))
                    {
                        return new Type[] { typeof(int[]) };
                    }

                    if (((ArrayDeclExpr)expr).TokenType.IdentiferName.Equals("double", StringComparison.OrdinalIgnoreCase))
                    {
                        return new Type[] { typeof(double[]) };
                    }

                    if (((ArrayDeclExpr)expr).TokenType.IdentiferName.Equals("bool", StringComparison.OrdinalIgnoreCase))
                    {
                        return new Type[] { typeof(bool[]) };
                    }

                }
            }

            return null;
        }
Exemple #4
0
        private void WalkTree(Expr boe)
        {
            if (boe != null)
            {
                try
                {
                    var tboe = boe as BinaryOperatorExpression;
                    if (tboe != null)
                    {
                        WalkTree(((BinaryOperatorExpression)boe).Left);
                        Console.WriteLine(((BinaryOperatorExpression)boe).Operation.GetToken().IdentiferName);
                        WalkTree(((BinaryOperatorExpression)boe).Right);
                    }

                    var ie = boe as IdentifierExpression;
                    if (ie != null)
                    {
                        Console.WriteLine(boe.GetToken().IdentiferName);
                    }

                    var fce = boe as FunctionCallExpression;
                    if (fce != null)
                    {
                        Console.WriteLine(fce.FunctionName);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
        public void AddStatment(Expr expr)
        {
            if (this.statementList == null)
            {
                this.statementList = new List<Expr>();
            }

            this.statementList.Add(expr);
        }
Exemple #6
0
 private void ParseIntDeclaration(out Expr expr)
 {
     expr = null;
 }
Exemple #7
0
 private void ParseStringDeclartion(out Expr expr)
 {
     Token tokenType = _scanner.GetToken();
     expr = ArrayDeclaration(tokenType);
 }
Exemple #8
0
 private void ParseFloatDeclartion(out Expr expr)
 {
     expr = null;
 }
Exemple #9
0
        /// <summary>
        /// Parse the signature of the function
        /// </summary>
        private void ParseFunctionSignature(
            Expr parentNode,
            Token functionName)
        {
            List<Expr> pll = null;
            functionName.Kind = ByteCodeIdentifiers.TokenCode.Function;

            Token paren = _scanner.GetToken();

            /*
            * If there are parameters
            * add them to the parameter list
            */
            if (paren.Value.Equals(constants.LEFTPAREN))
            {
                pll = ParseFunctionParameters();
            }

            if (pll != null && pll.Count > 0)
            {
                var progExpression = parentNode as BlockDeclExpr;
                if (progExpression != null)
                {
                    progExpression.Parameters = pll;
                }

                if (functionName.IdentiferName.Equals(constants.MAIN, StringComparison.OrdinalIgnoreCase))
                {
                    _isMain = true;
                    progExpression.IsMain = true;
                }
            }
        }
Exemple #10
0
 private void ParseBoolDeclartion(out Expr expr)
 {
     expr = null;
 }
Exemple #11
0
 private void AddStatementExpressionTreesToFunctionBlock(Expr bin)
 {
     var scopeExpr = _expressionScopeStack.Peek() as FunctionDeclBlock;
     if (scopeExpr != null)
     {
         scopeExpr.AddStatment(bin);
     }
 }
Exemple #12
0
 internal AssignmentExpr(OperatorExpression operation,
     Expr left,
     Expr right)
     : base(operation, left, right)
 {
 }
Exemple #13
0
 internal ArithmeticBinaryExpr(OperatorExpression operation,
     Expr left,
     Expr right)
     : base(operation, left, right)
 {
 }
Exemple #14
0
 internal BinaryOperatorExpression(
     OperatorExpression operation,
     Expr left,
     Expr right)
     : this()
 {
     this.left = left;
     this.right = right;
     this.operation = operation;
 }