CLIP Command Line InterPreter for a subset of C++.

  • Published on
    04-Jan-2016

  • View
    221

  • Download
    4

Transcript

  • CLIPCommand Line InterPreter for a subset of C++

  • This presentationIntroduction and why CLIP was madeOther C++ interpretersMain ideas in CLIPC--Other featuresCLIP vs. compilerEvaluationQuestions

  • IntroductionIn teaching programming the intention is not to teach only one programming language but problem solving in generalHowever, a programming language is needed for student motivationTeacher is often not free to choose the language based on the pedagogical factsThus, teacher should try to make learning the chosen language as easy as possibleAt TUT this means C++

  • Why CLIP?Learning programming is hardWhen using compilers, there is much overhead in writing the first complete programsBy using an interpreter-based approach, this problem can be avoided

  • Why CLIP?C++ is not the best language for teachingCompiler error messages are far from intuitiveCompilers may be hard to useCLIP is made to smooth these problems

  • Other C++ interpretersCh, CINT, UnderC, IfNCPNone of these interpreters met our requirements, which wereAvailable for freeLocalizableEasy to useReliableEasy integration of visualization module

  • CLIP backgroundCLIP was developed from the interpreter used in VIP, a Visual InterPreter for a subset of C++. VIP was made by Antti Virtanen.Professor Hannu-Matti Jrvinen is making a book where he presents a interpreter-based programming education and he needed an interpreter to support the book

  • Main ideas in CLIPClear error messagesLocalization to students mother languageImperative-first approach

  • How to use CLIPIn interactive mode (normal mode) you can run the commands like inside main-function. You can still define functions and structs etc. like in global scope.You can also start CLIP in a single file mode from command line, and then the interpreter functions in a slightly different mode.

  • C--The language that CLIP supports, called C--, is a subset of C++.Main features which are included:All the basic data and control structuresPointers and referencesFunctionsEnumsStructs (no methods)String, vector, cin and cout partlyMath library partly

  • C--Main features which are missing:goto statementClasses (exceptions: cin, cout, string, vector)File streamsBit operatorsExceptionsNamespaces (using namespace is allowed)Templates (with the exception of vector)Overloading of function names

  • Other featuresCLIP adds these features compared to a standard compiler:When an error is found from code, show the line where the error came fromShow contents of the symbol table in runtimeTeachers can turn some features on or off depending on the topic which is taughtCommands for saving and loading functions to and from external files.Faster feedback than from compiler

  • ConstraintsAt the moment the following features can be disabled from the interpreter:Switch statementPointersAltering the for loop variable inside the for loopSubroutines, which have both non-const parameters and a return valueGlobal variables

  • Runtime error messagesThe interpreter detects also the following runtime errors:Divide by zeroToo deep recursionInfinite loopReference through a null pointerIndex or pointer out of boundsUse of uninitialized variables

  • CLIP vs. compilerWe compared the differences between CLIP and GNU C++ compiler (g++) by giving them the following piece of code:#include #include using namespace std;int main() {vector i;cout
  • CLIP vs. compilerg++ gave an error which was about 80 lines long and started with the following lines:b.cc: In function 'int main()':b.cc:6: error: no match for 'operator
  • CLIP vs. compilerCLIP gave the following error:Semantic error on line 6: Can't print type vector of intto cout. cout
  • EvaluationCLIP is intended to be used in the elementary programming courses at TUT.Hypothesis is that the students will learn the basic concepts easier than before.Although the first real experiences of the usage of the interpreter are still in the future, we feel that the tool statisfies the requirements we have put on it.

  • ConclusionsCLIP smooths the first steps in C++ by offering to the novice programmer a limited programming language and friendly interpreter environment.Later on a visualization module will be integrated with it and we get a system where students can visualize and debug their code.

  • Questions

    I am going to tell you about CLIP, a Command Line InterPreter for a subset of C++.

    Ok, this presentation goes as follows.First I'll tell you about why CLIP was made.Then shortly of other C++ interpretersThen we discuss about main ideas in CLIP and C--, the subset of C++ which CLIP interprets.Then something about other features in CLIP.Then we compare CLIP with a normal compilerIn the end something about evaluation and then you can ask your questions.

    2. Some teachers have tried to use some kind of formal structures instead of a real programming language, but that hasn't become too popular mainly due to the lack of motivation of students3. The university, the industry and other things might affect to the choice of programming language4. In the following slides, we assume that we use C++.

    2. For example, students have to know what is a main function, include all libraries and know how to compile and execute their program. Students have to write all kinds of mystical spells without knowing what they actually do, for example, using namespace std. This is where an interpreter comes handy.3. In interpreter-based approach to programming education, students can start from the basic structures. They don't have to worry about compiling or running the program.

    1. Ok, we already covered this topic. When we can't change the programming language, at least we can make the learning little easier.2. Novice programmers get very easily stuck when compiler gives an error which they do not fully understand. It can even take an hour from a novice programmer to correct a simple syntax error which would require a couple of seconds from an experienced programmer.3. Novice programmers do not have any routines for the lower-level programming like experts do. Thus the programming tools should be as simple as possible.

    0. Ok, then shortly about other C++ interpreters. The C++ interpreters we evaluated were the following ones.7. Ch wasn't reliable enough, CINT was hard to use, UnderC and IfNCP were not available and in addition, it would have been very hard to integrate a visualization module to any of these existing interpreters.

    1. There were some errors in the interpreter that were difficult to correct and the implementation was hard to develop further, so the new version of the interpreter is completely new in design and implementation.3. So, there are now two requirements, a new interpreter for the VIP environment and a command line interpreter for the interpreter-based programming education. When these two requirements were connected, we got CLIP as a result. We don't want to maintain two separate interpreters.

    1. The error messages which a normal compiler gives are sometimes next to impossible to understand. This is ofter a consequence of the usage of template libraries. In CLIP, the supported subset of C++ is smaller than in compilers, which makes the error messages simpler.2. Localization to students mother language is also important because novice students may not have good english skills.3. Although C++ is an object-oriented programming language, CLIP does not support classes and is intended for imperative-first approach, which is often used when C++ is taught as the first programming language.

    0. There are two different modes in which you can start CLIP: interactive mode and single file mode.2. For example, in single file mode a main function is needed and it is run automatically, when in interactive mode the main function is not needed or not special in any way.1. This is important so that students can move directly from this interpreter to normal C++ compilers.2. And then here is a list of the feature which are included in the C--.7. Methods are forbidden in structs because that would basically mean that they were classes (which are not supported).8. All these classes string, vector, cin and cout are implemented partly so that the basic usage is allowed.9. And also mathematical library is implemented partly.0. Ok, then to the features which are missing. The idea has been that by a selective use of some properties of the C++ some of its problems can be, made smaller.3. Classes are omitted with the exception that cin and cout are available for input and output. Also strings and vectors are available.9. Overloading of function names was left out because it would have been little confusing on command line when you want to change the declaration of a function.2. This means that it shows the whole line, not just the line number.3. This feature is useful when you want to see variables values.4. For example, when references are taught, pointers can be turned off. In that case the use of pointers would just result in an error message.6. An interpreter gives the feedback instantly without any need to compile the whole program first.

    5. This constraint forces students to use either functions which do not alter their parameters, or procedures, which do not return a value.7. If some of these constraints is enabled, using of the feature will only cause an error message.8. So, these features are at least some extra compared to a normal compiler.Ok, you can see that the error is on the line 6 where we try to print a vector to cout. Now lets see what happened.

    The compiler finds the error and tries to tell all the candidates that can be printed to cout, but in a very complex form.You can only imagine which one of these is easier to understand for a novice programmer. In addition, when using CLIP interactive mode, student would have only needed to write the two lines, the vector initialization and the cout statement. No struggling with namespaces or main function is needed.3. Some tentative tests have given encouraging feedback and the properties seem to be consistent with the requirements found in the literature.

Recommended

View more >