0
votes

I would like to know how can I fix this error?

The following sets of rules are mutually left-recursive [type, array_type]

The goal is to achieve something like this:

(array type) type -> type [ expr ]

that should be included in the type parameter. Any help would be appreciated

The following code:

// Types
type
  : atomic_type
  | named_type
  | pointer_type
  | record_type
  | enclosed_type
  | array_type
  ;

atomic_type
  : VOID
  | CHAR
  | INTEGER
  | BOOLEAN
  ;

named_type
  : IDENTIFIER
  ;

// LEFT SIDE RECURSION, SHOULD BE INCLUDED IN TYPE ABOVE
array_type
  : type MLBRACE expr MRBRACE
  ;

pointer_type
  : CARET type
  ;

record_type
  : BLBRACE IDENTIFIER COLON type BLBRACE (COMMA? IDENTIFIER COLON type) BRBRACE BRBRACE
  ;

enclosed_type
  : SLBRACE type SRBRACE 
  ;

EDIT: I already in the lines of:

type
  : atomic_type
  | named_type
  | pointer_type
  | record_type
  | enclosed_type
  | type MLBRACE expr MRBRACE
  ;

but my question is, is it possible to have array_type instead of type MLBRACE expr MRBRACE?

1

1 Answers

1
votes

No, that is not possible. You cannot use indirect left recursion in ANTLR4, period.