Summary Files Commits Branches @commit @diff @stats
path: root / src / blog / sane-explanation-of-compilers / part-1 / regex_parser_simple.cpp
diff options
context:
space:
mode:
1 files changed, 16 insertions, 0 deletions
-rw-r--r--src/blog/sane-explanation-of-compilers/part-1/regex_parser_simple.cpp16
diff --git a/src/blog/sane-explanation-of-compilers/part-1/regex_parser_simple.cpp b/src/blog/sane-explanation-of-compilers/part-1/regex_parser_simple.cpp
new file mode 100644
index 0000000..c0a5a4e
--- /dev/null
+++ b/src/blog/sane-explanation-of-compilers/part-1/regex_parser_simple.cpp
@@ -0,0 +1,16 @@
+bool matchesp(string str) {
+ string regex = "acce_t";
+
+ for (int si = 0, ri = 0; si < str.size() && ri < regex.size(); si++, ri++) {
+ while (regex[ri] == '_')
+ if (str[si] == 'n' || str[si] == 'p')
+ si++;
+ else
+ ri++;
+ }
+
+ if (str[si] != regex[ri])
+ return false;
+ }
+ return true;
+}