Automatic Generation of Python Programs Using Context-Free Grammars

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Yamani, Kamel, Naïr, Marwa, Baghdadi, Riyadh
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866917610326589440
author Yamani, Kamel
Naïr, Marwa
Baghdadi, Riyadh
author_facet Yamani, Kamel
Naïr, Marwa
Baghdadi, Riyadh
contents In recent years, data has emerged as the new gold, serving as a powerful tool for creating intelligent systems. However, procuring high-quality data remains challenging, especially for code. To address this, we developed TinyPy Generator, a tool that generates random Python programs using a context-free grammar. The generated programs are guaranteed to be correct by construction. Our system uses custom production rules (in the Backus-Naur Form (BNF) format) to recursively generate code. This allows us to generate code with different levels of complexity, ranging from code containing only assignments to more complex code containing conditionals and loops. Our proposed tool enables effortless large-scale Python code generation, beneficial for a wide range of applications. TinyPy Generator is particularly useful in the field of machine learning, where it can generate substantial amounts of Python code for training Python language models. Additionally, researchers who are studying programming languages can utilize this tool to create datasets for their experiments, which can help validate the robustness of code interpreters or compilers. Unlike existing research, we have open-sourced our implementation. This allows customization according to user needs and extends potential usage to other languages.
format Preprint
id arxiv_https___arxiv_org_abs_2403_06503
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Automatic Generation of Python Programs Using Context-Free Grammars
Yamani, Kamel
Naïr, Marwa
Baghdadi, Riyadh
Programming Languages
Computation and Language
Machine Learning
In recent years, data has emerged as the new gold, serving as a powerful tool for creating intelligent systems. However, procuring high-quality data remains challenging, especially for code. To address this, we developed TinyPy Generator, a tool that generates random Python programs using a context-free grammar. The generated programs are guaranteed to be correct by construction. Our system uses custom production rules (in the Backus-Naur Form (BNF) format) to recursively generate code. This allows us to generate code with different levels of complexity, ranging from code containing only assignments to more complex code containing conditionals and loops. Our proposed tool enables effortless large-scale Python code generation, beneficial for a wide range of applications. TinyPy Generator is particularly useful in the field of machine learning, where it can generate substantial amounts of Python code for training Python language models. Additionally, researchers who are studying programming languages can utilize this tool to create datasets for their experiments, which can help validate the robustness of code interpreters or compilers. Unlike existing research, we have open-sourced our implementation. This allows customization according to user needs and extends potential usage to other languages.
title Automatic Generation of Python Programs Using Context-Free Grammars
topic Programming Languages
Computation and Language
Machine Learning
url https://arxiv.org/abs/2403.06503