1.1 输出代码的函数设计

1.1.1 输出头文件

  • 函数接口

    1. void outputHeadFileList()
  • 返回值

    1. void
  • 参数列表

  • 函数伪代码

    void outputHeadFileList() {
      for (遍历mp_headFileShow) {
          //遍历
          if(属性值为true) {
              //如果涉及该头文件的过程或函数出现
              cout << "#include<" << it->key << ">" << endl;
              //输出头文件
              属性值设为false;
          }
      }
      无条件输出‘#include<stdbool.h>’头文件
    }
    

1.1.2 输出常数列表

  • 函数接口

    void outputConstList(vector<string> &constIdList, vector<string> &constTypeList, vector<string> &constValueList, int retract=0)
    
  • 返回值

     void
    
  • 参数列表 | 参数 | 描述 | | —- | —- | | vector &constIdList | 常数标识符列表 | | vector &constTypeList | 常数类型列表 | | vector &constValueList | 常数取值列表 | | int retract | 语句前的制表符个数(缩进控制) |

  • 函数伪代码

    void outputConstList(vector<string> &constIdList, vector<string> &constTypeList, vector<string> &constValueList, int retract=0) {
      for (遍历这三个列表) {
          输出retract个制表符;
          cout << "const " << constTypeList[i] << " " <<  constIdList[i] << "=" << constValueList[i] << ";" <<endl;
          //将三个列表的信息组装成常量定义并输出
      }
    }
    

    1.1.3 输出变量列表

  • 函数接口

    void outputVariantList(vector<string> &variantIdList, vector<string> &variantTypeList, vector< vector<int> > &arraySizeList, int retract=0)
    
  • 返回值

     void
    
  • 参数列表 | 参数 | 描述 | | —- | —- | | vector &variantIdList | 变量标识符列表 | | vector &variantTypeList | 变量类型列表 | | vector< vector<int> > &arraySizeList | 变量各维大小列表 | | int retract | 语句前的制表符个数(缩进控制) |

  • 函数伪代码
    void outputVariantList(vector<string> &variantIdList, vector<string> &variantTypeList, vector< vector<int> > &arraySizeList, int retract=0) {
      遍历这三个列表 {
          输出retract个制表符;
          cout << variantTypeList[i] << " " << variantIdList[i];
          遍历数组各维大小
          cout << "[" << arraySizeList[i][j] << "]";
          cout << ";" << endl;
          //将三个列表的信息组装成变量定义并输出
      }
    }
    

1.1.4 输出子程序接口声明

  • 函数接口

    void outputSubproDec(subproDec &tmp,int flag=0)
    
  • 返回值

     void
    
  • 参数列表 | 参数 | 描述 | | —- | —- | | subproDec &tmp | 子程序声明结构体 | | int flag | flag==0时表示接口声明,flag==1时表示定义时的子程序头,前者比后者在尾部多一个分号 |

  • 函数伪代码
    void outputSubproDec(subproDec &tmp, int flag) {//flag==0时表示接口声明,flag==1时表示定义时的子程序头  
      输出返回值类型、空格、子程序名、左括号;  
      遍历形参列表 {  
          if (不是第一个形参)  
              输出逗号、空格  
          输出形参类型、空格;  
          if (当前形参是传引用参数)  
              输出"*";  
          输出形参标识符;  
      }  
      输出右括号;  
      if (flag == 0)  
          输出分号;  
      输出换行;  
    }
    

1.1.5 输出子程序接口声明列表

  • 函数接口

    void outputSubproDecList()
    
  • 返回值

     void
    
  • 参数列表

  • 函数伪代码

    void outputSubproDecList() {
      输出原PASCAL主程序对应C的程序头;
      vector< struct subproDec > &vec = v_subproDecList;
      遍历子程序定义列表vec
      调用outputSubproDec输出每一个子程序声明(最后添加分号);
    }
    

1.1.6 输出语句

  • 函数接口

    void outputStatement(pair<string,int> &tmp)
    
  • 返回值

     void
    
  • 参数列表 | 参数 | 描述 | | —- | —- | | pair &tmp | 语句及其前的制表符个数 |

  • 函数伪代码
    void outputStatement(pair<string,int> &tmp) {
      输出tmp.second个制表符;
      输出语句;
      输出换行;
    }
    

1.1.7 输出语句列表

  • 函数接口

    void outputStatementList(vector< pair<string,int> > &vec)
    
  • 返回值

     void
    
  • 参数列表 | 参数 | 描述 | | —- | —- | | vector< pair > &vec | 语句列表 |

  • 函数伪代码
    void outputStatementList(vector< pair<string,int> > &vec) {
      遍历语句列表中的每一条语句
      调用outputStatement输出每一条语句;
      vec.clear();
      //清空
    }
    

1.1.8 输出子程序定义列表

  • 函数接口

    void outputSubproDefList()
    
  • 返回值

     void
    
  • 参数列表

  • 函数伪代码

    void outputSubproDefList(){    
      输出pascal主程序对应的C程序头、换行;  
      输出左大括号、换行;  
      输出pascal主程序对应的C程序体;  
      输出右大括号、换行;  
      遍历子程序定义列表{    
          调用outputSubproDec输出子程序头(后面不需要添加分号);  
               输出左大括号、换行;   
          调用outputConstList输出全局常量定义列表;  
          调用outputVariantList输出全局变量定义列表;  
          调用outputStatementList输出程序体语句列表;  
              输出右大括号、换行、换行;    
      }    
    }
    

1.1.9 输出main函数体

  • 函数接口

    void ouputMain()
    
  • 返回值

     void
    
  • 参数列表

  • 函数伪代码

    void ouputMain() {
      cout << "int main()\n{\tmain_function();\n\treturn 0;\n}\n";
    }