internal void InitGenerator(Expr expr) { ProgramDeclBlock pdb = expr as ProgramDeclBlock; string name = pdb.FunctionName; this.expr = expr; Generate(name, "exe"); }
/// <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; }
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; }
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); }
private void ParseIntDeclaration(out Expr expr) { expr = null; }
private void ParseStringDeclartion(out Expr expr) { Token tokenType = _scanner.GetToken(); expr = ArrayDeclaration(tokenType); }
private void ParseFloatDeclartion(out Expr expr) { expr = null; }
/// <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; } } }
private void ParseBoolDeclartion(out Expr expr) { expr = null; }
private void AddStatementExpressionTreesToFunctionBlock(Expr bin) { var scopeExpr = _expressionScopeStack.Peek() as FunctionDeclBlock; if (scopeExpr != null) { scopeExpr.AddStatment(bin); } }
internal AssignmentExpr(OperatorExpression operation, Expr left, Expr right) : base(operation, left, right) { }
internal ArithmeticBinaryExpr(OperatorExpression operation, Expr left, Expr right) : base(operation, left, right) { }
internal BinaryOperatorExpression( OperatorExpression operation, Expr left, Expr right) : this() { this.left = left; this.right = right; this.operation = operation; }