示例#1
0
        public void AddNode(Node node)
        {
            if (AllNodes.Contains(node))
                return;

            AllNodes.Add(node);

            if (!DirectContingents.ContainsKey(node))
                DirectContingents.Add(node, new List<Node>());

            if (!DirectDependents.ContainsKey(node))
                DirectDependents.Add(node, new List<Node>());
        }
示例#2
0
	void functiondecl(out Node node, ProtoCore.DSASM.AccessModifier access = ProtoCore.DSASM.AccessModifier.kPublic) {
		FunctionDefinitionNode f = new FunctionDefinitionNode(); 
		string methodName;  
		Node argumentSignature; 
		ProtoCore.Type returnType;  
		Node pattern; 
		string externLibName = ""; 
		bool isExternLib = false; 
		bool isDNI = false; 								
		
		if (la.kind == 26) {
			Get();
			isExternLib = true; 
			if (la.kind == 22) {
				Get();
				isDNI = true; 
			}
			ExternalLibraryReference(out externLibName);
		}
		Expect(25);
		MethodSignature(out methodName, out argumentSignature, out pattern, out returnType);
		f = new FunctionDefinitionNode(); 
		f.IsExternLib = isExternLib; 
		f.IsDNI = isDNI; 
		f.ExternLibName = externLibName; 
		f.Name = methodName; 
		f.Name = methodName; 
		f.Pattern = pattern; 
		f.ReturnType = returnType; 
		f.access = access;
		f.Singnature = argumentSignature as ArgumentSignatureNode; 
		Node functionBody = null; 
		
		if (la.kind == 20) {
			Get();
		} else if (la.kind == 32) {
			FunctionalMethodBodyMultiLine(out functionBody);
		} else SynErr(62);
		f.FunctionBody = functionBody as CodeBlockNode; 
		node = f;	
		
	}
示例#3
0
        public override void ConsolidateNames(ref Dictionary<string, List<Node>> names)
        {
            IdentifierNode rightTerminalNode = RightNode as IdentifierNode;
            if (rightTerminalNode != null)
            {
                if (Optr != ProtoCore.DSASM.Operator.dot)
                {
                    //replace RHS
                    Consolidate(ref(names), ref(rightTerminalNode));
                    RightNode = rightTerminalNode;
                }
            }
            else
            {
                RightNode.ConsolidateNames(ref(names));
            }

            //left has to be done 2nd, because in case of modifiers, we dont want to 
            //replace the node on RHS by a node on LHS. So a modifier stack name is not unique.
            IdentifierNode leftTerminalNode = LeftNode as IdentifierNode;
            if (leftTerminalNode != null)
            {
                if (Optr != ProtoCore.DSASM.Operator.assign)
                {
                    //replace LHS
                    Consolidate(ref(names), ref(leftTerminalNode));
                    LeftNode = leftTerminalNode;
                }
                else
                {
                    if (leftTerminalNode.Name != null)
                    {
                        if (names.ContainsKey(leftTerminalNode.Name))
                        {
                            List<Node> candidates = names[leftTerminalNode.Name];
                            candidates.Add(leftTerminalNode);
                        }
                        else
                        {
                            //append LHS
                            List<Node> candidates = new List<Node>();
                            candidates.Add(leftTerminalNode);
                            names.Add(leftTerminalNode.Name, candidates);
                        }
                    }
                    
                }
            }
            else
            {
                LeftNode.ConsolidateNames(ref(names));
            }
        }
示例#4
0
 public void RemoveDirectContingents(Node node)
 {
     DirectContingents[node].Clear();
 }
示例#5
0
 public void AddDirectDependent(Node node, Node dependent)
 {
     if (!DirectDependents[node].Contains(dependent))
         DirectDependents[node].Add(dependent);
 }
示例#6
0
 public static void GenerateDependencyGraph(this DependencyTracker tracker, Node t)
 {
     t.GenerateDependencyGraph(tracker);
 }
示例#7
0
	void ComparisonExpression(out Node node) {
		RangeExpr(out node);
		while (StartOf(9)) {
			Operator op; 
			ComparisonOp(out op);
			Node expr2; 
			RangeExpr(out expr2);
			BinaryExpressionNode binaryNode = new BinaryExpressionNode();
			binaryNode.LeftNode = node;
			binaryNode.RightNode = expr2;
			binaryNode.Optr = op;
			node = binaryNode;
			
		}
	}
示例#8
0
	void LogicalExpression(out Node node) {
		ComparisonExpression(out node);
		while (la.kind == 55 || la.kind == 56) {
			Operator op;
			LogicalOp(out op);
			Node expr2; 
			Expression(out expr2);
			BinaryExpressionNode binaryNode = new BinaryExpressionNode();
			binaryNode.LeftNode = node;
			binaryNode.RightNode = expr2;
			binaryNode.Optr = op;
			node = binaryNode;
			
		}
	}
示例#9
0
	void BaseConstructorCall(out Node bnode) {
		FunctionCallNode f = new FunctionCallNode(); 
		NodeList args = null; 
		Expect(37);
		if (la.kind == 1) {
			Ident(out bnode);
			f.Function = bnode; 
		}
		Arguments(out args);
		f.FormalArguments = args; 
		bnode = f; 
	}
示例#10
0
	void MethodSignature(out string methodName, out Node argumentSign, out Node pattern, out ProtoCore.Type returnType) {
		Expect(1);
		methodName = t.val; 
		Node argumentSignature = null;
		                          returnType = new ProtoCore.Type(); 
		                          returnType.Name = "var";
		                          returnType.UID = 0;
		
		                          // TODO Jun: Luke made changes to array representation, handle this
		                          //returnType.IsArray = false;
		                      
		if (la.kind == 36) {
			TypeRestriction(out returnType);
		}
		ArgumentSignatureDefinition(out argumentSignature);
		pattern = null; 
		if (la.kind == 15) {
			PatternExpression(out pattern);
		}
		argumentSign = argumentSignature; 
	}
示例#11
0
	void constructordecl(out Node constrNode, ProtoCore.DSASM.AccessModifier access) {
		ConstructorDefinitionNode constr = null;									
		string methodName;  
		Node argumentSignature; 
		ProtoCore.Type returnType;  
		Node pattern;								
		
		Expect(24);
		MethodSignature(out methodName, out argumentSignature, out pattern, out returnType);
		constr = new ConstructorDefinitionNode(); 
		constr.Name = methodName; 
		constr.Pattern = pattern; 
		constr.ReturnType = returnType;
		constr.Signature = argumentSignature as ArgumentSignatureNode;
		constr.access = access; 
		Node functionBody = null; 
		
		if (la.kind == 36) {
			Get();
			Node bnode; 
			BaseConstructorCall(out bnode);
			constr.baseConstr = bnode as FunctionCallNode; 
		}
		FunctionalMethodBodyMultiLine(out functionBody);
		constr.FunctionBody = functionBody as CodeBlockNode; 
		constrNode = constr; 
	}
示例#12
0
	void ForLoop(out Node forLoop) {
		Node node;
		ForLoopNode loop = new ForLoopNode(); 
		NodeList forBody = null; 
		
		Expect(48);
		Expect(18);
		IdentifierList(out node);
		loop.id = node; 
		Expect(49);
		Expression(out node);
		loop.expression = node; 
		Expect(19);
		Expect(32);
		StatementList(out forBody);
		loop.body = forBody; 
		Expect(33);
		forLoop = loop; 
	}
示例#13
0
	void FunctionalStatement(out Node node) {
		while (!(la.kind == 0 || la.kind == 1)) {SynErr(64); Get();}
		node = null; 
		Node leftNode; 
		IdentifierList(out leftNode);
		Expect(35);
		Node rightNode = null; 
		if (la.kind == 11) {
			LanguageBlock(out rightNode);
			BinaryExpressionNode expressionNode = new BinaryExpressionNode(); 
			expressionNode.LeftNode = leftNode; 
			expressionNode.RightNode = rightNode; 
			expressionNode.Optr = Operator.assign; 
			node = expressionNode; 
		} else if (StartOf(4)) {
			Expression(out rightNode);
			BinaryExpressionNode expressionNode = new BinaryExpressionNode(); 
			expressionNode.LeftNode = leftNode; 
			expressionNode.RightNode = rightNode; 
			expressionNode.Optr = Operator.assign; 
			node = expressionNode; 
			while (!(la.kind == 0 || la.kind == 20)) {SynErr(65); Get();}
			Expect(20);
		} else if (la.kind == 41) {
			Get();
			ModifierStackNode mstack = new ModifierStackNode(); 
			string name = ""; 
			Expression(out rightNode);
			if (la.kind == 42) {
				Get();
				Expect(1);
				name = t.val; 
			}
			BinaryExpressionNode expressionNode = new BinaryExpressionNode();
			expressionNode.RightNode = rightNode;
			expressionNode.LeftNode = leftNode; 
			expressionNode.Optr = Operator.assign;
			mstack.AddElementNode(expressionNode, name); 
			
			while (!(la.kind == 0 || la.kind == 20)) {SynErr(66); Get();}
			Expect(20);
			while (StartOf(5)) {
				name = ""; 
				bool bHasOperator = false; 
				Operator op = Operator.add;  
				if (StartOf(6)) {
					bHasOperator = true; 
					BinaryOps(out op);
				}
				Expression(out rightNode);
				if (la.kind == 42) {
					Get();
					Expect(1);
					name = t.val; 
				}
				if(!bHasOperator)
				{
				  expressionNode = new BinaryExpressionNode();
				  expressionNode.RightNode = rightNode;
				  expressionNode.LeftNode = leftNode; 
				  expressionNode.Optr = Operator.assign;
				  mstack.AddElementNode(expressionNode, name);
				}
				else
				{ 
				  BinaryExpressionNode expressionNode2 = new BinaryExpressionNode(); 
				  expressionNode2.LeftNode = leftNode;
				  expressionNode2.RightNode = rightNode;
				  expressionNode2.Optr = op;
				  expressionNode = new BinaryExpressionNode();
				  expressionNode.RightNode = expressionNode2;
				  expressionNode.LeftNode = leftNode; 
				  expressionNode.Optr = Operator.assign;
				  mstack.AddElementNode(expressionNode, name);
				}
				
				while (!(la.kind == 0 || la.kind == 20)) {SynErr(67); Get();}
				Expect(20);
			}
			node = mstack; 
			Expect(33);
		} else SynErr(68);
	}
示例#14
0
	void LanguageBlock(out Node node) {
		node = null; 
		LanguageBlockNode langblock = new LanguageBlockNode(); 
		
		Expect(11);
		Expect(1);
		if( 0 == t.val.CompareTo("Imperative")) {
		langblock.codeblock.language = ProtoCore.Language.kImperative;
		}
		else if( 0 == t.val.CompareTo("Associative")) {
		langblock.codeblock.language = ProtoCore.Language.kAssociative; 
		}
		
		while (la.kind == 34) {
			Get();
			string key; 
			Expect(1);
			key = t.val; 
			Expect(35);
			Expect(4);
			if ("fingerprint" == key)
			{
			langblock.codeblock.fingerprint = t.val; 
			langblock.codeblock.fingerprint = langblock.codeblock.fingerprint.Remove(0,1); 
			langblock.codeblock.fingerprint = langblock.codeblock.fingerprint.Remove(langblock.codeblock.fingerprint.Length-1,1); 
			}
			else if ("version" == key)
			{
			langblock.codeblock.version = t.val; 
			langblock.codeblock.version = langblock.codeblock.version.Remove(0,1); 
			langblock.codeblock.version = langblock.codeblock.version.Remove(langblock.codeblock.version.Length-1,1);
			}
			
		}
		Expect(12);
		Expect(31);
		langblock.codeblock.body = t.val.Substring(2,t.val.Length-4);									
		node = langblock;
		                                ParseLanguageBlockNode(langblock);
		
	}
示例#15
0
	void classdecl(out Node node) {
		ClassDeclNode classnode = new ClassDeclNode(); 
		Expect(23);
		Expect(1);
		classnode.name = t.val; 
		if (la.kind == 27) {
			Get();
			Expect(1);
			classnode.superClass = new List<string>();
			classnode.superClass.Add(t.val); 
			
			while (la.kind == 1) {
				Get();
				classnode.superClass.Add(t.val); 
			}
		}
		Expect(32);
		while (StartOf(3)) {
			ProtoCore.DSASM.AccessModifier access = ProtoCore.DSASM.AccessModifier.kPublic; 
			if (la.kind == 38 || la.kind == 39 || la.kind == 40) {
				AccessModifier(out access);
			}
			if (la.kind == 24) {
				Node constr = null; 
				constructordecl(out constr, access);
				classnode.funclist.Add(constr); 
			} else if (la.kind == 25 || la.kind == 26) {
				Node funcnode; 
				functiondecl(out funcnode, access);
				classnode.funclist.Add(funcnode); 
			} else if (la.kind == 1) {
				Node varnode = null; 
				vardecl(out varnode, access);
				classnode.varlist.Add(varnode); 
				Expect(20);
			} else SynErr(63);
		}
		Expect(33);
		node = classnode; 
	}
示例#16
0
	void IdentifierList(out Node node) {
		node = null; 
		NameReference(out node);
		while (la.kind == 5) {
			Get();
			Node rnode = null; 
			NameReference(out rnode);
			IdentifierListNode bnode = new IdentifierListNode(); 
			bnode.LeftNode = node; 
			bnode.Optr = Operator.dot; 
			bnode.RightNode = rnode; 
			node = bnode; 
			
		}
	}
示例#17
0
	void UnaryExpression(out Node node) {
		node = null; 
		UnaryOperator op; 
		Node exprNode; 
		unaryop(out op);
		Expression(out exprNode);
		UnaryExpressionNode unary = new UnaryExpressionNode(); 
		unary.Operator = op;
		unary.Expression = exprNode;
		node = unary;
		
	}
示例#18
0
	void FunctionalMethodBodyMultiLine(out Node funcBody) {
		CodeBlockNode functionBody = new CodeBlockNode(); 
		NodeList body = new NodeList(); 
		
		Expect(32);
		StatementList(out body);
		functionBody = new CodeBlockNode(); 
		functionBody.Body =body;  
		Expect(33);
		funcBody = functionBody; 
	}
示例#19
0
	void TernaryOp(ref Node node) {
		InlineConditionalNode inlineConNode = new InlineConditionalNode(); 
		Expect(43);
		inlineConNode.ConditionExpression = node; node = null; 
		Expression(out node);
		inlineConNode.TrueExpression = node; 
		Expect(36);
		node = null; 
		Expression(out node);
		inlineConNode.FalseExpression = node; 
		node = inlineConNode; 
	}
示例#20
0
	void Ident(out Node node) {
		Expect(1);
		int ltype = (0 == String.Compare(t.val, "return")) ? (int)ProtoCore.PrimitiveType.kTypeReturn : (int)ProtoCore.PrimitiveType.kTypeVar;
		IdentifierNode var = new IdentifierNode() 
		{
		// TODO Jun: Move the primitive types into a class table 
		Value = t.val, 
		Name = t.val, 
		type = ltype,
		datatype = (ProtoCore.PrimitiveType)ltype 
		}; 
		node = var;
		
	}
示例#21
0
	void RangeExpr(out Node node) {
		ArithmeticExpression(out node);
		if (la.kind == 21) {
			RangeExprNode rnode = new RangeExprNode(); 
			rnode.FromNode = node;
			
			Get();
			ArithmeticExpression(out node);
			rnode.ToNode = node; 
			if (la.kind == 21) {
				RangeStepOperator op; 
				Get();
				rangeStepOperator(out op);
				rnode.stepoperator = op; 
				ArithmeticExpression(out node);
				rnode.StepNode = node; 
			}
			node = rnode; 
		}
	}
示例#22
0
	void ArgumentSignatureDefinition(out Node argumentSign) {
		ArgumentSignatureNode argumentSignature = new ArgumentSignatureNode(); 
		Expect(18);
		if (la.kind == 1) {
			Node arg;
			ArgDecl(out arg);
			argumentSignature.AddArgument(arg as VarDeclNode); 
			while (la.kind == 34) {
				Get();
				ArgDecl(out arg);
				argumentSignature.AddArgument(arg as VarDeclNode); 
			}
		}
		Expect(19);
		argumentSign = argumentSignature; 
	}
示例#23
0
 public void AddDirectContingent(Node node, Node contingent)
 {
     if(!DirectContingents[node].Contains(contingent))
         DirectContingents[node].Add(contingent);
 }
示例#24
0
	void PatternExpression(out Node pattern) {
		Node p = null; 
		Expect(15);
		Expression(out p);
		pattern = p; 
	}
示例#25
0
	void ArgDecl(out Node node, ProtoCore.DSASM.AccessModifier access = ProtoCore.DSASM.AccessModifier.kPublic) {
		IdentifierNode tNode = null; 
		VarDeclNode varDeclNode = new VarDeclNode(); 
		varDeclNode.memregion = ProtoCore.DSASM.MemoryRegion.kMemStack;
		varDeclNode.access = access;
		
		if (IsArrayAccess()) {
			arrayIdent(out node);
			tNode = node as IdentifierNode; 
			varDeclNode.NameNode = tNode;
			
		} else if (la.kind == 1) {
			Get();
			tNode = new IdentifierNode() 
			{ 
			   Value = t.val, 
			   Name = t.val, 
			   type = (int)ProtoCore.PrimitiveType.kTypeVar, 
			   datatype = ProtoCore.PrimitiveType.kTypeVar 
			}; 
			varDeclNode.NameNode = tNode;
			
		} else SynErr(71);
		ProtoCore.Type argtype = new ProtoCore.Type(); argtype.Name = "var"; argtype.rank = 0; argtype.UID = 0; 
		if (la.kind == 36) {
			Get();
			Expect(1);
			argtype.Name = t.val; 
			if (la.kind == 11) {
				argtype.IsIndexable = true; 
				Get();
				Expect(12);
				argtype.rank = 1; 
				if (la.kind == 11 || la.kind == 21 || la.kind == 35) {
					if (la.kind == 21) {
						Get();
						Expect(11);
						Expect(12);
						argtype.rank = ProtoCore.DSASM.Constants.nDimensionArrayRank; 
					} else {
						while (la.kind == 11) {
							Get();
							Expect(12);
							argtype.rank++; 
						}
					}
				}
			}
		}
		varDeclNode.ArgumentType = argtype; 
		if (la.kind == 35) {
			Get();
			Node rhsNode; 
			Expression(out rhsNode);
			BinaryExpressionNode bNode = new BinaryExpressionNode();
			bNode.LeftNode = tNode;
			bNode.RightNode = rhsNode;
			bNode.Optr = Operator.assign;
			varDeclNode.NameNode = bNode;		
			
		}
		node = varDeclNode; 
	}
示例#26
0
	void arrayIdent(out Node node) {
		Ident(out node);
		IdentifierNode var = node as IdentifierNode; 
		if (la.kind == 11) {
			ArrayNode array = null; 
			arrayIndices(out array);
			var.ArrayDimensions = array; 
		}
	}
示例#27
0
 public void RemoveDirectDependents(Node node)
 {
     DirectDependents[node].Clear();
 }
示例#28
0
	void Expression(out Node node) {
		node = null; 
		if (la.kind == 13 || la.kind == 57) {
			UnaryExpression(out node);
		} else if (StartOf(8)) {
			LogicalExpression(out node);
		} else SynErr(72);
		while (la.kind == 43) {
			TernaryOp(ref node);
		}
	}
示例#29
0
 public void AddElementNode(Node n, string name)
 {
     ElementNodes.Add(n);
     if ("" != name)
     {
         AtNames.Add(name, n);
         BinaryExpressionNode o = n as BinaryExpressionNode;
         IdentifierNode t = o.LeftNode as IdentifierNode;
         BinaryExpressionNode e = new BinaryExpressionNode();
         e.LeftNode = new IdentifierNode() { Value = name, Name = name, type = t.type, datatype = t.datatype };
         e.RightNode = t;
         e.Optr = ProtoCore.DSASM.Operator.assign;
         ElementNodes.Add(e);
     }
 }
示例#30
0
	void Statement(out Node node) {
		while (!(StartOf(2))) {SynErr(60); Get();}
		node = null; 
		if (la.kind == 1) {
			FunctionalStatement(out node);
		} else if (la.kind == 48) {
			ForLoop(out node);
		} else if (la.kind == 20) {
			Get();
		} else SynErr(61);
	}