Posts

Showing posts with the label grammars

On computing all patterns matched by a regular expression

Image
[Code/código: regexPrinter ] A regular expression , without much rigor, is a very compact way of representing several different strings. One common use of regular expressions is to look for strings that have a certain structure in a bigger string (say a text). As an example, the regular expression abc(d|e) can be used to look for the strings "abcd" and "abce", where the character | denotes we have to make a choice. Thus cat|dog would match the strings "cat" and "dog". There are other special symbols that have meanings and purposes. One very interesting question that arises is: given a regular expression, what are the strings matched by it? To answer that question I wrote a small Python program, that I called regexPrinter , that prints all strings matched by a given regular expression! In order to manage that task, I chose a subset of the regex syntax that I wanted to be able to print and also decided that whenever a piece of a pattern was inf...

Creating a programming language from scratch!

Image
Python is the programming language I am more comfortable with, by far; at an early stage of my learning I heard that Python was built on top of C. Whatever that meant. Then I started thinking of it in this way: programming languages are used to build programs. Someone used C to create another program, that can be used to create even more programs! That seemed reasonable. At some point in time I got interested in compilers and interpreters and all those weird things, and I came across this wonderful blog post. I immediately started following the "Let's Build a Simple Interpreter" series to write my own Pascal interpreter with Python, which is the aim of that series. At that time there were only 5 or 6 posts, and I got to the point where I had done everything he told us to do and couldn't wait for the other posts, as I noticed the frequency with which the author posted in that series was rather low. At that point, my project's aim diverged of that of the blog and I...