Esempio n. 1
0
 public void treeprint(string prefix, AstNode tree, int depth)
 {
     if (tree == null) {
         return;
     }
     tree.Print(depth);
 }
Esempio n. 2
0
 public void BuildEnv(AstNode node)
 {
     if (node == null)
         return;
     AstNode cur = node;
     while (node != null) {
         node.BuildEnv();
         node = node.sibling;
     }
 }
Esempio n. 3
0
 public AstNode(AstNode node)
 {
     nodetype = node.nodetype;
     symbol = node.symbol;
     val = node.val;
     type = node.type;
     child = node.child;
     sibling = node.sibling;
     localenv = node.localenv;
     closure = node.closure;
 }
Esempio n. 4
0
        private void GeneratePlangCore(AstNode root)
        {
            // generate all global field
            //foreach (var keyvalue in EnviromentList.Global.table) {
            //    EnviromentNode node = keyvalue.Value;
            //    if( node.Type != "__function__" && node.Type != "__lambda__" )
            //        node.field = program.DefineField(keyvalue.Key, typeof(TypeBase), System.Reflection.FieldAttributes.Private | System.Reflection.FieldAttributes.Static);
            //}

            // then generate global sentenses
            main = program.DefineMethod("Main", System.Reflection.MethodAttributes.Static | System.Reflection.MethodAttributes.Public,
                 System.Reflection.CallingConventions.Standard, typeof(void), null);
            _gen.SetEntryPoint(main);
            AstNode sentense = root;
            while (sentense != null) {
                    sentense.Gen(program, main);
                sentense = sentense.sibling;
            }
            main.GetILGenerator().Emit(OpCodes.Ret);
        }
Esempio n. 5
0
 public bool AddSymbol(string symbol, AstNode _node, bool global, int paramIndex = -1)
 {
     if (string.IsNullOrEmpty(symbol))
         return false;
     if (table.Keys.Contains(symbol))
         return false;
     else {
         EnviromentNode node = new EnviromentNode();
         node.BlockName = Name;
         node.Symbol = symbol;
         if (_node != null) {
             node.Type = _node.type;
             node.Grammer = _node;
         }
         node.IsGlobal = global;
         node.ParamIndex = paramIndex;
         table.Add(symbol, node);
         return true;
     }
 }
Esempio n. 6
0
 public void Generate(AstNode root)
 {
     GenerateProgram();
     GeneratePlangCore(root);
 }
Esempio n. 7
0
 public DoubleNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 8
0
 public FunctorNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 9
0
 public FunctionCallNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 10
0
 public StringNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 11
0
        public bool AddSymbol(string symbol, AstNode node, int paramIndex = -1)
        {
            // FIXME
            // dont add to global

            if (current == null)
                return Global.AddSymbol(symbol, node, true, paramIndex);
            else
                return current.AddSymbol(symbol, node, false, paramIndex);
        }
Esempio n. 12
0
 public MulDivNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 13
0
 public CaculatorNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 14
0
 public PoweredNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 15
0
 public OverriteNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 16
0
 public AssignNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 17
0
 public BoolNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 18
0
 public ArrayNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 19
0
 public IdentifyNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 20
0
 private bool CheckFunctor( MethodBuilder up, AstNode functor )
 {
     if (functor.type == "__lambda__")
         return false;
     var node = EnviromentList.Instance.LoopupSymbol( functor.symbol );
     if (node != null && node.method == up)
         return true;
     else
         return false;
 }
Esempio n. 21
0
 public FunctionAbs(AstNode node)
     : base(node)
 {
 }
Esempio n. 22
0
 public EmptyNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 23
0
        private bool IsTailRecury( AstNode sentense, MethodBuilder up, bool jumpToLast = true)
        {
            if (EnviromentList.Instance.EnableTailRecury == false)
                return false;
            AstNode body = sentense;
            AstNode last = sentense;
            if (jumpToLast) {
                while (body != null) {
                    last = body;
                    body = body.sibling;
                }
            }

            // 查看最后一条是不是
            // 1. function call
            // 2. if then else, 并且最终结果要么是值,要么是function call
            // 3. 并且function call是up
            if (last is IfCondition) {
                AstNode condition = last.child;
                AstNode match = condition.sibling;
                AstNode notmatch = match.sibling;
                return IsTailRecury( match , up, false) && IsTailRecury( notmatch, up, false);
            } else if (last is FunctionCallNode) {
                FunctionCallNode call = last as FunctionCallNode;
                AstNode functor = call.child.child;
                return CheckFunctor( up, functor );
            }else if ( last is CharNode ||
                last is DigitNode ||
                last is DoubleNode ||
                last is StringNode ||
                last is ArrayNode ||
                last is LambdaNode ||
                last is IdentifyNode){
                return true;
            } else {
                return false;
            }
        }
Esempio n. 24
0
 public void eval(AstNode tree)
 {
 }
Esempio n. 25
0
 public FunctionBodyNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 26
0
 internal void appendchild(AstNode parent, AstNode child)
 {
     parent.child =  child;
 }
Esempio n. 27
0
 public FunctionDeclearNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 28
0
 internal void appendsibling(AstNode parent, AstNode sibling)
 {
     if (parent.sibling == null) {
         parent.sibling = sibling;
     } else {
         AstNode last = parent.sibling;
         while (last.sibling != null)
             last = last.sibling;
         last.sibling = sibling;
     }
 }
Esempio n. 29
0
 public ParametersNode(AstNode node)
     : base(node)
 {
 }
Esempio n. 30
0
 public ArrayBound(AstNode node)
     : base(node)
 {
 }