开始写代码STEP_4

 

 

#ifndef _DECLARATION_H
#define  _DECLARATION_H
#include 
" Vector.h "
#include 
< stdio.h >
#include 
" Stmt.h "
#include 
" Port.h "

typedef 
struct  Declaration_t CDeclaration;

typedef 
struct  Declaration_VMT {
  
void (*generate)(CDeclaration*, FILE*);
}
CDeclaration_VMT;

struct  Declaration_t {
  
const CDeclaration_VMT *vmt;
  
int srcLineNoBegin;
  
int srcLineNoEnd;
}
;

extern   void  CDeclaration_Initialize(CDeclaration * int int );

extern   void  CDeclaration_Generate(CDeclaration * , FILE * );

#define  Declaration_Generate(this,arg1)
  (((CDeclaration
* )( this )) -> vmt -> generate((CDeclaration * )( this ),arg1))

#endif

 

#include  " Declaration.h "

static   const  CDeclaration_VMT vmt  =   { CDeclaration_Generate } ;

void  CDeclaration_Initialize(CDeclaration  * this int  no1,  int  no2)
{
  ((CDeclaration
*)this)->vmt = (const CDeclaration_VMT*)&vmt;

  
this->srcLineNoBegin = no1;
  
this->srcLineNoEnd = no2;
}


void  CDeclaration_Generate(CDeclaration  * this , FILE  * output)
{
#ifdef DEBUG
  fprintf(output, 
"CDeclaration_Generate ");
#endif
}

 

 

#ifndef _VARIABLE_DECL_H
#define  _VARIABLE_DECL_H
#include 
" Expression.h "
#include 
" Declaration.h "

typedef 
struct  VariableDecl_t CVariableDecl;

typedef 
struct  VariableDecl_VMT {
  
void (*generate)(CVariableDecl*, FILE*);
}
CVariableDecl_VMT;

struct  VariableDecl_t {
  CDeclaration super;
  
char *name;
  CExpression 
*constraint;
  
char *type;
}
;

extern   void  CVariableDecl_Initialize(CVariableDecl * char * , CExpression * char * int int );

extern   void  CVariableDecl_Generate(CVariableDecl * , FILE * );

#endif
#include  < string .h >
#include 
" VariableDecl.h "

static   const  CVariableDecl_VMT vmt  =   { CVariableDecl_Generate } ;

void  CVariableDecl_Initialize(CVariableDecl  * this char   * name, CExpression  * constraint,  char   * type,  int  no1,  int  no2)
{
  CDeclaration_Initialize((CDeclaration
*)this, no1, no2);
  ((CDeclaration
*)this)->vmt = (const CDeclaration_VMT*)&vmt;

  
this->name = name;
  
this->constraint = constraint;
  
this->type = type;
}


void  CVariableDecl_Generate(CVariableDecl  * this , FILE  * output)
{

  fprintf(output, 
"Dim %s"this->name);

  
if(this->constraint != 0){
    Expression_Generate(
this->constraint, output);
  }

  
  
if(!strncmp(this->type, "string"6)){
    fprintf(output, 
" As String ");
  }
else if(!strncmp(this->type, "integer"7)){
    fprintf(output, 
" As Long ");
  }
else{
    fprintf(output, 
" As %s "this->type);
  }

}

 

 

#ifndef _FUNCTION_DECL_H
#define  _FUNCTION_DECL_H
#include 
" Declaration.h "

typedef 
struct  FunctionDecl_t CFunctionDecl;

typedef 
struct  FunctionDecl_VMT {
  
void (*generate)(CFunctionDecl*, FILE*);
}
CFunctionDecl_VMT;

struct  FunctionDecl_t {
  CDeclaration super;
  Vector 
*decls;
  
char *name;
  Vector 
*args;
  
char *retType;
  Vector 
*stmts;
}
;

extern   void  CFunctionDecl_Initialize(CFunctionDecl * char * , Vector * , Vector * char * , Vector * int int );

extern   void  CFunctionDecl_Generate(CFunctionDecl * , FILE * );

#endif
#include  " FunctionDecl.h "

static   const  CFunctionDecl_VMT vmt  =   { CFunctionDecl_Generate } ;

void  CFunctionDecl_Initialize(CFunctionDecl  * this char   * name, Vector  * decls, Vector *  args,  char   * retType, Vector  * stmts,  int  no1,  int  no2) {
  CDeclaration_Initialize((CDeclaration
*)this, no1, no2);
  ((CDeclaration
*)this)->vmt = (const CDeclaration_VMT*)&vmt;

  
this->decls = decls;
  
this->name = name;
  
this->args = args;
  
this->retType = retType;
  
this->stmts = stmts;
}


void  CFunctionDecl_Generate(CFunctionDecl  * this , FILE  * output) {
  
int i, j;
  CDeclaration 
*decl = (CDeclaration*)this;
  
  fprintf(output, 
"Function %s("this->name);

  
if(this->args != 0){
    
for(i = 0; i < size(this->args); i++){
      CPort 
*port = elementAt(this->args, i);
      Port_Generate(port, output);
      
if(i < size(this->args) - 1){
        fprintf(output, 
",");
      }

    }

  }


  fprintf(output, 
") As %s "this->retType);

  fprintf(output, 
"Dim s_(%d) as String ", decl->srcLineNoEnd - decl->srcLineNoBegin + 1);
  
for(i = decl->srcLineNoBegin - 1, j = 0; i < decl->srcLineNoEnd; i++, j++){
    fprintf(output, 
"s_(%3d) = "%3d:%s" ", j, i + 1, getLineAt(i));
  }

  fprintf(output, 
"LoadSrc2 s_ "this->name);  

  
  
if(this->decls != 0){
    
for(i = 0; i < size(this->decls); i++){
      Declaration_Generate(elementAt(
this->decls, i), output);
    }

  }


  fprintf(output, 
"Dim loop_count As Integer ");

  
if(this->stmts != 0){
    
for(i = 0; i < size(this->stmts); i++){
      Stmt_Generate(elementAt(
this->stmts, i), output);
    }

  }


  fprintf(output, 
"End Function ");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的横打

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值