Exemple #1
0
        public void codeGenTest_Method_StackCount()
        {
            BFTestHelper.debugMethod_Output("0 2 6 0 ", "a()",
                                            @"
				void a()
				var 
					stack<int>[8] stck;
				begin
					out stck.count();

					stck.push(0);
					stck.push(0);

					out stck.count();

					stck.push(0);
					stck.push(0);
					stck.push(0);
					stck.push(0);

					out stck.count();

					while (!stck.empty()) do stck.pop(); end

					out stck.count();
				end
			"            );
        }
Exemple #2
0
        public void codeGenTest_Method_Random_2()
        {
            BFTestHelper.debugMethod("calc()",
                                     @"
			void calc()
			var
				int i := 0;
				char[2] lb := { '\r', '\n' };
			BEGIN
				BEGIN
					OUT lb[(int)RAND];
					OUT lb[(int)RAND];
					
					OUT ''A \r\n\r\n'';

					OUT lb[(int)RAND];
					OUT lb[(int)RAND];

					OUT ''B'';

					OUT lb[(int)RAND];
					OUT lb[(int)RAND];

					OUT '''';
					
					OUT lb[(int)RAND];
					OUT lb[(int)RAND];

				END
			END
			"            );
        }
Exemple #3
0
        public void codeGenTest_Program_VariableSpace2_2()
        {
            BFTestHelper.debugProgram_Output("113010 ", @"
			program p0
				global 
					int ii;
					int a, b, c ,d, e, f, g, h, i, j;
					int[100] s1;
					int k, l, m, n, o, p, q, r, s, t;
					int[100] s2;
					int sum;
				begin
					sum = 0;

					FOR(ii = 0; ii < 100; ii++) DO
						s1[ii] = ii;
					END
					a=101;b=102;c=103;d=104;e=105;f=106;g=107;h=108;i=109;j=110;
					k=201;l=202;m=203;n=204;o=205;p=206;q=207;r=208;s=209;t=210;
					FOR(ii = 0; ii < 100; ii++) DO
						s2[ii] = 1000 + ii;
					END
					
					FOR(ii = 0; ii < 100; ii++) DO
						sum += s1[ii] + s2[ii];
					END
					sum += a+b+c+d+e+f+g+h+i+j;
					sum += k+l+m+n+o+p+q+r+s+t;

					out sum;
				end
			end
			"            );
        }
Exemple #4
0
        public void codeGenTest_Program_ArrayParameter()
        {
            BFTestHelper.debugProgram_Output("110308", @"
			program p0
				var 
					digit[6] x := {#1, #1, #2, #3, #5, #8};
				begin
					x[2] = #0;
					x[4] = #0;
					a(x);
				end

				void a(digit[6] px)
				begin
					out b(px, 0);
					out b(px, 1);
					out b(px, 2);
					out b(px, 3);
					out b(px, 4);
					out b(px, 5);
				end

				digit b(digit[6] a, int i)
				var 
					digit[6] tmp;
				begin
					tmp = a;
					return tmp[i];
				end
			end
			"            );
        }
Exemple #5
0
        public void codeGenTest_Program_StackIdentity()
        {
            BFTestHelper.debugProgram_Output("4 8 15 16 23 42 ", @"
			program p0
				var 
					stack<int>[16] s;
				begin
					s.Push(42);
					s.Push(identity(16) + identity(8) - 1);
					s.Push(identity(16));
					s.Push(identity(identity(identity(15))));
					s.Push(identity(identity(8)));
					s.Push(identity(4));

					while (!s.empty()) do
						out s.peek();
						s.pop();
					end
				end

				int identity(int i)
				begin
					return i;
				end
			end
			"            );
        }
Exemple #6
0
        public void codeGenTest_Program_switch_Access()
        {
            ASTObject.CGO.DisplayModuloAccess = true;

            BFTestHelper.debugProgram_Output("WIN", @"
			program example
				begin
					switch (9 * 9 / 9 / 9)
					begin
						case 1: 
							OUT ''WIN'';
						end
						case 4:
							OUT ''FAIL'';
						end
						case 0:
							OUT ''FAIL'';
						end
						case -9:
							OUT ''FAIL'';
						end
						case 111:
							OUT ''FAIL'';
						end
					end
				end
			end
			"            );
        }
Exemple #7
0
        public void codeGenTest_Program_switch_Common_Reversed()
        {
            ASTObject.CGO.DisplayModuloAccess = true;

            BFTestHelper.debugProgram(@"
			program p 
				begin
					OUT '''';
					for (;;) do
						switch RAND[1]
						begin
							case 0:
								OUT ''0 '';
							end
							case 1:
								OUT ''1 '';
							end
							case 2:
								OUT ''2 '';
							end
							case 3:
								OUT ''3 '';
							end
						end
					end

				end
			end
			"            );
        }
Exemple #8
0
        public void codeGenTest_Program_Modulo_Display_Access()
        {
            ASTObject.CGO.DisplayModuloAccess = true;

            BFTestHelper.debugProgram(@"
			program example : display[64, 16]
				begin
					FOR(;;) DO
						paintR();
					END
				end

				void paintR() 
				var
				 int x;
				 int y;
				begin
					x = ((((((((int)RAND)*2) + ((int)RAND))*2 + ((int)RAND) ) * 2 + ((int)RAND)*2) + ((int)RAND))*2 + ((int)RAND) ) * 2 + ((int)RAND);
					y = ((((((((int)RAND)*2) + ((int)RAND))*2 + ((int)RAND) ) * 2 + ((int)RAND)*2) + ((int)RAND))*2 + ((int)RAND) ) * 2 + ((int)RAND);

					OUT x;
					OUT '','';		
					OUT y;
					OUT ''\r\n'';		

					display[x, y] = '#';

					OUT ''\r\n'';

				end
			end
			"            );
        }
Exemple #9
0
        public void codeGenTest_Program_GlobalVar()
        {
            BFTestHelper.debugProgram_Output("99 ", @"
			program example
				global
				 int i;
				begin
					i = 0;
		
					doodle();
		
					OUT i;
				end

				void doodle() 
				begin
					i = 10;
		
					doodle2();
				end
	 
				void doodle2() 
				begin
					i = i * 10;
		
					doodle3();
				end
	 
				void doodle3() 
				begin
					i--;
				end
			end
			"            );
        }
Exemple #10
0
        public void codeGenTest_Program_Euklid()
        {
            BFTestHelper.debugProgram_Output("4 ", @"
			program example
				begin
					out euclid(44, 12);
				end

				int euclid(int a, int b) 
				begin
					if (a == 0) then
						return b;
					else 
						if (b == 0) then
							return a;
						else 
							if (a > b) then
								return euclid(a - b, b);
							else
								return euclid(a, b - a);
							end
						end
					end
				end
			end
			"            );
        }
Exemple #11
0
        public void codeGenTest_Method_GotoHell()
        {
            BFTestHelper.debugMethod("blub()",
                                     @"
			void blub()
			var
				int i := 10;
			begin

				lblstart:

				OUT i;

				i--;

				IF (i != 0) THEN
					OUT ''\r\n'';
					GOTO lblstart;
				ELSE
					GOTO lblend;
				END

				OUT ''WADWAD'';

				lblend:
				RETURN;

			end
			"            );
        }
Exemple #12
0
        public void codeGenTest_Program_ParameterIdentity()
        {
            BFTestHelper.debugProgram_Terminate(@"
			program p0 
				begin 
					id(); 
				end 

				int[8] id() 
				var 
					int[8] uv := {7,7,7,7,7,7,7,7}; 
				begin 
					return uv; 
				end 
			end
			"            );

            BFTestHelper.debugProgram_Terminate(@"
			program p0
				var 
					int[8] x;
				begin
					x = id(x);
				end
				int[8] id(int[8] input)
				begin
					return input;
				end
			end
			"            );
        }
Exemple #13
0
        public void codeGenTest_Method_StringEscaping_2()
        {
            BFTestHelper.debugMethod("calc()",
                                     @"
			void calc()
			var
				int i := 0;
				char[2] lb := { '\r', '\n' };
			begin
				OUT lb[0];
				OUT lb[1];
				
				OUT ''A \r\n\r\n'';

				OUT lb[0];
				OUT lb[1];

				OUT ''B'';

				OUT lb[0];
				OUT lb[1];

				OUT ''C'';
			END
			"            );
        }
Exemple #14
0
        public void codeGenTest_Method_InputArray()
        {
            BFTestHelper.debugMethod("calc()",
                                     @"
			void calc()
			var
				char[5] c;
				char[5] d;
				char[5] e;

				int[4] x;
			BEGIN
				IN c;
				
				d = c;

				e[0] = d[4];
				e[1] = d[3];
				e[2] = d[2];
				e[3] = d[1];
				e[4] = d[0];

				OUT c;
				OUT '' -> '';
				OUT e;
			END
			"            );
        }
Exemple #15
0
 public void codeGenTest_Statement_Out()
 {
     BFTestHelper.debugStatement_Output("OUT ''a'';", "a");
     BFTestHelper.debugStatement_Output("OUT ''ab'';", "ab");
     BFTestHelper.debugStatement_Output("OUT ''abcd'';", "abcd");
     BFTestHelper.debugStatement_Output("OUT ''abcdefgh'';", "abcdefgh");
     BFTestHelper.debugStatement_Output("OUT ''abcdefghijklmnop'';", "abcdefghijklmnop");
     BFTestHelper.debugStatement_Output("OUT ''abcdefghijklmnopqrstuvwxyz123456'';", "abcdefghijklmnopqrstuvwxyz123456");
 }
Exemple #16
0
        public void codeGenTest_Program_MethodCalls()
        {
            BFTestHelper.debugProgram_Terminate(@"
			program testprog
				VAR
					int i;
				BEGIN

					OUT ''\r\nSTART\r\n'';

					ma();
					mb();
					mc();

					OUT ''\r\nFIN\r\n'';

					QUIT;
				END

				VOID ma()
				BEGIN
				
					OUT ''A1'';
					OUT ''A2'';
					OUT ''A3'';
					OUT ''\r\n'';

					RETURN;

				END

				VOID mb()
				BEGIN

					OUT ''B1'';
					OUT ''B2'';
					OUT ''B3'';
					OUT ''\r\n'';

					RETURN;

				END

				VOID mc()
				BEGIN

					OUT ''C1'';
					OUT ''C2'';
					OUT ''C3'';
					OUT ''\r\n'';

					RETURN;

				END
			END
			"            );
        }
Exemple #17
0
        public void codeGenTest_Program_VariableSpace4()
        {
            BFTestHelper.debugProgram_Output("113010 ", @"
			program p0
				var 
					int a, b, c ,d, e, f, g, h, i, j;
					int[100] s1;
					int k, l, m, n, o, p, q, r, s, t;
					int[100] s2;

					int ii;
				begin
					s1 = arrinit(s1, 0000);
					s2 = arrinit(s2, 1000);

					out sumfunc(s1, s2);
				end

				int[100] arrinit(int[100] base, int offset)
				var
					int ii;
					int[100] ss;
				begin
					FOR(ii = 0; ii < 100; ii++) DO
						ss[ii] = base[ii] + offset + ii;
					END
					return ss;
				end

				int sumfunc(int[100] sp1, int[100] sp2)
				var
					int a, b, c ,d, e, f, g, h, i, j;
					int[100] s1;
					int k, l, m, n, o, p, q, r, s, t;
					int[100] s2;

					int sum := 0;
					int ii;
				begin
					a=101;b=102;c=103;d=104;e=105;f=106;g=107;h=108;i=109;j=110;
					k=201;l=202;m=203;n=204;o=205;p=206;q=207;r=208;s=209;t=210;

					s1 = sp1;
					s2 = sp2;

					FOR(ii = 0; ii < 100; ii++) DO
						sum += s1[ii] + s2[ii];
					END
					sum += a+b+c+d+e+f+g+h+i+j;
					sum += k+l+m+n+o+p+q+r+s+t;

					return sum;
				end
			end
			"            );
        }
Exemple #18
0
        public void codeGenTest_Method_StringEscaping()
        {
            BFTestHelper.debugMethod("calc()",
                                     @"
			void calc()
			begin
				OUT ''A \r\n\r\n'';
			END
			"            );
        }
Exemple #19
0
        public void codeGenTest_Method_ReversedOut()
        {
            BFTestHelper.debugMethod("doIt()",
                                     @"
			int doIt()
			begin
				out (char) 54;
				out (char) 55;
				return 0;
			end
			"            );
        }
Exemple #20
0
        public void codeGenTest_Method_PreDecrement()
        {
            BFTestHelper.debugMethod_Output("4 ", "a()",
                                            @"
				void a()
				var
					int i;
				begin
					i = 5;

					OUT --i;
				end
			"            );
        }
Exemple #21
0
        public void codeGenTest_Method_OutExpression()
        {
            BFTestHelper.debugMethod_NonTerminate("doIt()",
                                                  @"
			int doIt()
			begin
				out (char)(48+(int)RAND);
				out (char)(48+(int)RAND);
				out (char)(48+(int)RAND);
				out (char)(48+(int)RAND);
				quit;
			end
			"            );
        }
Exemple #22
0
        public void codeGenTest_Method_PostIncrement()
        {
            BFTestHelper.debugMethod_Output("5 ", "a()",
                                            @"
				void a()
				var
					int i;
				begin
					i = 5;

					OUT i++;
				end
			"            );
        }
Exemple #23
0
        public void codeGenTest_Method_For()
        {
            BFTestHelper.debugMethod_Output("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "a()",
                                            @"
				void a()
				var
					int i;
				begin
					FOR(i = (int)'A'; i <= (int)'Z'; i++) DO
						OUT (char)i;
					END
				end
			"            );
        }
Exemple #24
0
        public void codeGenTest_Expr_CompileTimeEvaluation()
        {
            ASTObject.CGO.CompileTimeEvaluateExpressions = true;

            BFTestHelper.debugExpression_Output("0 ", "int", "RAND[0]");
            BFTestHelper.debugExpression_Output("0 ", "int", "4 - 4");
            BFTestHelper.debugExpression_Output("0 ", "int", "4 * 0");
            BFTestHelper.debugExpression_Output("0 ", "int", "0 * 4");
            BFTestHelper.debugExpression_Output("0 ", "int", "0 * 0");
            BFTestHelper.debugExpression_Output("0 ", "int", "0 + 0");
            BFTestHelper.debugExpression_Output("0 ", "int", "12 * (11 - 11)");
            BFTestHelper.debugExpression_Output("0 ", "int", "666 / 6 - 111");
            BFTestHelper.debugExpression("bool", "!a");
        }
Exemple #25
0
        public void codeGenTest_Method_UniformArr()
        {
            BFTestHelper.debugMethod_Output("6 6 6 6 6 6 6 6 6 6 6 6 ", "a()",
                                            @"
				void a()
				var 
					int[12] arr := {6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
					int i;
				begin
	                for (i=0; i < 12; i++) do
						out arr[i];
	                end
				end
			"            );
        }
Exemple #26
0
        public void codeGenTest_Program_VariableSpace2_3()
        {
            BFTestHelper.debugProgram_Output("0 ", @"
			program p0
				var 
					int ii;
					int[100] s1,s2;
					int sum := 0;
				begin
					FOR(ii = 0; ii < 100; ii++) DO
						sum += s1[ii] + s2[ii];
					END
					out sum;
				end
			end
			"            );
        }
Exemple #27
0
        public void codeGenTest_Method_VarInitializer()
        {
            BFTestHelper.debugMethod("doFiber(8)",
                                     @"
			int doFiber(int max)
			var
				int a := 4;
				bool b;	
				char cc := 'o';
				int[4] e := {40, 48, 60, -20};
				bool c;
				bool d := false;
				int[8] h;
			begin
				return max;
			end
			"            );
        }
Exemple #28
0
        public void codeGenTest_Method_NestedStatementLists()
        {
            BFTestHelper.debugStatement_NonTerminate(@"
			while (true) do
				out (char)(48+(int)RAND);
				begin
					out (char)(50+(int)RAND);
					out (char)(50+(int)RAND);
				end
				begin
					out (char)(50+(int)RAND);
					out (char)(50+(int)RAND);
				end
				out (char)(48+(int)RAND);
				out (char)(48+(int)RAND);
				out (char)(48+(int)RAND);
			end
			"            );
        }
Exemple #29
0
        public void codeGenTest_Program_ParameterMethodCalls()
        {
            BFTestHelper.debugProgram_Terminate(@"
			program example
				begin
					out euclid(44, 12);
				end

				int euclid(int a, int b) 
				begin
					OUT a;
					OUT ''  '';
					OUT b;
					OUT ''  '';
					return 1337;
				end
			end
			"            );
        }
Exemple #30
0
        public void codeGenTest_Method_StackFill()
        {
            BFTestHelper.debugMethod_Output("128 64 32 16 8 4 2 1 ", "a()",
                                            @"
				void a()
				var 
					stack<int>[8] stck;
					int i := 1;
				begin
					while(!stck.Full()) do
						stck.push(i);
						i *= 2;
					end

					while (!stck.empty()) do
						out stck.pop();
					end
				end
			"            );
        }