开始写代码STEP_3

#ifndef STMT__H_
#define STMT__H_
#include 
<stdio.h>
#include 
"Vector.h"
#include 
"Expression.h"
#include 
"CodeRepo.h"

typedef 
struct Stmt_t CStmt;

typedef 
struct Stmt_VMT{
    
void(*generate)(CStmt*, FILE*);
}
CStmt_VMT;

struct Stmt_t{
    
const CStmt_VMT* vmt;
    
int srcLineNo;
}
;

extern void CStmt_Initialize(CStmt*,int);

extern void CStmt_Generate(CStmt*, FILE*);

#define Stmt_Generate(this,arg) 
           (((CStmt
*)this)->vmt->generate((CStmt*)(this),arg))
#endif

 

 

#include "Stmt.h"

static const CStmt_VMT vmt = { CStmt_Generate };


void CStmt_Initialize(CStmt* this,int no)
{
    ((CStmt
*)this)->vmt = (const CStmt_VMT*)&vmt;
    
this->srcLineNo = no;
}


void CStmt_Generate(CStmt *this, FILE* output)
{
    
    
}

 

 

#include "IfStmt.h"

extern int subprog;

static const CIfStmt_VMT vmt = {CIfStmt_Generate};

void CIfStmt_Initialize(CIfStmt* this,int no,CExpression *cond, Vector* ifpart, Vector* elsepart)
{
    CStmt_Initialize((CStmt
*)this, no);
    ((CStmt
*)(this))->vmt = (const CStmt_VMT*)&vmt;
    
this->ifpart = ifpart;
    
this->elspart = elsepart;
    
this->condition = cond;
}


void CIfStmt_Generate(CIfStmt* this, FILE* output)
{
    
int i;
  
if(subprog){
    fprintf(output, 
"setCursor2 %d ", ((CStmt*)this)->srcLineNo - getRef(((CStmt*)this)->srcLineNo) + 1);
  }

  
else{
    fprintf(output, 
"setCursor %d ", ((CStmt*)this)->srcLineNo - getRef(((CStmt*)this)->srcLineNo));
  }

    
    fprintf(output, 
"If ");
    
if(this->condition != NULL){
        Expression_Generate(
this->condition, output);
    }

      fprintf(output, 
" Then ");
      
    
if(this->ifpart != NULL){
        
for(i = 0; i < size(this->ifpart); i++){
              Stmt_Generate(elementAt(
this->ifpart, i), output);
        }

    }

    
    
if(this->elspart != NULL){
        fprintf(output, 
"Else ");

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

    }


  fprintf(output, 
"End If ");
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

进击的横打

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

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

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

打赏作者

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

抵扣说明:

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

余额充值