Regular Expressions in a CS Formal Languages Course

Marco T. Morazán
DOI: https://doi.org/10.4204/EPTCS.382.3
2023-08-14
Abstract:Regular expressions in an Automata Theory and Formal Languages course are mostly treated as a theoretical topic. That is, to some degree their mathematical properties and their role to describe languages is discussed. This approach fails to capture the interest of most Computer Science students. It is a missed opportunity to engage Computer Science students that are far more motivated by practical applications of theory. To this end, regular expressions may be discussed as the description of an algorithm to generate words in a language that is easily programmed. This article describes a programming-based methodology to introduce students to regular expressions in an Automata Theory and Formal Languages course. The language of instruction is FSM in which there is a regular expression type. Thus, facilitating the study of regular expressions and of algorithms based on regular expressions.
Formal Languages and Automata Theory,Programming Languages
What problem does this paper attempt to address?
### Problems the Paper Attempts to Solve This paper aims to address the disconnect between theory and practice in teaching regular expressions in formal language courses in computer science (CS). Specifically: 1. **Disconnect between Theory and Practice**: Traditional courses on formal languages and automata theory mainly focus on the mathematical properties of regular expressions and their ability to describe languages. This often leads to a lack of interest among most computer science students, who are more inclined towards practical applications. 2. **Enhancing Student Interest**: By introducing regular expressions as an algorithm for generating language members, the paper aims to increase student interest in the subject. This approach allows students to understand and apply regular expressions through programming practice. 3. **Programming Practice**: The paper proposes a programming-based approach for students to learn regular expressions in formal language and automata theory courses. Using FSM (Finite State Machine) languages as a teaching tool, students can write and implement programs for regular expressions. ### Summary of Main Content 1. **Introduction to Regular Expressions**: The paper first introduces the definition of regular expressions and their representation in FSM. 2. **Programming Examples**: It provides specific programming examples, such as generating regular expressions for all strings ending with the letter "a". 3. **Generating Binary Numbers**: It discusses in detail how to use regular expressions to generate binary numbers without leading zeros and implements a random generation function. 4. **Generating Words for Arbitrary Regular Expressions**: It proposes a general algorithm for generating words in the language described by any regular expression. Through these methods, the paper attempts to help students better understand the practical and algorithmic aspects of regular expressions, rather than just their theoretical background.