📄 benc.c
字号:
/*File:BenC.c *The main file of this project */#include "Global.h"#include "Scan.h"#include "Parse.h"#include "GenCode.h"/*Allocate Global Variables*/int g_lineno = 0;FILE *g_src_file = NULL;FILE *g_lst_file = NULL;FILE *g_asm_file = NULL;FILE *g_data_file = NULL;FILE *g_bss_file = NULL;int g_error = FALSE; int main(int argc, char **argv){ char codeFile[MAX_PATH]; char cFile[MAX_PATH]; /*syntax tree*/ TreeNode *syntaxTree; /*check arg*/ if (argc != 2) { fprintf(stderr, "Usage: %s <source file name>\n", argv[0]); exit(1); }/*end if (argc != 2)*/ strcpy(codeFile, argv[1]); if (strchr(codeFile, '.') != NULL) { int len = strcspn(codeFile, "."); strncpy(cFile, codeFile, len); cFile[len] = '\0'; }/*end if (strchr(codeFile, '.')!=NULL)*/ else { strcpy(cFile, codeFile); strcat(codeFile, ".c"); }/*end if (strchr(codeFile, '.')!=NULL) else*/ g_src_file = fopen(codeFile, "r"); if (g_src_file == NULL) { fprintf(stderr, "File %s not found!\n", codeFile); exit(1); }/*end if (g_src_file == NULL)*/ strcpy(codeFile, cFile); strcat(codeFile, ".lst"); g_lst_file = fopen(codeFile, "w"); if (g_lst_file == NULL) { fprintf(stderr, "Unable to open %s\n", codeFile); exit(1); }/*end if (g_lst_file == NULL)*/ syntaxTree = (TreeNode*)parse(); fprintf(g_lst_file, "\nSyntax Tree:\n"); printTree(syntaxTree); if (!g_error) { /*do some analyzation*/ fprintf(g_lst_file, "\nBuilding Symbol Table...\n"); buildSymtab(syntaxTree); fprintf(g_lst_file, "\nChecking Types..\n"); typeCheck(syntaxTree); fprintf(g_lst_file, "\nType Checking Finished\n"); if (!g_error) { strcpy(codeFile, cFile); strcat(codeFile, ".s"); g_asm_file = fopen(codeFile, "w"); strcpy(codeFile, cFile); strcat(codeFile, ".d"); g_data_file = fopen(codeFile, "w"); strcpy(codeFile, cFile); strcat(codeFile, ".b"); g_bss_file = fopen(codeFile, "w"); if (g_asm_file == NULL || g_data_file == NULL || g_bss_file == NULL) { fprintf(stderr, "Unable to open %s", codeFile); exit(1); }/*if (g_asm_file == NULL)*/ /*code generation*/ GenHeader(cFile); GenCode(syntaxTree); combineFiles(cFile); fclose(g_asm_file); fclose(g_data_file); fclose(g_bss_file); }/*if (!g_error)*/ else { fprintf(stderr, "Error: There isn't a main function!\n"); } }/*end if(!g_error)*/ fclose(g_src_file); fclose(g_lst_file); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -