Exercise 32:

Number lists
Note: this problem is taken from the Programming Languages subject at Barcelona School of Informatics.

Design a parser to describe heterogeneous lists of numbers. The following example shows the elements of the language:
  L1 = []
  L2 = [1,2,3]
  L3 = L1#L2
  L4 = [[[1,2],3],4]
  L5 = lreduce + L4
  L6 = lmap - 1 L4
  print L5
  L7 = lfilter > 2 L4
Make the grammar so that the parser generator builds the following AST for the previous example:
  list
   \__=
   |   \__L1
   |   \__[
   \__=
   |   \__L2
   |   \__[
   |       \__1
   |       \__2
   |       \__3
   \__=
   |   \__L3
   |   \__#
   |       \__L1
   |       \__L2
   \__=
   |   \__L4
   |   \__[
   |       \__[
   |       |   \__[
   |       |   |   \__1
   |       |   |   \__2
   |       |   \__3
   |       \__4
   \__=
   |   \__L5
   |   \__lreduce
   |             \__+
   |             \__L4
   \__=
   |   \__L6
   |   \__lmap
   |          \__-
   |          |   \__1
   |          \__L4
   \__print
   |       \__L5
   \__=
       \__L7
       \__lfilter
                 \__>
                 |   \__2
                 \__L4
Remarks:
Authors: Nil Mamano / Documentation:
To be able to submit you need to either log in, register, or become a guest.