diff --git a/lexer/array_max.mj b/lexer/array_max.mj new file mode 100644 index 0000000000000000000000000000000000000000..64808e033be84925e0d8bae60e80bb60625efa0e --- /dev/null +++ b/lexer/array_max.mj @@ -0,0 +1,32 @@ +class ArrayMax { + public static void main(String[] args) { + ArrayMax tmp = new ArrayMax(); + + int a[] = new int[10]; + int i = 0; + while(i < 10) { + a[i] = System.in.read(); + i = i + 1; + } + + System.out.write(tmp.max(a, 10)); + System.out.flush(); + } + + /* + Calculates maximal value of array a + */ + public int max(int[] a, int length) { + if(length <= 0) return -1; + int max = a[0]; + int i = 1; + while(i < length) { + if(a[i] > max) { + max = a[i]; + } + i = i + 1; + } + return max; + } +} + diff --git a/lexer/array_max.mj.out b/lexer/array_max.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..33a44ee7a959ac09dd343b6aeea1db4e652993a2 --- /dev/null +++ b/lexer/array_max.mj.out @@ -0,0 +1,164 @@ +class +identifier ArrayMax +{ +public +static +void +identifier main +( +identifier String +[ +] +identifier args +) +{ +identifier ArrayMax +identifier tmp += +new +identifier ArrayMax +( +) +; +int +identifier a +[ +] += +new +int +[ +integer literal 10 +] +; +int +identifier i += +integer literal 0 +; +while +( +identifier i +< +integer literal 10 +) +{ +identifier a +[ +identifier i +] += +identifier System +. +identifier in +. +identifier read +( +) +; +identifier i += +identifier i ++ +integer literal 1 +; +} +identifier System +. +identifier out +. +identifier write +( +identifier tmp +. +identifier max +( +identifier a +, +integer literal 10 +) +) +; +identifier System +. +identifier out +. +identifier flush +( +) +; +} +public +int +identifier max +( +int +[ +] +identifier a +, +int +identifier length +) +{ +if +( +identifier length +<= +integer literal 0 +) +return +- +integer literal 1 +; +int +identifier max += +identifier a +[ +integer literal 0 +] +; +int +identifier i += +integer literal 1 +; +while +( +identifier i +< +identifier length +) +{ +if +( +identifier a +[ +identifier i +] +> +identifier max +) +{ +identifier max += +identifier a +[ +identifier i +] +; +} +identifier i += +identifier i ++ +integer literal 1 +; +} +return +identifier max +; +} +} +EOF diff --git a/lexer/combinations.mj b/lexer/combinations.mj new file mode 100644 index 0000000000000000000000000000000000000000..f139f59780789be0c32aafa78d385a5d89ad0e69 --- /dev/null +++ b/lexer/combinations.mj @@ -0,0 +1,4 @@ +switch protected a 21 _ u ++ 1-b +package package packagee hj 123 __ ! +ja bool break ; ; ; = a(()) +14360 diff --git a/lexer/combinations.mj.out b/lexer/combinations.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..3705f56dd13c32a9b4eabe5b7a0f9eb8b50bf376 --- /dev/null +++ b/lexer/combinations.mj.out @@ -0,0 +1,31 @@ +switch +protected +identifier a +integer literal 21 +identifier _ +identifier u +++ +integer literal 1 +- +identifier b +package +package +identifier packagee +identifier hj +integer literal 123 +identifier __ +! +identifier ja +identifier bool +break +; +; +; += +identifier a +( +( +) +) +integer literal 14360 +EOF diff --git a/lexer/fibonacci.mj b/lexer/fibonacci.mj new file mode 100644 index 0000000000000000000000000000000000000000..79f81e29e359cf428718c11f8224a40c6cfad121 --- /dev/null +++ b/lexer/fibonacci.mj @@ -0,0 +1,15 @@ +class Fibonacci { + public static void main(String[] args) { + Fibonacci tmp = new Fibonacci(); + int a = System.in.read(); + + System.out.write(tmp.fibonacci(a)); + System.out.flush(); + } + + public int fibonacci(int n) { + if(n <= 1) return n; + else return fibonacci(n - 1) + fibonacci(n - 2); + } +} + diff --git a/lexer/fibonacci.mj.out b/lexer/fibonacci.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..ba68c28ddadb6a75f612d9cc4008cc4b03b1fba8 --- /dev/null +++ b/lexer/fibonacci.mj.out @@ -0,0 +1,92 @@ +class +identifier Fibonacci +{ +public +static +void +identifier main +( +identifier String +[ +] +identifier args +) +{ +identifier Fibonacci +identifier tmp += +new +identifier Fibonacci +( +) +; +int +identifier a += +identifier System +. +identifier in +. +identifier read +( +) +; +identifier System +. +identifier out +. +identifier write +( +identifier tmp +. +identifier fibonacci +( +identifier a +) +) +; +identifier System +. +identifier out +. +identifier flush +( +) +; +} +public +int +identifier fibonacci +( +int +identifier n +) +{ +if +( +identifier n +<= +integer literal 1 +) +return +identifier n +; +else +return +identifier fibonacci +( +identifier n +- +integer literal 1 +) ++ +identifier fibonacci +( +identifier n +- +integer literal 2 +) +; +} +} +EOF diff --git a/lexer/gcd.mj b/lexer/gcd.mj new file mode 100644 index 0000000000000000000000000000000000000000..e96e7362c4f3626f32ad834e29b9fe24bd5b3737 --- /dev/null +++ b/lexer/gcd.mj @@ -0,0 +1,24 @@ +class GCD { + public static void main(String[] args) { + GCD tmp = new GCD(); + int a = System.in.read(); + int b = System.in.read(); + + System.out.write(tmp.gcd(a,b)); + System.out.flush(); + } + + public int gcd(int a, int b) { + if(a <= 0 && b <= 0) return -1; + + int t; + while(b != 0) { + t = a % b; + a = b; + b = t; + } + + return a; + } +} + diff --git a/lexer/gcd.mj.out b/lexer/gcd.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..8b16900a345cdb8680b511f5fb26396aa2860eda --- /dev/null +++ b/lexer/gcd.mj.out @@ -0,0 +1,125 @@ +class +identifier GCD +{ +public +static +void +identifier main +( +identifier String +[ +] +identifier args +) +{ +identifier GCD +identifier tmp += +new +identifier GCD +( +) +; +int +identifier a += +identifier System +. +identifier in +. +identifier read +( +) +; +int +identifier b += +identifier System +. +identifier in +. +identifier read +( +) +; +identifier System +. +identifier out +. +identifier write +( +identifier tmp +. +identifier gcd +( +identifier a +, +identifier b +) +) +; +identifier System +. +identifier out +. +identifier flush +( +) +; +} +public +int +identifier gcd +( +int +identifier a +, +int +identifier b +) +{ +if +( +identifier a +<= +integer literal 0 +&& +identifier b +<= +integer literal 0 +) +return +- +integer literal 1 +; +int +identifier t +; +while +( +identifier b +!= +integer literal 0 +) +{ +identifier t += +identifier a +% +identifier b +; +identifier a += +identifier b +; +identifier b += +identifier t +; +} +return +identifier a +; +} +} +EOF diff --git a/lexer/keywords.mj b/lexer/keywords.mj new file mode 100644 index 0000000000000000000000000000000000000000..c0d30f12279c8a154f6a6ad6bbb134d62925ef0d --- /dev/null +++ b/lexer/keywords.mj @@ -0,0 +1 @@ +abstract; assert; boolean; break; byte; case; catch; char; class; const; continue; default; double; do; else; enum; extends; false; finally; final; float; for; goto; if; implements; import; instanceof; interface; int; long; native; new; null; package; private; protected; public; return; short; static; strictfp; super; switch; synchronized; this; throws; throw; transient; true; try; void; volatile; while diff --git a/lexer/keywords.mj.out b/lexer/keywords.mj.out new file mode 100644 index 0000000000000000000000000000000000000000..6c61a904f8e01cdcfdf59f7425f05b85556a9910 --- /dev/null +++ b/lexer/keywords.mj.out @@ -0,0 +1,106 @@ +abstract +; +assert +; +boolean +; +break +; +byte +; +case +; +catch +; +char +; +class +; +const +; +continue +; +default +; +double +; +do +; +else +; +enum +; +extends +; +false +; +finally +; +final +; +float +; +for +; +goto +; +if +; +implements +; +import +; +instanceof +; +interface +; +int +; +long +; +native +; +new +; +null +; +package +; +private +; +protected +; +public +; +return +; +short +; +static +; +strictfp +; +super +; +switch +; +synchronized +; +this +; +throws +; +throw +; +transient +; +true +; +try +; +void +; +volatile +; +while +EOF diff --git a/lexer/unknown_char.invalid.mj b/lexer/unknown_char.invalid.mj new file mode 100644 index 0000000000000000000000000000000000000000..a403df7cec23300e56c9fc2cd52ca153d8524f35 --- /dev/null +++ b/lexer/unknown_char.invalid.mj @@ -0,0 +1 @@ +void #method() {}