예제 #1
0
		} // CaptureTokens
	
	
	// Read JavaScript source text and output a C# file.  progClassName
	// is the name of the C# class we generate.  inputFileLabel denotes
	// the source of the input text; it is inserted in a comment in the
	// C# source.
	public static void CompileToCSharp( TextReader input, TextWriter output,
										string progClassName,
										string inputFileLabel,
										bool forEvalCode )
		{
		Tokenizer tokenizer = new Tokenizer(input);
		TokenListNode tokenList = CaptureTokens(tokenizer);
		
		Phase1Parser parser = new Phase1Parser(new Retokenizer(tokenList));
		
		ProgramInfo programInfo = new ProgramInfo();
		FunctionInfo rootFunc = new FunctionInfo(programInfo, null, null);
		
		parser.ParseProgram(rootFunc);
		
		PrettyPrinter pp = new PrettyPrinter(output);
		
		pp.Line("// JANET compiler output for source file " + inputFileLabel);
		pp.Line("// ");
		
		CSharpGenerator gen = new CSharpGenerator( rootFunc, pp, progClassName,
												   forEvalCode );
		Phase2Parser parser2 = new Phase2Parser( new Retokenizer(tokenList),
												 gen );
		parser2.ParseProgram(rootFunc);
		} // CompileToCSharp
예제 #2
0
	private static TokenListNode CaptureTokens(Tokenizer tokenizer)
		{
		TokenListNode head = null;
		TokenListNode tail = null;
		while (true)
			{
			Token tok = tokenizer.Match();
			if (tok == null)
				break;
			
			TokenListNode newNode = new TokenListNode();
			newNode.token = tok;
			newNode.next = null;
			if (head == null)
				head = newNode;
			else
				tail.next = newNode;
			
			tail = newNode;
			}
		
		return head;
		} // CaptureTokens