CS 3040, Assignment 2: Designing a Programming Language

This assignment is intended to give you experience in writing grammars. Develop a grammar for the following programming language. In this language, the basic data type is a matrix. A sample program is

        define cube(values)
          assert values has dimension [4, 4];
          return values * values * values;
        end

        dim [4, 4] z, y;
        z = [1,  2, 3, 4,
             5,  6, 7, 8,
             9, 10,11,12,
             13,14,15,16];
        y = cube(z);
        if y > z then
          y = z - y;
        else
          y = y - z;
        end
        display y;
Specifically,

There are likely aspects of this language that the above list fails to specify. In those cases, you can make your own choices. This language is inspired by the data science language R, but avoids some of its quirkier aspects. There is no need to research R for this assignment!

Working with one or two partners, you are to write a grammar for this language. Use initial capital letters for nonterminals, single quote marks around terminals, and no quote marks around regular expressions. Thus a couple rules might look like

        Aaa → Bbb 'xyz' '.'
        Bbb → [a-z]+
As usual, the non-terminal being defined in the first production will be interpreted as being the start symbol, so there is no need to write out the full grammar in tuple form.

In addition, add one other feature to your language. Possible features:

Alternatively, you can add a similar feature of your own choosing. Feel free to borrow ideas from other languages you know - good programming language designers do that all the time! If you do, it would be a good idea to name your source in your report.

Teams with three students are to add two additional features.

Note that this assignment is focused on just specifying the syntax of programs. A full implementation would include checks on dimensions (to ensure multiplication, addition are legal) as well as other aspects. Those are not part of this assignment. We will may implement some of this language later, but you would have opportunity to revise your grammar when you do that.

Additional Notes

Submission

Type up your grammar as a word-processed document (Word, Google Docs) or use a tool like OneNote. You can simply use -> for arrows and do not have to italicize non-terminals. You should be able to use ε to signal an empty string, but if for some reason your word-processing environment does not allow epsilon you can use a different symbol (that's well defined) for that. Sometimes it's convenient to have a grammar rule Empty -> ε.

Include the following in your document:

Upload your document as a PDF.