C# with pylint for cunstruct checking

Re: C# with pylint for cunstruct checking

by Richard Lobb -
Number of replies: 0

I assume the C# template you're using is written in Python. You should be able to extend that template to perform various checks on the submitted code before running it. But I doubt the code in the python3_cosc121 template will be of much direct use. The version currently  in the file uocprototypes.xml in the CodeRunner distribution uses Python's ast module to do a complete parse of the submitted Python ode. It then traverses the parse tree to count uses of various constructs and functions. This makes it relatively straightforward to disallow or require particular constructs and/or functions.

I have a C question type (written in Python) that does something similar, using a third party pycparser module to parse the student's C code. But C# is a much more complex proposition and I can't immediately see any third party C# parsers written in Python on the web.

What we used to do, and still do in messy ill-defined languages like Matlab, is use roll-your-own code checkers (e.g. with extensive use of regular expressions) to remove comments and then search for banned or required constructs. As a very simplistic example, you might have something like:

student_answer = """{{ STUDENT_ANSWER | e('py') }}"""
if 'while' not in student_answer:
    raise Exception("Your code must contain at least one while loop")

This is of course a very weak check, satisfied even by a comment like 

// I never use while loops

but it perhaps shows you the general idea?

To do this all properly (to the extent possible in the absence of a parser) takes a lot of effort, but writing new question types is certainly a lot more enjoyable than marking.

Check out the python3_cosc121 prototype to see how to use template parameters to pass in the banned or required constructs so that you don't have to directly edit the template for each such question.

Richard