Giter Club home page Giter Club logo

mini_java's Introduction

An implementaion of Java-OOP mini-language

This is a homework for functional programming course.

License: LGPL

Author: Bozhnyuk Alexander, [email protected]

Замечания.

    1. Ключевые слова не могут являться именами классов
    1. Метод main ничего в себя не принимает, является просто точкой входа программы. Метод main - единственный.
    1. i++ и ++i эквиваленты i = i + 1. Ничего более
    1. StackOverflow не детектится
    1. Многомерные массивы не поддерживаются
    1. Приведение типов через () не поддерживается.
    1. Метод equals при сравнении объектов вызывается в случае, если он переопределен. В противном случае происходит непосредственное сравнение ссылок.
    1. Работа с реплом: запуск факториала
    > int fac1(int acc, int n) {if (n <= 1) return acc; else return fac1(acc * n, n - 1); }@
    > int fac(int n) {return fac1(1, n);}@
    > fac(5)@
    > Result: VInt (120)
    
    1. Работа с реплом: ArrayTypeMismatchException:
    > Object[] x = new Object[3];@    
    Statement evaluated
    > x[0] = new Circle(5);@
    ArrayStoreException
    > Object[] y = new Figure[3];@
    Statement evaluated
    > y[0] = new QuickSorter();@
    Wrong assign type!
    
    
    1. Работа с реплом: show_available_methods@
    > int id(int n) {return n;}@                    
    Method added
    > int square(int n) {return n*n;}@
    Method added
    > show_available_methods@
    Current available methods:
    "int square(int n) {return n*n;}"
    "int id(int n) {return n;}"
    

Features done:

  • 1 Загрузка классов
  • 2 Стандартные конструкции: ветвления, циклы
  • 3 Стандартные типы: числа, строки и операции с ними
  • 4 Стандартный тип массива и операции с ним.
  • 5 ООП: классы, публичные методы, публичные поля.
  • 6 ООП: стандартный базовый класс Object
  • 7 ООП: наследование
  • 8 Рекурсия
  • 9 Тесты, в том числе и тест паттерна Visitor, требуемый тест на массивы
  • 10 REPL и набор классов для стандартной библиотеки.
  • 11 Типы данных - boolean и char как полноценные
  • 12 Cтроки - теперь полноценные объекты класса String, загружаемого заранее.

Класс Object:

public class Object {
    public boolean equals(Object obj) {
        return this == obj;
    }
    
    public String toString() {
    	return "Object";
    }
}

Класс String:

final class String {
    public final char[] value;

    public String() {
        this.value = new char[0];
    }

    public String(String original) {
        this.value = original.value;
    }

    public String(char[] value) {
        this.value = new char[value.length];
        for (int i = 0; i < value.length; i++) {
            this.value[i] = value[i];
        }
    }

    public int length() {
        return value.length;
    }

    public String concat(String str) {
        int otherLen = str.length();
        if (str.length() == 0) {
            return this;
        }
        int len = value.length;
        char[] newValue = new char[len + otherLen];
        for (int i = 0; i < len; i++) {
            newValue[i] = value[i];
        }
        for (int j = len; j < len + otherLen; j++) {
            newValue[j] = str.value[j - len];
        }
        return new String(newValue);
    }

    public boolean startsWith(String prefix, int toffset) {
        char[] ta = value;
        char[] pa = prefix.value;
        int pc = prefix.length();
        if ((toffset < 0) || (toffset > value.length - pc)) {
            return false;
        }
        for (int i = toffset; i < toffset + pc; i++) {
            if (ta[i] != pa[i - toffset]) {
                return false;
            }
        }
        return true;
    }

    public boolean startsWith(String prefix) {
        return startsWith(prefix, 0);
    }
}

mini_java's People

Contributors

bozhnyukalex avatar i1ya-kznts9v avatar kakadu avatar miloserdova-l avatar vladislav-miroshnikov avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.