Hello,

Am new here but I will appreciate if I can get an answer.

I am to build a miniature automatic feedback for programming assignment system in PHP as a final year project.

This system will take a programming assignment in C either through a web form or a text file and check for errors. It will then notify the uploader of the program of the errors and possible corrections expected. It isn't necessarily going to be a grading system.

I just want to know how to start with this. Anyone who has any idea what I can do to acheive my objective should please help out.

Thanks.

Member Avatar for diafol

You want php to read C code and tell you if there are errors in it?

commented: Exactly what i want to do +0

If you run the source code through a compiler you can gather the compiler output and parse it to find the errors reported by the compiler. Then analyse the error list and suggest causes and/or fixes. For common things like undeclared or mis-spelt variables, missing include files and so on, it would be possible to provide guidance for novice level students. To provide anything useful for more advanced students would be much harder.
Is that the sort of thing you are considering?

@Salmisoft, how then can i add a compiler tothe web project? I'm thinking of minimising the project to do just common things like undeclared or mis-spelt variables, missing include files and so on, since anything more than that is far higher than my strength.

I am getting away from my area of expertise by answering this, so I hope someone with more knowledge can comment. In essence it should be simple though. Use a compiler that you can run from the command line, passing in the name of a source code file. Then all you have to do is write the user's source code to a temporary file and start the compiler with the name of that temp file as a command line parameter. I don't know PHP but I think you need an Exec or System command to start the compiler.
Redirect the compiler to a text file. Then you can open that file, read it, and find the error messages.

In this sense the compiler is not really added to the web project, merely launched from your code.

Thanks all. I finally got an approval today from my supervisor to develop just the framework and she will program the solution herself. Thanks once again.

Member Avatar for iamthwee

Yeah unless there is a PHP 'c' compiler out there, you would need your own Virtual Private Server, that way you can run scripts and install gcc on your linux box - basically do what saimisoft said. Shared hosting might not allow you such liberties.

If you know you have gcc installed perhaps using something like 'exec'

and piping those results to a file:

http://stackoverflow.com/questions/3460111/trying-compile-a-c-code-with-php

Hmm...I just mailed my hosting provider and they said they can't provide such (compiling on their servers) using a shared hosting... I think I'll just develop d framework and leave the implementation to my lecturer

Member Avatar for iamthwee

I think I'll just develop d framework

No offence but writing your own c compiler is no easy task... If this is just purely academic, you might get away with a very stripped down ad hoc compiler.

It might not necessarily be a bad thing. It wouldn't be much of a project otherwise.

Just to add more info., here is a good example of a PHP script that can compile C .

I prefer using the exec("your_compiler_command_here 2>&1", $res, $err);

$res and $error are the text file error log.

That's all I can tell you. I am pretty rusty with C. The last time I played with it was, when I was trying to write a game about two characters throwing bananas at each other.

@iamthwee: I don't think anyone would write a compiler just for this. Better to run an existing compiler and capture the error messages. It could still be a good project if it explained the error messages in terms a novice programmer could understand, and provided good guidance about how to fix the problems.

That's a really good example to use as a starting point. A project that tailored those explanations to the actual code compiled, guided the user to the code that produced the error, highlighted the problem in the actual code, and suggested how the code could be corrected, should be a great help to novice programmers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.