summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/encrox/automaten/Core.java262
-rwxr-xr-xsrc/com/encrox/automaten/Schlange.java56
-rwxr-xr-xsrc/com/encrox/automaten/Stapel.java54
3 files changed, 372 insertions, 0 deletions
diff --git a/src/com/encrox/automaten/Core.java b/src/com/encrox/automaten/Core.java
new file mode 100755
index 0000000..3ec994f
--- /dev/null
+++ b/src/com/encrox/automaten/Core.java
@@ -0,0 +1,262 @@
+package com.encrox.automaten;
+
+public class Core {
+
+ public static void main(String args[]) {
+ System.out.println(isOkNormal("z"));
+ System.out.println(isOk("z"));
+ }
+
+ public static boolean isOkNormal(String str) {
+ boolean out = false;
+ char current;
+ Schlange schlange = new Schlange();
+ for(int i = 0, len = str.length(); i<len; i++) {
+ schlange.anhaengen(str.charAt(i));
+ }
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'e') {
+ out = false;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ }
+ }
+ }
+ }
+ } else if(current == 'k') {
+ out = false;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ } else if(current == '0') {
+ out = false;
+ } else if(current == 'e') {
+ out = false;
+ out = false;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'e') {
+ out = false;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ }
+ }
+ }
+ }
+ } else if(current == 'k') {
+ out = false;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ } else if(current == '0') {
+ out = false;
+ } else if(current == 'e') {
+ out = false;
+ out = false;
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ } else if(current == '-') {
+ if(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current == 'z') {
+ out = true;
+ while(!schlange.istLeer()) {
+ current = (char)schlange.entnehmen();
+ if(current != '0' && current != 'z')
+ out = false;
+ }
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return out;
+ }
+
+ public static boolean isOk(String str) {
+ Schlange schlange = new Schlange();
+ for(int i = 0, len = str.length(); i<len; i++) {
+ schlange.anhaengen(str.charAt(i));
+ }
+ char c = (char)schlange.entnehmen();
+ if(c == '-') {
+ return a(schlange);
+ } else if(c == 'z') {
+ return b(schlange);
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean a(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ if((char)schlange.entnehmen() == 'z') {
+ return b(schlange);
+ }
+ }
+ return false;
+ }
+
+ public static boolean b(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == 'e') {
+ return e(schlange);
+ } else if(c == 'k') {
+ return c(schlange);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean c(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == '0') {
+ return c(schlange);
+ } else if(c == 'z') {
+ return f(schlange);
+ }
+ }
+ return false;
+ }
+
+ public static boolean f(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == 'z') {
+ return f(schlange);
+ } else if(c == '0') {
+ return c(schlange);
+ } else if(c == 'e') {
+ return e(schlange);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean e(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == 'z') {
+ return h(schlange);
+ } else if(c == '-') {
+ return g(schlange);
+ }
+ }
+ return false;
+ }
+
+ public static boolean g(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ if((char)schlange.entnehmen() == 'z') {
+ return h(schlange);
+ }
+ }
+ return false;
+ }
+
+ public static boolean h(Schlange schlange) {
+ if(!schlange.istLeer()) {
+ char c = (char)schlange.entnehmen();
+ if(c == '0' || c == 'z') {
+ return h(schlange);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/src/com/encrox/automaten/Schlange.java b/src/com/encrox/automaten/Schlange.java
new file mode 100755
index 0000000..c5b7f65
--- /dev/null
+++ b/src/com/encrox/automaten/Schlange.java
@@ -0,0 +1,56 @@
+package com.encrox.automaten;
+
+public class Schlange {
+
+ Schlange next;
+ Object inhalt;
+
+ public Schlange(){
+
+ }
+
+ private int zaehlen(){
+ if (next == null) return 0;
+ else return 1+next.zaehlen();
+ }
+
+ public boolean istLeer(){
+ if (zaehlen()==0) return true;
+ else return false;
+ }
+
+ public void anhaengen(Object i){
+ if (next == null){
+ Schlange element = new Schlange();
+ element.inhalt=i;
+ next = element;
+ }
+ else next.anhaengen(i);
+ }
+
+ public Object inhaltGeben(){
+ if (next != null) return next.inhalt;
+ else return null;
+ }
+
+ public Object entnehmen(){
+ if (next != null){
+ Object i = next.inhalt;
+ next = next.next;
+ return i;
+ }
+ return null;
+ }
+
+ public String ausgeben(){
+ String s="";
+ if (inhalt != null){
+ s = s+inhalt.toString()+"\n";
+ }
+ if (next != null){
+ s = s + next.ausgeben();
+ }
+ return s;
+ }
+
+}
diff --git a/src/com/encrox/automaten/Stapel.java b/src/com/encrox/automaten/Stapel.java
new file mode 100755
index 0000000..a4c5ee9
--- /dev/null
+++ b/src/com/encrox/automaten/Stapel.java
@@ -0,0 +1,54 @@
+
+package com.encrox.automaten;
+
+public class Stapel {
+
+ Object inhalt;
+ Stapel next;
+
+ private int zaehlen(){
+ if (next == null) return 0;
+ else return 1+next.zaehlen();
+ }
+
+ public Stapel(){
+ }
+
+ public boolean istLeer(){
+ if (zaehlen()==0) return true;
+ else return false;
+ }
+
+ public void ablegen(Object i){
+ Stapel element = new Stapel();
+ element.inhalt = i;
+ element.next = next;
+ next = element;
+ }
+
+ public Object inhaltGeben(){
+ if (next != null) return next.inhalt;
+ else return null;
+ }
+
+ public Object entnehmen(){
+ if (next != null){
+ Object i = next.inhalt;
+ next = next.next;
+ return i;
+ }
+ return null;
+ }
+
+ public String ausgeben(){
+ String s="";
+ if (inhalt != null){
+ s = s+inhalt.toString()+"\n";
+ }
+ if (next != null){
+ s = s + next.ausgeben();
+ }
+ return s;
+ }
+
+}