Contains helper methods for creating LNodes. An LNodeFactory holds a reference to the current source file (File) so that it does not need to be repeated every time you create a node.
Example #1
0
 /// <summary>
 /// Creates a new immutable header from the given node factory, symbol table and template table.
 /// </summary>
 /// <param name="nodeFactory"></param>
 /// <param name="symbolTable"></param>
 /// <param name="templateTable"></param>
 public ReaderState(LNodeFactory nodeFactory, IReadOnlyList<string> symbolTable, IReadOnlyList<NodeTemplate> templateTable)
 {
     this.NodeFactory = nodeFactory;
     this.SymbolTable = symbolTable;
     this.SymbolPool = SymbolPool.@new();
     this.TemplateTable = templateTable;
 }
Example #2
0
			public GenerateCodeVisitor(LLParserGenerator llpg)
			{
				LLPG = llpg;
				F = new LNodeFactory(llpg._sourceFile);
				_classBody = llpg._classBody;
			}
Example #3
0
		public CodeGenHelperBase()
		{
			F = new LNodeFactory(EmptySourceFile.Unknown);
			ListType = F.Of(F.Id("List"), F.Id(_T));
			ListInitializer = F.Call(S.New, F.Call(ListType));
		}
Example #4
0
		public virtual void Done()
		{
			_classBody = null;
			F = null;
			_setDeclNames = null;
			_currentRule = null;
		}
Example #5
0
		public virtual void Begin(RWList<LNode> classBody, ISourceFile sourceFile)
		{
			_classBody = classBody;
			F = new LNodeFactory(sourceFile);
			_setDeclNames = new Dictionary<IPGTerminalSet, Symbol>();
		}
Example #6
0
 private IReadOnlyList<LNode> GenerateRandomNodeList(LNodeFactory Factory, Random Rand, int Depth)
 {
     var results = new LNode[(int)System.Math.Sqrt(Rand.Next(100))];
     for (int i = 0; i < results.Length; i++)
     {
         results[i] = GenerateRandomNode(Factory, Rand, Depth);
     }
     return results;
 }
Example #7
0
 private LNode GenerateRandomNode(LNodeFactory Factory, Random Rand, int Depth)
 {
     int index = Rand.Next(5);
     switch (Depth <= 0 && index > 1 ? Rand.Next(2) : index)
     {
         case 0:
             return Factory.Literal(GenerateRandomLiteral(Rand));
         case 1:
             return Factory.Id(GenerateRandomSymbol(Rand));
         case 2:
             return Factory.Attr(GenerateRandomNode(Factory, Rand, Depth - 1), GenerateRandomNode(Factory, Rand, Depth - 1));
         case 3:
             return Factory.Call(GenerateRandomSymbol(Rand), GenerateRandomNodeList(Factory, Rand, Depth - 1));
         default:
             return Factory.Call(GenerateRandomNode(Factory, Rand, Depth - 1), GenerateRandomNodeList(Factory, Rand, Depth - 1));
     }
 }