本文整理汇总了C++中ParseTree::get_root方法的典型用法代码示例。如果您正苦于以下问题:C++ ParseTree::get_root方法的具体用法?C++ ParseTree::get_root怎么用?C++ ParseTree::get_root使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseTree
的用法示例。
在下文中一共展示了ParseTree::get_root方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
printf("Output file not specified\n");
return 0;
}
strcpy(output, argv[i+1]);
i++;
}
//input file
else if(input == NULL) {
input = (char*)malloc(sizeof(argv[i]));
strcpy(input, argv[i]);
}
//invalid
else {
printf("Unknown argument: %s\n", argv[i]);
return 0;
}
}
//initialize the symbol table and parse tree
SymbolTable *symbolTable = new SymbolTable();
ParseTree *parseTree = new ParseTree();
//get the lexical analyzer input file
FILE *lex_file = fopen("lex_table.csv", "r");
if(lex_file == NULL) {
printf("Could not find lex syntax file!\n");
printf("The file should be placed in the same directory and named 'lex_table.csv'\n");
return 0;
}
//get the code input file
if(argc < 2) {
printf("Please add the input file to the arguments\n");
printf("(example ./compiler test)\n");
return 0;
}
FILE *infile = fopen(input, "r");
if(infile == NULL) {
printf("Could not find the input file: %s\n", argv[1]);
printf("Please ensure that it exists\n");
return 0;
}
//get the syntax analyzer input file
FILE *syn_file = fopen("parse_table.csv", "r");
if(syn_file == NULL) {
printf("Could not find the parse table file!\n");
printf("The file should be placed in the same directory and named 'parse_table.csv'\n");
return 0;
}
//create the lexical analyzer and syntax analyzer
LexicalAnalyzer *lexicalAnalyzer = new LexicalAnalyzer(lex_file, infile);
SyntaxAnalyzer *syntaxAnalyzer = new SyntaxAnalyzer(syn_file, lexicalAnalyzer, symbolTable, parseTree);
//close the opened files
fclose(lex_file);
fclose(syn_file);
//complete the parsing
int ret = syntaxAnalyzer->parse();
if(ret == 0) {
if(strcmp(target, "osx") == 0) {
if(strcmp(abi, "macho32") == 0) {
CodeGenerator_macho32_osx *c = new CodeGenerator_macho32_osx(symbolTable, output);
parseTree->get_root()->accept(c);
c->write_exit();
c->write_code();
}
else if(strcmp(abi, "macho64") == 0) {
CodeGenerator_macho64_osx *c = new CodeGenerator_macho64_osx(symbolTable, output);
parseTree->get_root()->accept(c);
c->write_exit();
c->write_code();
}
else {
printf("Currently, the compatible Ubuntu formats are:\n\tmacho32\n\tmacho64\n");
}
}
else if(strcmp(target, "win") == 0) {
printf("Windows is not currently supported\n");
}
else if(strcmp(target, "ubu") == 0) {
if(strcmp(abi, "macho32") == 0) {
CodeGenerator_macho32_ubu *c = new CodeGenerator_macho32_ubu(symbolTable, output);
parseTree->get_root()->accept(c);
c->write_exit();
c->write_code();
}
else {
printf("Currently, the compatible Ubuntu formats are:\n\tmacho32\n");
}
}
}
fclose(infile);
return 0;
}