} // set during AST construction #region implemented abstract members of Node public override void BuildNode <TSymbol>(IParseTree <TSymbol> parseTree) { // LoopControl -> ("break" | "continue") (Expression DecimalNumberLiteral?)? var childs = ASTBuilder.ChildrenArray(parseTree); Debug.Assert(childs.Length >= 1); switch (childs[0].Fragment.GetOriginText()) { case "break": Mode = LoopControlMode.LCM_BREAK; break; case "continue": Mode = LoopControlMode.LCM_CONTINUE; break; } if (childs.Length >= 2) { Value = ExpressionNode.GetExpressionNode(childs[1]); } if (childs.Length == 3) { Depth = int.Parse(childs[2].Fragment.GetOriginText()); } }
public override void BuildNode <TSymbol> (IParseTree <TSymbol> parseTree) { var arr = ASTBuilder.ChildrenArray(parseTree); FieldName = arr [0].Fragment.GetOriginText(); Value = ExpressionNode.GetExpressionNode(arr [2]); }
public override void BuildNode <TSymbol> (IParseTree <TSymbol> parseTree) { Console.WriteLine("Build ast: " + parseTree); IParseTree <TSymbol>[] childs = ASTBuilder.ChildrenArray(parseTree); // name { fields } Debug.Assert(childs.Length == 4); // name from arg 0 Name = TypeNode.GetTypeNode(childs[0]); // fields from arg 2 Fields = GetFields(childs[2]); }
public override void BuildNode <TSymbol>(IParseTree <TSymbol> parseTree) { // IfExpression -> "if" Expression Expression ("else" Expression)? var childs = ASTBuilder.ChildrenArray(parseTree); Debug.Assert(childs.Length >= 3); Condition = ExpressionNode.GetExpressionNode(childs[1]); Then = ExpressionNode.GetExpressionNode(childs[2]); if (childs.Length == 5) { Else = ExpressionNode.GetExpressionNode(childs[4]); } }
public override void BuildNode <TSymbol>(IParseTree <TSymbol> parseTree) { IParseTree <TSymbol>[] childs = ASTBuilder.ChildrenArray(parseTree); // name ( params ) -> type expr Debug.Assert(childs.Length == 7); // name from arg 0 Name = childs[0].Fragment.GetOriginText(); // parameters from arg 2 Parameters = GetParameters(childs[2]); // type from arg 5 ResultType = TypeNode.GetTypeNode(childs[5]); // body from arg 6 Body = ExpressionNode.GetExpressionNode(childs[6]); }
static IEnumerable <RecordTypeFieldDeclarationNode> GetFields <TSymbol>(IParseTree <TSymbol> parseTree) where TSymbol : ISymbol <TSymbol> { var lst = new LinkedList <RecordTypeFieldDeclarationNode>(); var childs = ASTBuilder.ChildrenEnumerator(parseTree); while (childs.MoveNext()) { var objectDefinition = ASTBuilder.ChildrenArray(childs.Current) [0]; var fld = new RecordTypeFieldDeclarationNode(); fld.BuildNode(objectDefinition); lst.AddLast(fld); } return(lst); }