Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
	// Construct a Retokenizer to scan a linked list of tokens with the
	// given head node.
	public Retokenizer(TokenListNode tokens)
		{
		nextToken = tokens;
		} // Retokenizer constructor
Exemplo n.º 4
0
 // Construct a Retokenizer to scan a linked list of tokens with the
 // given head node.
 public Retokenizer(TokenListNode tokens)
 {
     nextToken = tokens;
 }         // Retokenizer constructor