#include "program.hpp"

Program::~Program()
{
    while (first) {
        Item *next = first->next;
        delete first;
        first = next;
    }
}

void Program::Add(const rule &r)
{
    Item *p = new Item(r);

    if (last)
        last->next = p;
    else
        first = p;

    last = p;
}

const rule *Program::Find(int state, char symbol) const
{
    for (const Item *p = first; p; p = p->next)
        if (p->data.state == state && p->data.read == symbol)
            return &p->data;

    return 0;
}
