Syntactic Generation of Practice Novice Programs in Python

  • Abejide Ade-IbijolaEmail author
Conference paper
Part of the Communications in Computer and Information Science book series (CCIS, volume 963)


In the present day, computer programs are written in high level languages and parsed syntactically as part of a compilation process. These parsers are defined with context-free grammars (CFGs), a language recogniser for the respective programming language. Formal grammars in general are used for language recognition or generation. In this paper we present the automatic generation of procedural programs in Python using a CFG. We have defined CFG rules to model program templates and implemented these rules to produce infinitely many distinct practice programs in Python. Each generated program is designed to test a novice programmer’s knowledge of functions, expressions, loops, and/or conditional statements. The CFG rules are highly generic and can be extended to generate programs in other procedural languages. The resulting programs can be used as practice, test or examination problems in introductory programming courses. 500,000 iterations of generated programs can be found at: A survey of 103 students’ perception showed that 93.1% strongly agreed that these programs can help them in practice and improve their programming skills.


Synthesis of things Program synthesis Practice Python programs Novice programmers Context-free grammar applications 


  1. 1.
    Ade-Ibijola, A.: Synthesis of regular expression problems and solutions. Int. J. Comput. Appl. 1–17 (2018)
  2. 2.
    Ade-Ibijola, A.: Synthesis of social media profiles using a probabilistic context-free grammar. In: PRASA-RobMech 2017, Proceedings of Pattern Recognition Association of South Africa and Robotics and Mechatronics, pp. 104–109. IEEE (2017)Google Scholar
  3. 3.
    Ade-Ibijola, A., Ewert, S., Sanders, I.: Abstracting and narrating novice programs using regular expressions. In: SAICSIT 2014, Proceedings of Annual Conference of the South African Institute for Computer Scientist and Information Technologists, pp. 19–28. ACM (2014)Google Scholar
  4. 4.
    Ahmed, U.Z., Gulwani, S., Karkare, A.: Automatically generating problems and solutions for natural deduction. In: Proceedings of IJCAI 2013, pp. 1968–1975 (2013)Google Scholar
  5. 5.
    Aho, A.V., Sethi, R., Ullman, J.D.: Compilers: Principles, Techniques, and Tools. Addison-Wesley, Boston (1986)zbMATHGoogle Scholar
  6. 6.
    Alqadi, B.S., Maletic, J.I.: An empirical study of debugging patterns among novices programmers. In: Proceedings of the 2017 ACM SIGCSE Technical Symposium on Computer Science Education, pp. 15–20 (2017)Google Scholar
  7. 7.
    Baker, A., Zhang, J., Caldwell, E.R.: Reinforcing array and loop concepts through a game-like module. In: CGAMES 2012, Proceedings of 17th International Conference on Computer Games, pp. 175–179. IEEE (2012)Google Scholar
  8. 8.
    Bergin, S., Mooney, A., Ghent, J., Quille, K.: Using machine learning techniques to predict introductory programming performance. Int. J. Comput. Sci. Softw. Eng. 4(12), 323–328 (2015)Google Scholar
  9. 9.
    Butler, M., Morgan, M.: Learning challenges faced by novice programming students studying high level and low feedback concepts. In: Proceedings of 24th ASCILITE Conference, pp. 2–5 (2007)Google Scholar
  10. 10.
    Dale, N.B.: Most difficult topics in CS1: results of an online survey of educators. ACM SIGCSE Bull. 38(2), 49–53 (2006)MathSciNetCrossRefGoogle Scholar
  11. 11.
    Fincher, S.: What are we doing when we teach programming? In: Proceedings of 29th Annual Frontiers in Education Conference, p. 12A4 (1999)Google Scholar
  12. 12.
    Foote, S.: Learning to Program. Addison-Wesley, Boston (2014)Google Scholar
  13. 13.
    Gulwani, S., Korthikanti, V.A., Tiwari, A.: Synthesizing geometry constructions. ACM SIGPLAN Not. 46(6), 50–61 (2011)CrossRefGoogle Scholar
  14. 14.
    Haiduc, S., Aponte, J., Marcus, A.: Supporting program comprehension with source code summarization. In: ICSE 2010, Proceedings of 32nd International Conference on Software Engineering, pp. 223–226 (2010)Google Scholar
  15. 15.
    Hill, G.J.: Review of a problems-first approach to first year undergraduate programming. In: Kassel, S., Wu, B. (eds.) Software Engineering Education Going Agile, pp. 73–80. Springer, Cham (2016). Scholar
  16. 16.
    Iqbal-Malik, S.: Role of ADRI model in teaching and assessing novice programmers. Technical report, Deakin University (2016)Google Scholar
  17. 17.
    Jenkins, T.: On the difficulty of learning to program. In: Proceedings of 3rd Annual Conference of the LTSN Centre for Information and Computer Sciences, pp. 53–58 (2002)Google Scholar
  18. 18.
    Johnson, W.L.: Understanding and debugging novice programs. Artif. Intell. 42(1), 51–97 (1990)CrossRefGoogle Scholar
  19. 19.
    Lahtinen, E., Ala-Mutka, K., Järvinen, H.M.: A study of the difficulties of novice programmers. ACM SIGCSE Bull. 37(3), 14–18 (2005)CrossRefGoogle Scholar
  20. 20.
    Lucariello, J.M., Nastasi, B.K., Anderman, E.M., Dwyer, C., Ormiston, H., Skiba, R.: Science supports education: the behavioral research base for psychology’s top 20 principles for enhancing teaching and learning. Mind Brain Educ. 10(1), 55–67 (2016)CrossRefGoogle Scholar
  21. 21.
    Malik, S.I., Coldwell-Neilson, J.: A model for teaching an introductory programming course using ADRI. Educ. Inf. Technol. 22(3), 1089–1120 (2017)CrossRefGoogle Scholar
  22. 22.
    Martin, J.: Introduction to Languages and the Theory of Computation. McGraw-Hill, New York (2003)Google Scholar
  23. 23.
    Mathrani, A., Christian, S., Ponder-Sutton, A.: PlayIT: game based learning approach for teaching programming concepts. Educ. Technol. Soc. 19(2), 5–17 (2016)Google Scholar
  24. 24.
    Miljanovic, M.A., Bradbury, J.S.: Robot ON!: a serious game for improving programming comprehension. In: GAS 2016, Proceedings of 5th International Workshop on Games and Software Engineeing, pp. 33–36. ACM (2016)Google Scholar
  25. 25.
    Özmen, B., Altun, A.: Undergraduate students’ experiences in programming: difficulties and obstacles. Turk. Online J. Qual. Inq. 5(3), 1–27 (2014)Google Scholar
  26. 26.
    Ramalingam, V., Wiedenbeck, S.: An empirical study of novice program comprehension in the imperative and object-oriented styles. In: Proceedings of 7th Workshop on Empirical Studies of Programmers, pp. 124–139. ACM (1997)Google Scholar
  27. 27.
    Sadigh, D., Seshia, S.A., Gupta, M.: Automating exercise generation: a step towards meeting the MOOC challenge for embedded systems. In: Proceedings of Workshop on Embedded and Cyber-Physical Systems Education, p. 2. ACM (2012)Google Scholar
  28. 28.
    Shargabi, A., Aljunid, S.A., Annamalai, M., Shuhidan, S.M., Zin, A.M.: Tasks that can improve novices’ program comprehension. In: Proceedings of IEEE Conference on e-Learning, e-Management and e-Services, pp. 32–37 (2015)Google Scholar
  29. 29.
    Sharples, M., et al.: Innovating Pedagogy 2016. Open University Innovation Report 5 (2016)Google Scholar
  30. 30.
    Siegfried, R.M., Siegfried, J., Alexandro, G.: A longitudinal analysis of the Reid list of first programming languages. Inf. Syst. Educ. J. 14(6), 47 (2016)Google Scholar
  31. 31.
    Singh, R., Gulwani, S., Rajamani, S.K.: Automatically generating algebra problems. In: AAAI 2012, Proceedings of 26th Conference on AI (2012)Google Scholar
  32. 32.
    Storey, M., Best, C., Michand, J.: SHriMP views: an interactive environment for exploring Java programs. In: Proceedings of 9th International Workshop on Program Comprehension, pp. 111–112. IEEE (2001)Google Scholar
  33. 33.
    Storey, M.A.: Theories, tools and research methods in program comprehension: past, present and future. Softw. Qual. J. 14(3), 187–208 (2006)CrossRefGoogle Scholar
  34. 34.
    Wang, T., Su, X., Ma, P., Wang, Y., Wang, K.: Ability-training-oriented automated assessment in introductory programming course. Comput. Educ. 56(1), 220–226 (2011)CrossRefGoogle Scholar
  35. 35.
    Yadin, A.: Reducing the dropout rate in an introductory programming course. ACM Inroads 2(4), 71–76 (2011)CrossRefGoogle Scholar
  36. 36.
    Zhang, J., Atay, M., Caldwell, E.R., Jones, E.J.: Visualizing loops using a game-like instructional module. In: ICALT 2013, Proceedings of 13th IEEE International Conference on Advanced Learning Technology, pp. 448–450 (2013)Google Scholar

Copyright information

© Springer Nature Switzerland AG 2019

Authors and Affiliations

  1. 1.Department of Applied Information SystemsUniversity of JohannesburgJohannesburgSouth Africa

Personalised recommendations