예제 #1
0
def main():
    prog = '''
        int g = 1 - 2 - 3;
        bool axx = true;
        int[] aaa = new int[10];
        aaa[0] = 10;
        string g3 = "kek";
        int t = 4 + 5;
        double wow = g + t;
        t = 10 * 12 - (g + g);
        double s = 90;
    
        
        for (int i = 0, j = 8; ((i <= 5)); i = i + 1)
            for(; t < g;)
                if (t > 7 + g) {
                    t = t + g * (2 - 1) + 0;  // comment 2
                    g3 = "98\tура";
                }
        for(;;);
        
        string[] arr = new string[10];
        int[] kek = new int[]{ 1, 2, 3, 4, 5 };
        
        
        public int[] what(int a, int b) 
        {
            int[] c = new int[]{5, 4, 6, 5, 1};
            string fff = "asd";
            return c;
        }
        
        
        public static void whatElse(int a, int b) 
        {
            int[] c = what(a, b);
            c[a + b] = 0;
            int e = c[3];
            while (true)
            {
                a = a + b;
                do
                {
                    b = a - b * b;
                }
                while (g + t > t)
            }
            return;
        }
    '''
    prog = mel_parser.parse(prog)
    # print(*prog.tree, sep=os.linesep)
    a = Analyzer()
    the_prog, _ = a.analyze(prog)
    gen = CodeGenerator(the_prog, '')
    # try:
    #     a.analyze(prog)
    # except ValueError as e:
    #     print(e)
    print(*the_prog.tree, sep=os.linesep)
예제 #2
0
def prepare_global_scope() -> IdentScope:
    from mel_parser import parse

    prog = parse(BUILT_IN_OBJECTS)
    scope = IdentScope()
    prog.semantic_check(scope)
    for name, ident in scope.idents.items():
        ident.built_in = True
    scope.var_index = 0
    return scope
예제 #3
0
def main():
    prog = '''
        class A
        {
            int a(int a)
            {
                int b = 0;
            }

            int b;
        }

        int a(int a)
        {
            int b = 0;
        }
        
        A a1 = new A();

        int[] b = { a, b , {c, d } };
        a = a.lenght;
        a.lenght();
        //a = a[b + c];
        return ;
        return 2;
        return a+b;
        a = a[2];
        int[] b = new int[b + c][4];
        int[] b = 4;
        int g, g2 = g, g = 90;

        a = input(); b = input();  /* comment 1
        c = input();
        */

        //int [ ] b = int [ 5 ];
        //a = int[5];
        string b = "Привет";
        //a . g2;
        for (int i = 0, j = 8; ((i <= 5)) && g; i = i + 1, print(5))
            for(; a < b;)
                if (a > 7 + b) {
                    c = a+b * (2 - 1) + 0;  // comment 2
                    b = "98\tура";
                }
                else if (f)            
                    output(c + 1, 89.89);
        for(;;);

        while (g2 > g)
            output(g2);
    '''
    prog = mel_parser.parse(prog)
    print(*prog.tree, sep=os.linesep)
예제 #4
0
def execute(prog: str) -> None:
    prog = mel_parser.parse(prog)

    print('ast:')
    print(*prog.tree, sep=os.linesep)
    print()

    print('semantic_check:')
    try:
        scope = mel_semantic.prepare_global_scope()
        prog.semantic_check(scope)
        print(*prog.tree, sep=os.linesep)
    except mel_semantic.SemanticException as e:
        print('Ошибка: {}'.format(e.message))
        return
    print()
예제 #5
0
def main():
    prog = '''
        int g, g2 = g, g = 90;
    
        a = input(); b = input();  /* comment 1
        c = input();
        */
        for (int i = 0, j = 8; ((i <= 5)) && g; i = i + 1, print(5))
            for(; a < b;)
                if (a > 7 + b) {
                    c = a + b * (2 - 1) + 0;  // comment 2
                    b = "98\tура";
                }
                else if (f)            
                    output(c + 1, 89.89);
        for(;;);
    '''
    prog = mel_parser.parse(prog)
    print(*prog.tree, sep=os.linesep)
예제 #6
0
def main():
    prog = mel_parser.parse('''
        input a input b  /* comment 1
        input c
        */
        c = a + b * (2 - 1) + 0  // comment 2
        output c + 1

        if a + 7 then b = 9 elif a + 1 then c = 2 else b = 8 end if
        
        int a = 7
        
        begin
        
        loop i = i + 1 end loop
        
        while red + a loop green = b end loop
        
        for a + 1, b + 2, c + 3 loop coffee = 1 end loop
        
        end
    ''')
    print(*prog.tree, sep=os.linesep)