예제 #1
0
 internal void InitGenerator(Expr expr)
 {
     ProgramDeclBlock pdb = expr as ProgramDeclBlock;
     string name = pdb.FunctionName;
     this.expr = expr;
     Generate(name, "exe");
 }
예제 #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;
        }
예제 #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;
        }
예제 #4
0
파일: Parser.cs 프로젝트: donreamey/vmeex
        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);
                }
            }
        }
예제 #5
0
        public void AddStatment(Expr expr)
        {
            if (this.statementList == null)
            {
                this.statementList = new List<Expr>();
            }

            this.statementList.Add(expr);
        }
예제 #6
0
파일: Parser.cs 프로젝트: donreamey/vmeex
 private void ParseIntDeclaration(out Expr expr)
 {
     expr = null;
 }
예제 #7
0
파일: Parser.cs 프로젝트: donreamey/vmeex
 private void ParseStringDeclartion(out Expr expr)
 {
     Token tokenType = _scanner.GetToken();
     expr = ArrayDeclaration(tokenType);
 }
예제 #8
0
파일: Parser.cs 프로젝트: donreamey/vmeex
 private void ParseFloatDeclartion(out Expr expr)
 {
     expr = null;
 }
예제 #9
0
파일: Parser.cs 프로젝트: donreamey/vmeex
        /// <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;
                }
            }
        }
예제 #10
0
파일: Parser.cs 프로젝트: donreamey/vmeex
 private void ParseBoolDeclartion(out Expr expr)
 {
     expr = null;
 }
예제 #11
0
파일: Parser.cs 프로젝트: donreamey/vmeex
 private void AddStatementExpressionTreesToFunctionBlock(Expr bin)
 {
     var scopeExpr = _expressionScopeStack.Peek() as FunctionDeclBlock;
     if (scopeExpr != null)
     {
         scopeExpr.AddStatment(bin);
     }
 }
예제 #12
0
 internal AssignmentExpr(OperatorExpression operation,
     Expr left,
     Expr right)
     : base(operation, left, right)
 {
 }
예제 #13
0
 internal ArithmeticBinaryExpr(OperatorExpression operation,
     Expr left,
     Expr right)
     : base(operation, left, right)
 {
 }
예제 #14
0
 internal BinaryOperatorExpression(
     OperatorExpression operation,
     Expr left,
     Expr right)
     : this()
 {
     this.left = left;
     this.right = right;
     this.operation = operation;
 }