Skip to content

iec61131: Struct definition does not allow Array Init #5

Description

@Jan-Bulthuis

Thank you for your work on this project! I hope to be able to use it to perform some codegen from the ST AST. However, I did run into an issue.

The generated parser parses a struct type as follows (leaving out some irrelevant bits):

while !self.check(&Token::EndStruct) {
    let name = self.expect_identifier()?;
    self.expect(Token::Colon)?;
    let field_type = self.parse_type_spec()?;
    
    let init_value = if self.match_token(&Token::Assign) {
        Some(self.parse_expression()?)
    } else {
        None
    };
}

when a field has an initializer, this is parsed using parse_expression. However this method diverges slightly from the grammar rules set forth by IEC61131-3 2013. Specifically, parse_expression does not allow array initialization as below

TYPE TEST_TYPE :
STRUCT
    ARR : ARRAY [1..2] OF REAL := [1.0, 2.0];
END_STRUCT;
END_TYPE

because [1.0, 2.0] is not a valid expression.

Similarly, arrays with initialization also do not seem to be allowed. The following also gives an error when parsing:

TYPE ARR_TYPE :
    ARRAY [1..16] OF REAL := [1.0, 2.0];
END_TYPE

If you would be willing to share how you generate the ast/parser/lexer files I would be more than happy to take a look myself and to submit a PR.

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions