Example #1
0
File: eo.c Project: linehan/eo
/**
 * eo_prep
 * ```````
 * Validate and prepare the command line arguments for execution.
 *
 * @argc : number of arguments
 * @argv : vector of arguments
 * Return: nothing.
 */
void eo_prep(int argc, char *argv[])
{
        struct routine_t *r;
        static int tree[30];
        int i;

        if (isarg(1, "stat"))
                print_config();
        else if (isarg(1, "init"))
                eo_init();
        else if (isarg(1, "kleene")) {
                if ((kleene(argv[2], argv[3]))) printf("match\n");
                else                            printf("no match\n");
        }
        else {
                /* If there is only one argument, assume the CWD. */
                /*r = (argc==2) ? parse(scwd(), argv[1]) */
                              /*: parse(argv[1], argv[2]);*/

                if (argc == 2)

                        build_tree(tree, argv[1]);
                else
                        build_tree(tree, argv[2]);

                for (i=0; tree[i] != END; i++) {
                        printf("%s (%d)\n", op_name[tree[i]], tree[i]);
                }
                return;

                eo_process(r);
        }

        return;
}
Example #2
0
NFA::NFA(std::string postfixRegex)
{

	std::queue<NFA*> nfaQueue;

	for (auto it = postfixRegex.cbegin();
	it != postfixRegex.cend(); ++it)
	{
		switch (*it) {
		case '*': {
			NFA *n = nfaQueue.front();
			nfaQueue.pop();
			nfaQueue.push(kleene(n));
			break;
		}
		case '&': {
			NFA *left = nfaQueue.front();
			nfaQueue.pop();
			NFA *right = nfaQueue.front();
			nfaQueue.pop();
			nfaQueue.push(concate(left, right));
			break;
		}
		case '|': {
			NFA *left = nfaQueue.front();
			nfaQueue.pop();
			NFA *right = nfaQueue.front();
			nfaQueue.pop();
			nfaQueue.push(alternate(left, right));
			break;
		}
		default: {
			nfaQueue.push(new NFA(*it));
			break;
		}}
	}
	NFA *nfa = nfaQueue.front();
	nfaQueue.pop();
	assert(nfaQueue.empty());
	start = nfa->start;
	end = nfa->end;
}