LMU ☀️ CMSI 3802
LANGUAGES AND AUTOMATA II
HOMEWORK #1 Due: 2024-01-26

Learning Objectives

In this assignment you will demonstrate:

Readings, Videos, and Self-Study

Although your team will be turning in only one submission, every team member is individually responsible for each of the following:

Instructions

All homework in this class is to be done in your three to six-person group. DO NOT “partition” the work. Letting a team member do some problems while you do others cheapens your educational experience and leaves you behind. It is best for each student to do all of the problems, then meet as a group to (1) select the “best” answer for submission when more than one exist, and (2) teach each other. If one group member is unable to do one of the problems, another group member can teach that student how it do it. Everyone is responsible for understanding the entire homework submission, so everyone should contribute to the entire assignment.

Select one student to upload the single submission for the entire team.

Your team's BrightSpace submission should be an attached PDF or text file with:

  1. The names of every student
  2. For each student, an affidavit that each of the readings/watchings above were individually completed
  3. Answers to each ot the “Problems to Turn In,” numbered and neatly typeset
  4. A link to the public GitHub repository hosting your team’s project (This is to be a public GitHub repository named after the language you are creating. You will use this repo to host your compiler project, which will grow during each assignment. By the end of the term it will be amazing.)

Add me as a committer to your repository. My github name is rtoal. This will help me help you during office hours if your project seems to be flailing.

Problems to Turn In

Solutions to these problems will appear in the beautifully formatted PDF that you will submit to BrightSpace. For problems involving code to write, host your code on GitHub or Replit or OneCompiler (or similar) and provide the link to the hosting site in your BrightSpace submission.

  1. For the following complete JavaScript program, draw the AST, using the level of detail we used during class. You can use my JS AST Viewer to guide you and check your work, but remember, the drawing you need to produce for full credit will be far less verbose than the tool’s output. (Remember, the tool uses a third-party parser, esprima-next, that provides a complete ESTree-compliant AST, which is more verbose than hand-drawn ASTs.)
      let [x, y] = [0, 0];
      console.log(93.8 * 2 ** x + y);
    
  2. For the following complete JavaScript program, draw the AST, using the level of detail we used during class.
      import x from "x"
      console.log(93.8 * {x} << x.r[z])
    
  3. For the following JavaScript fragment (not a complete program), draw the AST, using the level of detail we used during class. By “not a complete program” I mean it suffices to leave off the root Program node; give only the AST for the expression.
      x / {[x]: `${x}`}[x]
    
  4. For the following JavaScript fragment (not a complete program), draw the AST, using the level of detail we used during class.
      class C {
        f({a}) {return ([a,f]) => C}
      }
    
  5. For each scenario below, give Ohm grammar rules for Exp, Term, Factor, and Primary that make the expression -2**2:
    1. Evaluate to 4.
    2. Evaluate to -4.
    3. Be a syntax error, while allowing (-2)**2 and -(2**2) to be legal.
  6. Astro is a really tiny language, so we'd like to make Astro++. This new language adds an if-statement, a while statement, a break statement, and relational operators. The while statement should start with the keyword while, followed by a test expression, followed by a block (a curly-brace delimited sequence of statements). The if-statement should start with the keyword if, followed by a test expression, then a block, then an optional else-part which is the keyword else followed by either a block or another if-statement. Neither the while statement nor the if statement should end with a semicolon. The break statement is only allowed to appear in a while statement’s block. The relational operators are the same as those in Python and are to be NON-associative. All of the relational operators are on the same precedence level, lower than all other operators. Give the syntax of Astro++ using Ohm.

For Your Project

In this class you will not only be writing a compiler—you will be writing a compiler for a language that you design yourself. You have wide latitude in designing your language: I want you to design a language you can actually love. The only requirements are: (1) it must be of sufficient complexity (i.e., enough interesting features, including features beyond the example languages we see in class), and (2) it requires significant work in the static analysis phase. You can satisfy the latter requirement with a statically-typed language with static scoping (in addition to a few other checks of course), but it may be possible to design a dynamically typed language, provided you define a significant number of statically checked contextual constraints. If you go with a dynamically-typed language, you should check with me first to make sure your workload is fair.

Grading Rubric

To help you get a good score, here are all the things you will be graded on.