summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.classpath7
-rw-r--r--.project17
-rw-r--r--.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--lib/automaton.jarbin0 -> 176313 bytes
-rw-r--r--src/regex/RegexTest.java47
5 files changed, 83 insertions, 0 deletions
diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..d43e807
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="lib" path="lib/automaton.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/.project b/.project
new file mode 100644
index 0000000..f372b55
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>RegexTest</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..a698e59
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/lib/automaton.jar b/lib/automaton.jar
new file mode 100644
index 0000000..ba583b3
--- /dev/null
+++ b/lib/automaton.jar
Binary files differ
diff --git a/src/regex/RegexTest.java b/src/regex/RegexTest.java
new file mode 100644
index 0000000..097e4f7
--- /dev/null
+++ b/src/regex/RegexTest.java
@@ -0,0 +1,47 @@
+/*
+ * provide names and student id numbers here
+ */
+
+package regex;
+
+import dk.brics.automaton.RegExp;
+import dk.brics.automaton.RunAutomaton;
+
+public class RegexTest {
+
+ private final RunAutomaton r;
+
+ public RegexTest(String regex) {
+ System.out.println("regular expression = " + regex);
+ r = new RunAutomaton(new RegExp(regex).toAutomaton());
+ }
+
+ public long dfaMatch(String input, int index) {
+ long start = System.nanoTime();
+ int length = r.run(input, index);
+ long end = System.nanoTime();
+
+ if (length == -1) {
+ System.out.println("No match found!");
+ } else {
+ String s = input.substring(index, index + length);
+ System.out.println("Found: " + s);
+ }
+
+ return end - start;
+ }
+
+ void runTest(String input, int index) {
+ System.out.println("input string = " + input);
+ System.out.println("index = " + index);
+
+ long dfaMatchTime = dfaMatch(input, index);
+ System.out.println("dfaMatchTime " + dfaMatchTime);
+ }
+
+ public static void main(String[] args) {
+ RegexTest exampleRegexTest = new RegexTest("aap");
+ exampleRegexTest.runTest("aap_df34_d asdf sdfd", 0);
+ exampleRegexTest.runTest("a_a_pasdf sdfd", 0);
+ }
+}