GithubHelp home page GithubHelp logo

edcuba / ifj Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 248 KB

Simple Java like interpreter written in C

License: GNU General Public License v3.0

Makefile 0.26% C 96.59% C++ 2.76% CMake 0.39%
c interpreter

ifj's Introduction

Hey there! 👨🏽‍💻

I'm a Software Engineer curious about AI & Machine Learning (especially GNNs, GANs, RL, and DL), Data Analysis, Cybersecurity, and Quantum Computing. I'm a BUT alumni, now at UZH, also a former Dreamer and Red Hat.

I work at CERN Openlab, exploring the overlaps of High Performance Computing, Machine Learning and Quantum Computing, and playing with Graph Neural Networks for improving particle reconstructions at the CMS Experiment.

Contact

You can find me on LinkedIn, Twitter, or reach out at eduard.cuba

I ❤️ Open Source!

I contributed to open-source projects in:

and published a series of my own projects like Faqtie, have a look!

ifj's People

Contributors

edcuba avatar h00n24 avatar halficek avatar kubaj avatar noname115 avatar

Watchers

 avatar  avatar  avatar  avatar

ifj's Issues

cmake version

@kubaj je minimálna verzia cmake nejak opodstatnená?
druhá vec, nechceme vyhodiť normálny makefile, nech to nie je duplicitne?

Valgrind identifikator

@edynox

// Nedefinovanie datove typu
// v argumente funkcie
// 2

class Main
{
	static void run()
	{
		int a = 5;
		int b = 10;
		test(a, b);
	}

	static void test(int a, b)
	{

	}
}

Valgrind - readInt

@kubaj
Skontroluj si valgrind, po tvojom commite to dava error vo vsetkych 4 testoch. Asi to bude rovnaka chyba, nieco s tvojim buffrom tam dava chybu.

// Program zo zadania IFJ16

class Main
{
    static void run()
    {
        int a;
        ifj16.print("Zadejte cislo pro vypocet faktorialu: ");
        a = ifj16.readInt();
        int vysl;
        if (a < 0)
        { // nacitani zaporneho cisla nemusite podporovat
            ifj16.print("Faktorial nelze spocitat!\n"); }
        else
        {
            vysl = 1;
            while (a > 0)
            {
                vysl = vysl * a; a = a - 1;
            }

            ifj16.print("Vysledek je: " + vysl + "\n");
        }
    }
}
// Program zo zadania IFJ16

class Main
{
    static void run()
    {
        int a;
        int vysl;
        int neg;
        ifj16.print("Zadejte cislo pro vypocet faktorialu: ");
        a = ifj16.readInt();

        if (a < 0)
        {
            ifj16.print("Faktorial nelze spocitat!\n");
        }
        else
        {
            vysl = factorial(a);
            neg = 0 - vysl;
            
            ifj16.print("Vysledek: " + vysl);
            ifj16.print(" (zaporny: " + neg+ ")\n");
        }
    }

    static int factorial(int n) // Definice funkce pro vypocet faktorialu
    {
        int temp_result;
        int decremented_n = n - 1;
        if (n < 2)
        {
            return 1;
        }
        else
        {
            temp_result = factorial(decremented_n);
            temp_result = n * temp_result;
        }

        return temp_result;
    }
}
// Komplexny program pre aritmeticke operacia
//

class Main
{
	static double s = 1.25;

	static void run()
	{
		double d = ifj16.readDouble();
		int i = ifj16.readInt();

		ifj16.print("Nacital som: " + d + " , " + i + "\n");
		ifj16.print("Zavolam funkciu Add" + "\n");

		d = Add(i, d);
		ifj16.print("Vysledok Add: " + d + "\n");
	}

	static double Add(int a, double b)
	{
		ifj16.print(a + " " + b + " " + s + "\n");
		double c = (a * 2) - 5 + (b * s);

		ifj16.print(c + "\n");
		return c;
	}
}
//Vstup 2147483648 - chyba 7

class Main
{
	static void run()
	{
		int a = ifj16.readInt();
		ifj16.print(a + "\n");
	}
}

Zle navratove kody

@edynox @halficek

Nastavit syntakticke chyby (2) pri:

class class Main
{
	static void run()
	{

	}
}
class Main
{
	static void int run()
	{

	}
}

FIXED

ifj16 find

@H00N24
Mal by si mi vratit -1, kedze si retazec nenasiel, ale vratis 32.

// Testovanie funkcie ifj16 find

class Main
{
	static void run()
	{
		int a = ifj16.find("Dlhy test", "text");
		ifj16.print(a + "\n");
	}
}

for v Main_run()

@edynox
Ked je For v run-e tak ti dam NULL kontext ako top zasobnika. Sa to cele zosipe :)

LEXA - wrong token identification

@kubaj
Cauko, máme segfaulty kvôli lexa.
double a = 1.9; funguje
double a = 0.9; sa zosype - 0.9 identifikuje ako integer a potom nám to padne keď to čítame (skús si to hodit do kódu)

Taktiež ak v riadku nie sú ukončené úvodzovky -

String a = "a
";

spraví segfault
ifj16.print("avas"+"\") - (chýba "n" v "\n") sa taktiež zosype

Samples not working

Sample syntax.ifj16 get error:
Error: line 3 unexpected identifier ","
Sample lexa1.ifj16 get error:
Error: line 9 unexpected identifier "unknown"
Works only syna:

Fib recursively: 987
Fib iteratively: 987
OK: 987 == 987
********************************************************************************
**********          **********                    **********          **********
**********          **********                    **********          **********
**********          **********          ********************          **********
**********          **********          ********************          **********
**********          **********               ***************          **********
**********          **********               ***************          **********
**********          **********          ********************          **********
**********          **********          ********************          **********
**********          **********          **************             *************
**********          **********          **************          ****************
********************************************************************************
******************************* SsYoloSwag41.Inc *******************************
OK: found pattern Correct!

bordel v kóde

@halficek

switch (expression_check_active(self, active, &b))
        {
            case 0:
                return 0; // Nahradenie povodnej -1
                break;

            case 2:
                if(!active->dataType)
                {
                    rc = resolve_identifier(self, table, &active, 0);
                    if(!rc)
                        return rc;
                }
                break;
        }

funkcia

inline int expression_check_active(ifjInter *self, token *active, int *b)
{
    switch (active->type)
    {
        case T_ADD:
        case T_SUBTRACT:
            *b = 0;
            return 1;

        case T_MULTIPLY:
        case T_DIVIDE:
            *b = 1;
            return 1;

        case T_LPAREN:
            *b = 2;
            return 1;

        case T_RPAREN:
            *b = 3;
            return 1;

        case T_SEMICOLON:
            *b = 5;
            return 1;

        case T_IDENTIFIER:
        case T_STRING_C:
        case T_INTEGER_C:
        case T_DOUBLE_C:
            *b = 4;
            return 1;
    }

    *b = -1;
    print_unexpected(self, active);
    SET_RETURN(2);
    return 0;
}

nikde tam tú dvojku nevraciaš...
to isté pre condition_check_active
je to len bordel alebo skutočne neresolvujeme identifikátory?

Indentifikatory

@kubaj
Zle vyhodnotenie identifikatorov.

// Definovanie identifikatora
// Zacina pismenom, _(podjebovnikom) , $(dolarom)
// Postupnost cislim, pismen, _, $

class Main
{
	static void run()
	{
		int a = 5;
		int a123 = 5;
		double A123 = 5;
		double A123_jd47 = 5;
		String _idenTIF1ka_tor = 5;
		String $iden_T1f2k5_$tor = 5;

		int $_iD3n_a___T1d2k$$$_85A = 25;
	}
}

double conversion

@kubaj @NoName115
input:

double a = 1.0;
ifj16.print(a + "\n");

output
1

input

double a = 1;
ifj16.print(a + "\n");

output
4.94066e-324
a rozplakaný valgrind ako bonus

Chyba 20.Riadok, asi typová kontrola

@halficek
Pullni si najnovsiu verziu, spusti si ./ifj16 tests/syna.
Dava chybu na 20 riadku, a je to pri typovej kontrole:

  1. dataType treba porovnavat iba so T_STRING, T_DOUBLE, T_INTEGER, nie s konstantou _C.
  2. Zrejme je chyba este aj vo funkciach dole co je typová kontrola, skus sa na to pozriet.

returnCode

@edynox

class Main
{
    static void run()
    {
         int i = 25;
         double d = 0.125 / i;
         calculate(d);
    }
    
    static void calculate(int a)
    {
    	
    }
}

Mame navratovy kod 0, ma byt 4. Je to volanie funkcie so zlym datovym typom... mozno u mna chyba v executore?

Valgrind - readDouble

@kubaj
Checkni si valgrind ked do readDouble dostanes znak alebo nieco ako 2.5.5 a pod. kraviny.

class Main
{
	static void run()
	{
		double a = ifj16.readDouble();
	}
}

Oktanove cisla

@kubaj

// Testy retazovych literalov
// Chyba 1, \ddd <001, 377>

class Main
{
	static void run()
	{
		String a = "Ahoj\nSve'te\\\042 \000";
		ifj16.print(a);
	}
}
// Testy retazovych literalov
// Chyba 1, \ddd <001, 377>

class Main
{
	static void run()
	{
		String a = "Ahoj\nSve'te\\\042 \378";
		ifj16.print(a);
	}
}

Definovanie ifj16 triedy

@edynox @halficek
Definovanie ifj16 triedy nam da SIGSEGV a returnCode -11. OPRAVIT !!

class Main
{
    static void run()
    {
        // Komentar
    }
}

class ifj16
{
    static void test()
    {
    	// Komentar 2
    }
}

Vypis stringu

@kubaj @edynox

// Testy retazovych literalov

class Main
{
	static void run()
	{
		String a = "V: \"\\\n a\"\t \n koniec\'";
		ifj16.print(a);

		ifj16.print("P: \"\\\n a\"\t \n koniec2\'");
	}
}

sema wrong returnCode

@halficek @edynox

class Main
{
    static void run()
    {
         String a = "retazec";

         if (a)
         {
            a = "Sematicka chyba";
         }
    }
}

Ma to byt sematicka chyba returnCode = 4, nie 2.

Nenacitava zaporne cisla

@kubaj @edynox @halficek
Hodi chybu returnCode 2 ze " Error: line 5 unexpected identifier ";" ", opravit.

class Main
{
    static void run()
    {
        int r = -5;
        double d = -12.58;
    }
}

SIGSEGV

@halficek
V condition ti to padne na pamati pri:

class Main
{
	static void run()
	{
        while (5 + (+) + 5) // syntax error
        {

        }
	}
}

class Dva

{

}

returnCode - sema fail

@edynox @halficek
Pri kode

class Main
{
    static void run()
    {
        int redefine = 2;
    }

    static void redefine(int a)
    {
    	// prazdna
    }
}

By nam malo vratit resultCode 3 vrati nam 0. Redefinovana premenna/funkcia by to mala byt.

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.