Esempio n. 1
0
int main()
{
	FILE *f;
	f=fopen("data/Input.in","r");

	int textLen, patternLen;
	fscanf(f, "%d", &textLen);
	fscanf(f, "%d", &patternLen);

	char *text = (char *)malloc(textLen * sizeof(char));
	char *pattern = (char *)malloc(patternLen * sizeof(char));

	Read_String(text, f);
	Read_String(pattern, f);

	fclose(f);

	printf("NFA\n");
	KMP_Matcher_NFA(text, pattern, textLen, patternLen);

	printf("\nDFA\n");
	KMP_Matcher_DFA(text, pattern, textLen, patternLen);

	return 0;
}
Esempio n. 2
0
int main()
{
	FILE *f;
	f=fopen("in.txt","r");

	int L_String, L_SubString;
	char String[1000];
    char SubString[100];

	fscanf(f,"%d",&L_String);
	fscanf(f,"%d",&L_SubString);

	Read_String(String, L_String, f);
	Read_String(SubString, L_SubString, f);

	KMP_Matcher(String, SubString, L_String, L_SubString);

	fclose(f);
	return 0;
}
Esempio n. 3
0
Object Read_Special (Object port, int konst) {
    Object ret;
    register int c, str;
    register FILE *f;

#define READ_QUOTE(sym) \
    ( ret = Read_Atom (port, konst),\
      konst ? (ret = Const_Cons (ret, Null), Const_Cons (sym, ret))\
           : (ret = Cons (ret, Null), Cons (sym, ret)))

    f = PORT(port)->file;
    str = PORT(port)->flags & P_STRING;
again:
    Reader_Getc;
    switch (c) {
    case EOF:
eof:
        Reader_Tweak_Stream;
        Reader_Error (port, "premature end of file");
    case ';':
        if (Skip_Comment (port) == EOF)
            goto eof;
        goto again;
    case ']':
    case ')':
        SET(ret, T_Special, c);
        return ret;
    case '[':
    case '(':
        return Read_Sequence (port, 0, konst, c);
    case '\'':
        return READ_QUOTE(Sym_Quote);
    case '`':
        return READ_QUOTE(Sym_Quasiquote);
    case ',':
        Reader_Getc;
        if (c == EOF)
            goto eof;
        if (c == '@') {
            return READ_QUOTE(Sym_Unquote_Splicing);
        } else {
            Reader_Ungetc;
            return READ_QUOTE(Sym_Unquote);
        }
    case '"':
        return Read_String (port, konst);
    case '#':
        ret = Read_Sharp (port, konst);
        if (TYPE(ret) == T_Special)
            goto again;
        return ret;
    default:
        if (Whitespace (c))
            goto again;
        Read_Reset ();
        if (c == '.') {
            Reader_Getc;
            if (c == EOF)
                goto eof;
            if (Whitespace (c)) {
                Reader_Ungetc;
                SET(ret, T_Special, '.');
                return ret;
            }
            Read_Store ('.');
        }
        while (!Whitespace (c) && !Delimiter (c) && c != EOF) {
            if (c == '\\') {
                Reader_Getc;
                if (c == EOF)
                    break;
            }
            Read_Store (c);
            Reader_Getc;
        }
        Read_Store ('\0');
        if (c != EOF)
            Reader_Ungetc;
        ret = Parse_Number (port, Read_Buf, 10);
        if (Nullp (ret))
            ret = Intern (Read_Buf);
        return ret;
    }
    /*NOTREACHED*/
}