Home | History | Annotate | Download | only in treeparser
      1 #import <Cocoa/Cocoa.h>
      2 #import "antlr3.h"
      3 #import "LangLexer.h"
      4 #import "LangParser.h"
      5 #import "LangDumpDecl.h"
      6 #import "stdio.h"
      7 #include <unistd.h>
      8 
      9 /*
     10 import org.antlr.runtime.*;
     11 import org.antlr.runtime.tree.*;
     12 
     13 public class Main {
     14 	public static void main(String[] args) throws Exception {
     15 		CharStream input = new ANTLRFileStream(args[0]);
     16 		LangLexer lex = new LangLexer(input);
     17 		CommonTokenStream tokens = new CommonTokenStream(lex);
     18 		LangParser parser = new LangParser(tokens);
     19 		//LangParser.decl_return r = parser.decl();
     20 		LangParser.start_return r = parser.start();
     21 		System.out.println("tree: "+((Tree)r.tree).toStringTree());
     22 		CommonTree r0 = ((CommonTree)r.tree);
     23         
     24 		CommonTreeNodeStream nodes = new CommonTreeNodeStream(r0);
     25 		nodes.setTokenStream(tokens);
     26 		LangDumpDecl walker = new LangDumpDecl(nodes);
     27 		walker.decl();
     28 	}
     29 }
     30 */
     31 
     32 int main(int argc, const char * argv[])
     33 {
     34     NSError *error;
     35     NSLog(@"starting treeparser\n");
     36     NSString *dir = @"/Users/acondit/source/antlr3/acondit_localhost/code/antlr/main/runtime/ObjC/Framework/examples/treeparser/input";
     37 	NSString *string = [NSString stringWithContentsOfFile:dir  encoding:NSASCIIStringEncoding error:&error];
     38 	NSLog(@"input = %@", string);
     39 	ANTLRStringStream *stream = [ANTLRStringStream newANTLRStringStream:string];
     40 	LangLexer *lex = [LangLexer newLangLexerWithCharStream:stream];
     41     ANTLRCommonTokenStream *tokens = [ANTLRCommonTokenStream newANTLRCommonTokenStreamWithTokenSource:lex];
     42     LangParser *parser = [LangParser newLangParser:tokens];
     43 //    LangParser_decl_return *r = [parser decl];
     44     LangParser_start_return *r = [parser start];
     45     NSLog( @"tree: %@", [r.tree toStringTree]);
     46     ANTLRCommonTree *r0 = [r getTree];
     47     
     48     ANTLRCommonTreeNodeStream *nodes = [ANTLRCommonTreeNodeStream newANTLRCommonTreeNodeStream:r0];
     49     [nodes setTokenStream:tokens];
     50     LangDumpDecl *walker = [LangDumpDecl newLangDumpDecl:nodes];
     51     [walker decl];
     52 
     53     NSLog(@"exiting treeparser\n");
     54 	return 0;
     55 }