1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Notes in Computer Science- P41 docx

5 271 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 263,28 KB

Nội dung

Design and Implementation of an Internet-Based Platform for C Language Learning 189 Client based on .NET Internet DB Management Module User DB Test-case DB Question DB Server based on .NET Fig. 1. The architecture of the system Client User Login Module Compile Error-check Module Logic Error-check Module Auxiliary Module Server User Management Module Logic Error-check Service Module Auxiliary Service Module TC Programming Module Send Information Feedback DB Management Module Fig. 2. The system module Users can learn C language knowledge and doing program in Turbo C 2.0 pro- gramming environment. If they meet compile errors which are difficult to solve, users can get hints and extra help form the compile error-check module and then rectify the grammatical mistakes. After the program ran successfully, users can send the source code to the server to do logic error-check. The server will return the results of the program quickly and display it in the massage frame. According the feedback, logic errors in the source code can be corrected. 3 Design and Implementation of Compile Error-Check Compile Error-check module is responsible for supporting users more accurate and comprehensive compile error messages. Its work process is shown in Figure 3. It ob- tains error messages in two ways. One way is to analyze the TC errors by interacting with the Turbo C 2.0. The other way is to infer the errors from the source code through kinds of algorithms provided by the system. 190 J. Wang, L. Chen, and W. Zhou read the source code brackets matching algorithm lexical analysis grammar and semantic analysis variable definition algorithm semicolon positioning algorithm get the correct errors statistic analysis get all compile errors lexical analyzer grammatical and semantic analyzer delete the correlate erro r TC compile error end begin Fig. 3. The flow sheet of compile error-check The first way is mainly to capture the error messages of Turbo C 2.0 compiler and to analyze the possible reasons. The communication between the system and the compiler is implemented by redirect technology under DOS. Meanwhile, the system saves these errors to a text file, then it positions each error correctly according to the analytical database. This way is responsible for deleting the relative errors and positioning the mistakes correctly. The main code is shown in the following: private string RunCmd(string command) { Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/c " + command; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); return p.StandardOutput.ReadToEnd(); } Design and Implementation of an Internet-Based Platform for C Language Learning 191 The second way is mainly to analyze the source code independently and to find out some hidden errors, which provides expert-level guidance for users. It can make up for the shortcoming of TC compiler. As we know, Turbo C 2.0 positions errors incorrectly sometimes and usually causes some correlated errors. Though it’s a classic C language compiler, Turbo C 2.0 only guarantees that the first error is correct. For example, sometimes losing a ";" will cause more than 10 errors. Besides, the external errors may shield internal errors in some compound statements. The C-language learners will feel terrified and don’t know what to do next because of these incorrect errors. This way is useful to deal with this problem. It analyzes the source code with different methods, which contains lexical analysis, grammatical and semantic analysis. There are kinds of algorithms in the system used to find out the errors in the code, such as brackets matching algorithm, semicolon positioning algorithm and variable definition algo- rithm. And they are self-contained and can be replaced and extended in the future. These algorithms are high efficient and can find out the hidden errors which may not be discovered by TC compiler. The two ways are good supplement to each other. And they will be unified in the end and then return the feedback to users. So the error messages presented by the system not only contain the correct TC errors, but also include some hidden errors in the code. They are more comprehensive. 4 Design and Implementation of Logic Error-Check Logic Error-check is the key module in the learning system, which is responsible for helping users to find out the logic errors in their programs and checking the codes whether have achieved the function of the program completely. It contains document processing, compile, safety-check, redirect input and output, test-case scheduling and feedback sub-modules. Its structure is shown in Figure 4. If any of sub-modules has appeared mistake, the server will return an error message to the client and delete the program directly. The document processing sub-module receives and processes the .C source files sent from the client. And the compile sub-module is responsible for compiling the source code, which is realized by the DOS command and the outside interface provided by the .NET platform. It can test the program whether has compile errors. The compile sub-module will call TC to run the program if there are not compile errors in the code. Document Processing Sub- module Compile Sub- module Test-case Scheduling Sub- module Safety- check Sub- module Redirect Input and output Sub- module Feedback Sub-module Fig. 4. The structure of function-test Module 192 J. Wang, L. Chen, and W. Zhou The safety-check sub-module is mainly to make sure the programs are safe to the computer. Usually, the computer will be in danger if the programs are in death cycle. Though we can interrupt the death cycle compulsively in Turbo C 2.0, the functions provided by the server are all automatic. So it is necessary to provide a good method to track the program’s running and delete the malicious code in time. The Process com- ponent is used to achieve this function in the sub-module, which is a useful tool to start, stop, control and monitor applications in the .NET platform. And it can get the infor- mation of currently running process, including thread set, performance and loadable module (. Dll and. Exe file). So the safety-check sub-module can judge the program coming to an end or not by this information of process. If the process has been closed in normal at prescribed time, it means that there is not death cycle in the program. Oth- erwise, it indicates that the process is dangerous to the computer. The Process com- ponent will call the interruption and delete the program at the same time. The main code is as following: Process myProcess; myProcess = Process.Start(exe_file); //run the .Exe file for (int k = 0; k < 100; k++) { if (!myProcess.HasExited) { myProcess.Refresh(); Thread.Sleep(50); } else { break; } } if (!myProcess.HasExited) // If the process hasn’t been closed in normal { myProcess.Kill(); …… } myProcess.Close(); The redirect input and output sub-module is used to take over the input and output of the programs when the platform does logic error-check function. The system tests the code whether has achieved the function completely only according the outputs of the program. However, the programs of users usually get their inputs from keyboard or their designated files, so the system can not check the correctness of the outputs. The sub-module must take over the inputs of the programs by the test-cases firstly. The class “ReplaceEdit” is used to implement this operation, which analyzes the .C source files and replaces the input-functions and output-functions of keyboard or files in the source code. For example, keyboard output-function “printf” is replaced by the file output-function “fprintf”, keyboard input-function “scanf” is replaced by the file input-function “fscanf”. So the source code will have specific input and output after being dealt by the redirect input and output sub-module. Design and Implementation of an Internet-Based Platform for C Language Learning 193 Test-case DB Test-case scheduling module Program Call Object instance of test-case Data Return results Create object instance Call class information Test-case class DB Fig. 5. The structure of test-case scheduling The test-case scheduling sub-module mainly manages and schedules the test-cases and methods. In order to test the programs whether have logic errors, a large number of test-cases and analysis methods are needed in the system. Usually, each program needs a corresponding test-case class to run it independently, because different programs require different test-cases and methods. If we write test-case class for each program, the system code will be prolix and bad for extending and modifying in the future. So the test-case scheduling sub-module supports the dynamic creation of test-case class for each program, which uses Object-Oriented design methods and C# Reflection tech- nology. Its structure is shown in Figure 5. There are two databases in the sub-module: test-case DB and test-case class DB. The test-case DB contains different test-cases, and the test-case class DB is used to save the information of the test-case classes. The test-case scheduling sub-module uses the Object-Oriented design methods to manage and communicate with these two databases. It calls the information of the test-case classes by the scheduling module. With the types of programs increased, the system code will be more complex. The parts in the sub-module should interact with each other only through their interfaces and can be replaced without affecting other parts of the sub-module for keeping the platform be flexible and extendable. The Factory method, Condition external and C# Reflection technology are used to achieve this function. The Factory method can ac- complish reconstruction technology and provides the interface of test-case. The Con- dition external offers the uniform information management by using configuration File. The C# Reflection technology can create an object instance of the test-case class for each program by calling the class’s attributes and methods. So each part in the sub-module is self-contained and can be replaced and extended. 5 An Example in the System The Internet-based system for C Language Learning provides programming environ- ment, rich learning materials and more powerful compile and logic error-check functions. . according to the analytical database. This way is responsible for deleting the relative errors and positioning the mistakes correctly. The main code is shown in the following: private string. analysis. There are kinds of algorithms in the system used to find out the errors in the code, such as brackets matching algorithm, semicolon positioning algorithm and variable definition algo- rithm mainly to make sure the programs are safe to the computer. Usually, the computer will be in danger if the programs are in death cycle. Though we can interrupt the death cycle compulsively in

Ngày đăng: 05/07/2014, 09:20

TỪ KHÓA LIÊN QUAN