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

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:

Submission 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 exercises while you do others cheapens your educational experience and leaves you behind. It is best for each student to do all of the exercises, 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 exercises, 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:

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.

Exercises

  1. Give the AST for the following JavaScript program, 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 far more verbose than expected for hand-drawn ASTs.)
    let [x, y] = [0, 0];
    console.log(93.8 * 2 ** x + y);
    
  2. Draw the AST for the following JavaScript program, using the level of detail we used during class.
    import x from "x"
    console.log(93.8 * {x} << x.r[z])
    
  3. Draw the AST for the following JavaScript program, using the level of detail we used during class.
    const x = x / {[x]: `${x}`}[x]("y")
    
  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, b: c}) {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. Hint: Check your grammar with the Ohm Editor so that you don’t needlessly throw away points.

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.