January 2013
Intermediate to advanced
328 pages
8h 5m
English
For our first project, let’s build a grammar for a tiny subset of C or one of its derivatives like Java. In particular, let’s recognize integers in, possibly nested, curly braces like {1, 2, 3} and {1, {2, 3}, 4}. These constructs could be int array or struct initializers. A grammar for this syntax would come in handy in a variety of situations. For one, we could use it to build a source code refactoring tool for C that converted integer arrays to byte arrays if all of the initialized values fit within a byte. We could also use this grammar to convert initialized Java short arrays to strings. For example, we could transform the following:
| | static short[] data = {1,2,3}; |
into the following equivalent string ...
Read now
Unlock full access