Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your grammar a single id can either be matched by the production <code>Expr ::= id</code> or <code>Expr ::= id Expr*</code>. In other words there's no way to distinguish between a nullary function application (assuming the <code>id Expr*</code> production is supposed to match function applications) and variables. Maybe you meant <code>id Expr+</code> instead (disallowing nullary function applications).</p> <p>Your existing code looks fine, but it's incomplete:</p> <p>Your <code>expr</code> type is missing a constructor for the <code>id Expr*</code> production of the grammar, i.e. you're missing a constructor that represents function applications. You should add one and then add a case for it to the <code>evaluate</code> function as well.</p> <p>In your <code>evaluate</code> function you're missing a case for the <code>Id</code> constructor. That case should lookup the value of the given identifier in a mapping from identifiers to values (ints). To that end your <code>evaluate</code> function should take such a mapping as an additional argument. It should also take another mapping from identifiers to functions, which you can then use to loop up function names in the case for function applications.</p> <p>Speaking of those mappings, you currently don't have any code to represent or process definitions. You should come up with a type to represent a definition and another to represent functions. The latter type should contain the name of the function parameters and the body as an <code>expr</code>.</p> <p>Then you should write a function that takes a list of definitions and creates the mappings for variables and functions. For each variable definition it should evaluate the expression on the right and add the resulting values to your variable mapping. For each function definition, you should add a value of your function type to the function mapping. After processing the definitions, you should evaluate the final expression by calling your <code>evaluate</code> function with that expression and the two mappings you created as arguments.</p> <p>Finally you don't have any code for actually parsing the program, but I think that might be intentional.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload