Skip to content

Parser rejects structured (aggregate) initializers in VAR declarations — Expected RParen, found := #206

Description

@dreamclass

Problem

Summary

STruC++ cannot parse an IEC 61131-3 structured initial value — the
( field := value, field := value, ... ) aggregate-initializer syntax used to
give a STRUCT-typed variable a default value in its declaration. The parser
reaches the first field := inside the parentheses, expects a closing ), and
aborts.

Environment

  • STruC++ version: 0.6.2 (strucpp.exe, win64)

Impact

Compilation fails during parsing

Reproduction

Steps to reproduce

udt.st:

TYPE
    inner : STRUCT
        a : INT;
        b : INT;
    END_STRUCT;
    outer : STRUCT
        p : inner;
        q : INT;
    END_STRUCT;
END_TYPE

PROGRAM PLC_PRG
VAR
    s : outer := ( p := ( a := 1, b := 2 ), q := 3 );
END_VAR
    s.q := s.q + 1;
END_PROGRAM
strucpp udt.st -o udt.cpp --no-default-libs

Actual result

Compilation fails during parsing:

Compilation failed:

udt.st:14:22: error: Expected `RParen`, found `:=`.
  14 |     s : outer := ( p := ( a := 1, b := 2 ), q := 3 );
     |                      ^

Code Locations

No response

Fix

No response

Acceptance

STruC++ can parse an IEC 61131-3 structured initial value — the
( field := value, field := value, ... ) aggregate-initializer syntax used to
give a STRUCT-typed variable a default value in its declaration.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions