main() regular_expression regexp while (input_regexp(std::cin, regexp)) const language l = generate(regexp) ouput_language(std::cout, l)
read()
, gen-language()
, or write()
.
regular-expression
? What's a language?
gen-language(regexp) if is-simple-regexp(regexp) return gen-simple-language(regexp) else regexp-f, regexp-r = split-regexp(regexp) return cross-product( gen-language(regexp-f), gen-language(regexp-r))
is-simple-regexp()
gen-simple-language()
split-regexp()
cross-product()
then we're done.
gen-language()
work? Is it correct?
cross-product()
is straightforward.
is-simple-regexp()
and split-regexp()
are related.
split-regexp()
splits after the first simple regular expression.
gen-simple-language()
assumes simple regular expressions.
simple-regexp-end()
returns a pointer to the end of the
first simple regular expression.
is-simple-regexp(R) return size(R) == simple-regexp-end(R) split-regexp(R) e = simple-regexp-end(R) return R[0, e - 1], R[e, size(R)]
simple-regexp-end()
gen-simple-language()
?
R
*
R
|
R1 R2
(
R1 R2 ... )
simple-regexp-end()
simple-regexp-end(regexp) case regexp[0] of '?' e = simple-regexp-end(regexp + 1) '*' e = simple-regexp-end(regexp + 1) '|' e = simple-regexp-end(regexp + 1) e = simple-regexp-end(regexp + e) '(' e = 1 while regexp[e] != ')' e = simple-regexp-end(regexp + e) else e = 1 return e
simple-regexp-end()
.
(
R1 R2 ... )
return gen-language(regexp[1, size(regexp)-1])
|
R1 R2
e1 = simple-regexp-end(regexp + 1) e2 = simple-regexp-end(regexp + e1) return union(gen-simple-language(regexp + e1) gen-simple-language(regexp + e2))
a
.
a
.
a
works, get a a
working.
Programs should handle empty input.$ ./pgm < /dev/null
Programs should handle garbage input.$ ./pgm < pgm
"" { } ( ) { } a a { a a } a b { a b } ? a { "", a } | a b { a, b } * a { "", a, a a } | a ( ) { "", a } ? a ? a { "", a, a a }
$ ./pgm < pgm
"Can input be like this...?"is "Yes."
../../test-code: line 165: 10192 Segmentation fault ... ../../test-code: line 133: 10060 Killed ...
// int qmarks = 0; // int stars = 0; // int bars = 0; /* int qmarks = 0; int stars = 0; int bars = 0; */
// Output an error if the open paren // exceeds the close paren. bool parenerror (int op, int cl)
// Return op ≤ cl. // Print an error if op > cl. bool parenerror (int op, int cl)