Archive for 21 11 月, 2009

Lex Version0.2 class Heap

星期六, 21 11 月, 2009

#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;
}

#pragma指令参考资料

星期六, 21 11 月, 2009

http://hi.baidu.com/sodumeng/blog/item/66df761a7330b9ddac6e75eb.html