Codechecker feedback lazarus / 21-General ---------------------------------------------------------------------- luc98611 · 2024-01-26 09:58 Dear people of this forum, I need to make a program for computer science in lazarus. The program is a kindoff game, with a database of programming related questions in python (such as: 'given the array a = [x,y,z], make a program that can search the array and can tell whether an user input is in the array or not'). The program should then, check if the code is right (syntax, variables on right place, right output). If the code is right, the next question appears. If the code is wrong or the user needs a hint, the program will give feedback (such as: 'watch your syntax!'). How do I create this 'checking' intelligence and then give the right feedback? ---------------------------------------------------------------------- ccrause · 2024-01-26 11:59 One option is to let the python interpreter do all the work. Basically take the submitted code and dump it in a script, execute the script and capture the output. Scan the output for either the correct result, or possible error messages. ---------------------------------------------------------------------- Thaddy · 2024-01-26 12:01 This can be answered on multiple levels of complexity: 1. The computer science way: From a python grammar write a lexer and parser. Usually not what people here ask for, though possible, it is likely not what you mean. Although if you are a computer science majoring, that is what it means. 2. Much simpler is - if it is just a computer science class - to use the pyton4lazarus package to let an embedded python engine let the syntax checking for you 3. Simplest: Use a TProcess to call an installed python like so: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i python -m py_compile TSynPythonSyn contains a python lexer, but that is not enough to do real syntax checking. For that you can use Python4Lazarus. Or use Tprocess to let python do the syntax check. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program pythonchecker;(*. hello.py looks like this, with intentional error:----------------------import sysprint('hello, py);----------------------save that as hello.py  *){$mode objfpc}{$H+}{$ifdef mswindows}{$apptype console}{$endif}uses classes, process; var P:TProcess;begin P :=TProcess.Create(nil); try   P.executable:='python.exe';// assumes windows, on linux leave the .exe out.   P.Parameters.Add('-m');   P.Parameters.Add('py_compile');   P.Parameters.Add('hello.py');   P.Execute; finally   P.Free; end;end. You can subsequently redirect that output to your program using streaming/pipes. Even simpler, but deprecated looks like this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+}{$ifdef mswindows}{$apptype console}{$endif}uses classes, process; var P:TProcess;begin P :=TProcess.Create(nil); try   P.Commandline := 'python -m py_compile hello.py';   P.Execute; finally   P.Free; end;end.I let it up to you to write the cosmetics yourself.. I can do the whole thing in minutes, but it is..... Homework. I used Python 3.12 for windows, but it should also work for older Python versions. ---------------------------------------------------------------------- Thaddy · 2024-01-26 16:54 Quote from: luc98611 on January 26, 2024, 10:58:51 amDear people of this forum, I need to make a program for computer science in lazarus. The program is a kindoff game, with a database of programming related questions in python (such as: 'given the array a = [x,y,z], make a program that can search the array and can tell whether an user input is in the array or not'). The program should then, check if the code is right (syntax, variables on right place, right output). If the code is right, the next question appears. If the code is wrong or the user needs a hint, the program will give feedback (such as: 'watch your syntax!'). How do I create this 'checking' intelligence and then give the right feedback? If you are really trying to major for CS then the grammar is here: https://docs.python.org/3/reference/grammar.html IOW the documentation....