Lex Version0.2 class Heap

#ifndef _HEAP_H_
#define _HEAP_H_
class Heap {
private:
 int syn[100];//存储词法分析后的符号表
 int head, tail;//游标
public:
 Heap();
 ~Heap();
 int first();//head=0并返回该syn。-1表示失败。
 int prev();//head前移并返回该syn。-1表示失败。
 int next();//head后移并返回该syn。-1表示失败。
 bool append(int);//加入syn
};
#endif

#include “StdAfx.h”
#include “Heap.h”

Heap::Heap()
{
 for(int i = 0; i < 100; i++)
  syn[i] = -1;
 head = tail = 0;
}

Heap::~Heap()
{

}

int Heap::first()
{
 head = 0;
 return syn[head];
}

int Heap::prev()
{
 if(head == 0)
  return -1;
 return syn[–head];
}

int Heap::next()
{
 if(head == tail – 1)
  return -1;
 return syn[++head];
}

bool Heap::append(int tempsyn)
{
 if(tail >= 200)
  return false;
 syn[tail++] = tempsyn;
 return true;
}



Comments are closed.