Skip to content

Support multi-dimensional arrays ([][n]TYPE) #64

@associate-1

Description

@associate-1

Difficulty: Medium — Parser, AST, and codegen must all support nested array dimensions.

Summary

Occam supports multi-dimensional arrays such as [][2]BYTE (open first dimension, fixed second) and [n][m]TYPE (both fixed). These are currently not parsed.

Occam syntax

VAL [][2]BYTE pairs IS [['A', 'a'], ['B', 'b']]:

[10][20]INT grid:

Proposed Go mapping

var pairs = [][2]byte{{'A', 'a'}, {'B', 'b'}}

var grid [10][20]int

Or using slices for open dimensions:

var pairs [][]byte = [][]byte{{'A', 'a'}, {'B', 'b'}}

Affected files

  • bar.occ (multi-dim array params/declarations)
  • test_utils.occ (line 19: VAL [][2]BYTE)

Work required

  1. Parser: After parsing [n], check for another [ to handle nested array dimensions
  2. AST: Extend array type representation to support multiple dimensions
  3. Codegen: Generate nested Go array/slice types

Part of #43.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions