Closed edwada closed 9 years ago
The grammar:
entrypoints Library_element_declaration_list ;
rules Library_element_declaration_list ::= Library_element_declaration Library_element_declaration_list | ;
-- Entrypoint -- library_element_declaration ::= data_type_declaration | function_declaration | function_block_declaration | program_declaration | configuration_declaration rules Library_element_declaration ::= Program_declaration | Data_type_declaration | Function_declaration | Function_block_declaration | Configuration_declaration ;
-- program_declaration ::= ’PROGRAM’ program_type_name { io_var_declarations | other_var_declarations | located_var_declarations | program_access_decls } function_block_body ’END_PROGRAM’ rules Program_declaration ::= "PROGRAM" Program_type_name ProgramVarAndAccessDeclarations Function_block_body "END_PROGRAM" ; rules ProgramVarAndAccessDeclaration ::= Other_var_declarations | Io_var_declarations | Located_var_declarations | Program_access_decls ; rules ProgramVarAndAccessDeclarations ::= ProgramVarAndAccessDeclaration ProgramVarAndAccessDeclarations | ;
-- other_var_declarations ::= external_var_declarations | var_declarations | retentive_var_declarations | non_retentive_var_declarations | temp_var_decls | incompl_located_var_declarations rules Other_var_declarations ::= Var_declarations | External_var_declarations | Retentive_var_declarations | Non_retentive_var_declarations | Temp_var_decls | Incompl_located_var_declarations ;
-- var_declarations ::= ’VAR’ [’CONSTANT’] var_init_decl ’;’ {(var_init_decl ’;’)} ’END_VAR’ VarDeclarations. Var_declarations ::= "VAR" OptionalConstantToken VarInitDeclList "END_VAR" ; rules OptionalConstantToken ::= "CONSTANT" | ;
-- incompl_located_var_declarations ::= ’VAR’ [’RETAIN’|’NON_RETAIN’] incompl_located_var_decl ’;’ {incompl_located_var_decl ’;’} ’END_VAR’ rules IncomplLocatedVarDeclList ::= Incompl_located_var_decl ";" | Incompl_located_var_decl ";" IncomplLocatedVarDeclList ; rules IncomplLocatedVarDeclInit ::= "VAR" | "VAR" "RETAIN"| "VAR" "NON_RETAIN" ; IncomplLocatedVarDeclarations. Incompl_located_var_declarations ::= IncomplLocatedVarDeclInit IncomplLocatedVarDeclList "END_VAR" ;
-- output_declarations ::= ’VAR_OUTPUT’ [’RETAIN’ | ’NON_RETAIN’] var_init_decl ’;’ {var_init_decl ’;’} ’END_VAR’ rules VarInitDeclList ::= Var_init_decl ";" VarInitDeclList | Var_init_decl ";" ; rules OutputDeclInit ::= "VAR_OUTPUT" "RETAIN" | "VAR_OUTPUT" "NON_RETAIN" | "VAR_OUTPUT"; OutputDeclarations. Output_declarations ::= OutputDeclInit VarInitDeclList "END_VAR" ;
-- function_block_body ::= ladder_diagram | function_block_diagram | instruction_list | statement_list |
-- statement_list ::= statement ’;’ {statement ’;’} rules Statement_list ::= Statement ";" | Statement ";" Statement_list ;
-- statement ::= NIL | assignment_statement | subprogram_control_statement | selection_statement | iteration_statement rules Statement ::= | Assignment_statement | Subprogram_control_statement | Selection_statement | Iteration_statement ;
-- {MACROS} -- letter ::= ’A’ | ’B’ | <...> | ’Z’ | ’a’ | ’b’ | <...> | ’z’ -- digit ::= ’0’ | ’1’ | ’2’ | ’3’ | ’4’ | ’5’ | ’6’ | ’7’ | ’8’ |’9’ -- octal_digit ::= ’0’ | ’1’ | ’2’ | ’3’ | ’4’ | ’5’ | ’6’ | ’7’ -- hex_digit ::= digit | ’A’| ’B’ | ’C’ | ’D’ | ’E’ | ’F’ -- common_character_representation ::= <any printable character except ’$’, ’"’ or "’"> | ’$$’ | ’$L’ | ’$N’ | ’$P’ | ’$R’ | ’$T’ | ’$l’ | ’$n’ | ’$p’ | ’$r’ | ’$t’ -- commonCharacter letter | digit | '$''$' | '$''L' | '$''N' | '$''P' | '$''R' | '$''T' | '$''1' | '$''n' | '$''p' | '$''r' | '$''t' -- single_byte_character_representation ::= common_character_representation | "$’" | ’"’ | ’$’ hex_digit hex_digit -- single_byte_character_representation :: letter | digit | '$''$' | '$''L' | '$''N' | '$''P' | '$''R' | '$''T' | '$''1' | '$''n' | '$''p' | '$''r' | '$''t' | "$’" | ’"’ | ’$’ hex_digit hex_digit -- double_byte_character_representation ::= common_character_representation | ’$"’ | "’"| ’$’ hex_digit hex_digit hex_digit hex_digit
-- identifier ::= (letter | (’’ (letter | digit))) {[’’](letter | digit)} token Identifier (["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] | ('' (["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] | ["0123456789"]))) (''? (["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] | ["0123456789"]))* ; -- integer ::= digit {[’’] digit} --token Integer ["0123456789"](''? ["0123456789"])* ; -- signedinteger ::= [’+’ |’-’] integer token SignedInteger ["+-"]? ["0123456789"](''? ["0123456789"])* ; -- bit ::= ’1’ | ’0’ token Bit ["01"] ; -- binaryinteger ::= ’2#’ bit {[’’] bit} token BinaryInteger '2' '#' ["01"]('_' ["01"])* ; -- octal_integer ::= ’8#’ octaldigit {[’’] octal_digit} token OctalInteger '8' '#' "01234567"* ; -- hex_integer ::= ’16#’ hexdigit{[’’] hexdigit} token HexInteger '1' '6' '#' ["0123456789ABCDEF"]('' ["0123456789ABCDEF"]) ; -- exponent ::= (’E’ | ’e’)[’+’|’-’] integer token Exponent ["eE"] ["+-"]? ["0123456789"]('_'? ["0123456789"])* ; -- single_byte_character_string ::= "’" single_byte_character_representation} "’" token Single_byte_character_string '\'' (letter | digit | '$''$' | '$''L' | '$''N' | '$''P' | '$''R' | '$''T' | '$''1' | '$''n' | '$''p' | '$''r' | '$''t' | '$''\'' | '"' | '$' ["0123456789ABCDEF"] ["0123456789ABCDEF"])* '\'' ; -- double_byte_character_string ::= ’"’ (letter | digit | '$''$' | '$''L' | '$''N' | '$''P' | '$''R' | '$''T' | '$''1' | '$''n' | '$''p' | '$''r' | '$''t' | '$''"' | '\'' | '$' ["0123456789ABCDEF"] ["0123456789ABCDEF"] ["0123456789ABCDEF"] ["0123456789ABCDEF"])* ’"’ token AbsDouble_byte_characterstring '"' (letter | digit | '$''$' | '$''L' | '$''N' | '$''P' | '$''R' | '$''T' | '$''1' | '$''n' | '$''p' | '$''r' | '$''t' | '$''"' | '\'' | '$' ["0123456789ABCDEF"] ["0123456789ABCDEF"] ["0123456789ABCDEF"] ["0123456789ABCDEF"])* '"' ; token FloatToken ["+-"]? ["0123456789"](''? ["0123456789"])* '.' ["0123456789"](''? ["0123456789"])* (["eE"] ["+-"]? ["0123456789"](''? ["0123456789"])*)? ;
CSignedInteger. AbsSignedInteger ::= SignedInteger ;
-- signed_integer_type_name ::= ’SINT’ | ’INT’ | ’DINT’ | ’LINT’ SintTypeName. Signed_integer_type_name ::= "SINT" ; IntTypeName. Signed_integer_type_name ::= "INT" ; DIntTypeName. Signed_integer_type_name ::= "DINT" ; LIntTypeName. Signed_integer_type_name ::= "LINT" ;
-- unsigned_integer_type_name ::= ’USINT’ | ’UINT’ | ’UDINT’ | ’ULINT’ UsintTypeName. Unsigned_integer_type_name ::= "USINT" ; UintTypeName. Unsigned_integer_type_name ::= "UINT" ; UdintTypeName. Unsigned_integer_type_name ::= "UDINT" ; UlintTypeName. Unsigned_integer_type_name ::= "ULINT" ;
-- integer_type_name ::= signed_integer_type_name | unsigned_integer_type_name SignedIntegerTypeName. StateInteger_type_name ::= Signed_integer_type_name ; UnsignedIntegerTypeName. StateInteger_type_name ::= Unsigned_integer_type_name ;
-- integer_literal ::= [ integer_type_name ’#’ ](signed_integer | binary_integer | octal_integer | hex_integer) rules IntegerValue ::= AbsSignedInteger | BinaryInteger | OctalInteger | HexInteger ; rules StateInteger_literal ::= StateInteger_type_name "#" IntegerValue | IntegerValue ;
-- real_type_name ::= ’REAL’ | ’LREAL’ RealTypeName. Real_type_name ::= "REAL" ; LrealTypeName. Real_type_name ::= "LREAL" ;
-- real_literal ::= [ real_type_name ’#’ ] signed_integer ’.’ integer [exponent] NoOptionalExponent. Optional_exponent ::= ; OptionalExponent. Optional_exponent ::= Exponent ; rules Real_literal ::= Real_type_name "#" FloatToken | FloatToken ;
-- numeric_literal ::= integer_literal | real_literal rules Numeric_literal ::= StateInteger_literal | Real_literal ;
-- numeric_type_name ::= integer_type_name | real_type_name rules Numeric_type_name ::= StateInteger_type_name | Real_type_name ;
-- date_type_name ::= ’DATE’ | ’TIME_OF_DAY’ | ’TOD’ | ’DATE_AND_TIME’ | ’DT’ rules Date_type_name ::= "DATE" | "TIME_OF_DAY" | "TOD" | "DATE_AND_TIME" | "DT" ;
-- bit_string_type_name ::= ’BOOL’ | ’BYTE’ | ’WORD’ | ’DWORD’ | ’LWORD’ rules Bit_string_type_name ::= "BOOL" | "BYTE" | "WORD" | "DWORD" | "LWORD" ;
-- elementary_type_name ::= numeric_type_name | date_type_name | bit_string_type_name | ’STRING’ | ’WSTRING’ | ’TIME’ rules Elementary_type_name ::= Numeric_type_name | Date_type_name | Bit_string_type_name | "STRING" | "WSTRING" | "TIME" ;
-- simple_type_name ::= identifier SimpleTypeName. Simple_type_name ::= Identifier ;
-- subrange_type_name ::= identifier SubrangeTypeName. Subrange_type_name ::= Identifier ;
-- enumerated_type_name ::= identifier EnumeratedTypeName. Enumerated_type_name ::= Identifier ;
-- single_element_type_name ::= simple_type_name | subrange_type_name | enumerated_type_name rules Single_element_type_name ::= Simple_type_name | Subrange_type_name | Enumerated_type_name ;
-- array_type_name ::= identifier ArrayTypeName. Array_type_name ::= Identifier ;
-- structure_type_name ::= identifier StructureTypeName. Structure_type_name ::= Identifier ;
-- string_type_name ::= identifier StringTypeName. StateString_type_name ::= Identifier ;
-- derived_type_name ::= single_element_type_name | array_type_name | structure_type_name | string_type_name rules Derived_type_name ::= Single_element_type_name | Array_type_name | Structure_type_name | StateString_type_name ;
-- non_generic_type_name ::= elementary_type_name | derived_type_name rules Non_generic_type_name ::= Elementary_type_name | Derived_type_name ;
-- generic_type_name ::= ’ANY’ | ’ANY_DERIVED’ | ’ANY_ELEMENTARY’ | ’ANY_MAGNITUDE’ | ’ANY_NUM’ | ’ANY_REAL’ | ’ANY_INT’ | ’ANY_BIT’ | ’ANY_STRING’ | ’ANY_DATE’ rules Generic_type_name ::= "ANY" | "ANY_DERIVED" | "ANY_ELEMENTARY" | "ANY_MAGNITUDE" | "ANY_NUM" | "ANY_REAL" | "ANY_INT" | "ANY_BIT" | "ANY_STRING" | "ANY_DATE" ;
-- data_type_name ::= non_generic_type_name | generic_type_name rules Data_type_name ::= Non_generic_type_name | Generic_type_name ;
-- standard_function_name ::= <as defined in clause 2.5.1.5 of the standard> -- TODO: expand correct implementation --rules Standard_function_name ::= Type_conversion_function_name | Numerical_function_name | Bit_string_function_name | SelectionOrComparisson_function_name | Char_string_function_name | Time_function_name | Enumerated_type_function_name ; StandardFunctionName. Standard_function_name ::= Identifier ;
-- derived_function_name ::= identifier DerivedFunctionName. Derived_function_name ::= Identifier ;
-- function_name ::= standard_function_name | derived_function_name rules Function_name ::= Standard_function_name | Derived_function_name ;
-- standard_function_block_name ::= <as defined in clause 2.5.2.3 of the standard> -- TODO: expand correct implementation StandardFunctionBlockName. Standard_function_block_name ::= Identifier ;
-- derived_function_block_name ::= identifier DerivedFunctionBlockName. Derived_function_block_name ::= Identifier ;
-- function_block_type_name ::= standard_function_block_name | derived_function_block_name rules Function_block_type_name ::= Standard_function_block_name | Derived_function_block_name ;
-- program_type_name :: = identifier ProgramTypeName. Program_type_name ::= Identifier ;
-- resource_type_name ::= identifier ResourceTypeName. Resource_type_name ::= Identifier ;
-- configuration_name ::= identifier ConfigurationName. Configuration_name ::= Identifier ;
-- ENTRYPOINT -- library_element_name ::= data_type_name | function_name | function_block_type_name | program_type_name | resource_type_name | configuration_name rules Library_element_name ::= Data_type_name | Function_name | Function_block_type_name | Program_type_name | Resource_type_name | Configuration_name ;
-- simple_specification ::= elementary_type_name | simple_type_name rules Simple_specification ::= Elementary_type_name | Simple_type_name ;
-- character_string ::= single_byte_character_string | double_byte_character_string rules Character_string ::= Single_byte_character_string | AbsDouble_byte_character_string ;
-- fixed_point ::= integer [ '.' integer] NoFraction. OptionalFraction ::= ; FixedPointFraction. OptionalFraction ::= "." Integer ; FixedPoint. Fixed_point ::= Integer OptionalFraction ;
-- milliseconds ::= fixed_point (’ms’) Milis. Milliseconds ::= Fixed_point "ms" ;
-- seconds ::= fixedpoint (’s’) | integer (’s’) [’’]milliseconds NoUnderscore. OptionalUnderscore ::= ; Underscore. OptionalUnderscore ::= "_" ; rules Seconds ::= Fixed_point "s" | Integer "s" OptionalUnderscore Milliseconds ;
-- minutes ::= fixedpoint (’m’) | integer (’m’) [’’] seconds rules Minutes ::= Fixed_point "m" | Integer "m" OptionalUnderscore Seconds ;
-- hours ::= fixedpoint (’h’) | integer (’h’)[’’] minutes rules Hours ::= Fixed_point "h" | Integer "h" OptionalUnderscore Minutes ;
-- days ::= fixedpoint ('d') | integer ('d') [''] hours rules Days ::= Fixed_point "d" | Integer "d" OptionalUnderscore Hours ;
-- interval ::= days | hours | minutes | seconds | milliseconds rules Interval ::= Days | Hours | Minutes | Seconds | Milliseconds ;
token Time 'T' | 'T' 'I' 'M' 'E' ; NoHyphen. OptionalHyphen ::= ; Hyphen. OptionalHyphen ::= "-" ;
-- duration ::= (’T’ | ’TIME’) ’#’ [’-’] interval DurationType. Duration ::= Time "#" OptionalHyphen Interval ;
-- day_hour ::= integer DayHour. Day_hour ::= Integer ;
-- day_minute ::= integer DayMinute. Day_minute ::= Integer ;
-- day_second ::= fixed_point DaySecond. Day_second ::= Fixed_point ;
-- daytime ::= day_hour ’:’ day_minute ’:’ day_second DaytimeType. Daytime ::= Day_hour ":" Day_minute ":" Day_second ;
-- time_of_day ::= (’TIME_OFDAY’ | ’TOD’) ’#’ daytime token TimeOfDayToken ('T' 'I' 'M' 'E' '' 'O' 'F' '_' 'D' 'A' 'Y') | ('T' 'O' 'D') ; TimeOfDay. Time_of_day ::= TimeOfDayToken "#" Daytime ;
-- date ::= (’DATE’ | ’D’) ’#’ date_literal rules DateToken ::= "DATE" | "D" ; DateType. Date ::= DateToken "#" Date_literal ;
-- date_literal ::= year ’-’ month ’-’ day DateLiteral. Date_literal ::= Year "-" Month "-" Day ;
-- year ::= integer YearType. Year ::= Integer ;
-- month ::= integer MonthType. Month ::= Integer ;
-- day ::= integer DayType. Day ::= Integer ;
-- date_and_time ::= (’DATE_AND_TIME’ | ’DT’) ’#’ date_literal ’-’ daytime external_declaration ’;’ {external_declaration ’;’} ’END_VAR’ rules DateAndTimeToken ::= "DATE_AND_TIME" | "DT" ; rules ExternalDeclarationList ::= Daytime External_declaration ";" | Daytime External_declaration ";" ExternalDeclarationList ; DateAndTime. Date_and_time ::= DateAndTimeToken "#" Date_literal "-" Daytime ExternalDeclarationList "END_VAR" ;
-- external_declaration ::= global_var_name ’:’ (simple_specification | subrange_specification | enumerated_specification | array_specification | structure_type_name | function_block_type_name) rules GlobalVarSpecification ::= Simple_specification | Subrange_specification | Enumerated_specification | Array_specification | Structure_type_name | Function_block_type_name ; ExternalDeclaraion. External_declaration ::= Global_var_name ":" GlobalVarSpecification ;
-- time_literal ::= duration | time_of_day | date | date_and_time rules Time_literal ::= Duration | Time_of_day | Date | Date_and_time;
UnsignedIntegerValue. Unsigned_integer ::= Integer;
-- bit_string_literal ::= [ (’BYTE’ | ’WORD’ | ’DWORD’ | ’LWORD’) ’#’ ](unsigned_integer | binary_integer | octal_integer | hex_integer) NoOptionalBitStringType. Optional_bit_string_type ::= ; OptionalBitStringTypeByte. Optional_bit_string_type ::= "BYTE" "#" ; OptionalBitStringTypeWord. Optional_bit_string_type ::= "WORD" "#" ; OptionalBitStringTypeDWord. Optional_bit_string_type ::= "DWORD" "#" ; OptionalBitStringTypeLWord. Optional_bit_string_type ::= "LWORD" "#" ; rules Bit_string_literal ::= Optional_bit_string_type Unsigned_integer | Optional_bit_string_type BinaryInteger | Optional_bit_string_type OctalInteger | Optional_bit_string_type HexInteger ;
-- boolean_literal ::= ( [ ’BOOL#’ ](’1’ | ’0’) )| ’TRUE’ | ’FALSE’ rules Boolean_literal ::= "BOOL#1" | "BOOL#0" | "TRUE" | "FALSE" ;
-- constant ::= numeric_literal | character_string | time_literal | bit_string_literal | boolean_literal rules Constant ::= Numeric_literal | Character_string | Time_literal | Bit_string_literal | Boolean_literal ;
-- simple_spec_init ::= simple_specification [’:=’ constant] EqualsConstant. OptionalEqualsConstant ::= ":=" Constant ; NoEqualsConstant. OptionalEqualsConstant ::= ; SimpleSpecification. Simple_spec_init ::= Simple_specification OptionalEqualsConstant ;
-- simple_type_declaration ::= simple_type_name ’:’ simple_spec_init SimpleTypeDeclaration. Simple_type_declaration ::= Simple_type_name ":" Simple_spec_init ;
-- subrange ::= signed_integer ’..’ signed_integer SubrangeValue. Subrange ::= AbsSignedInteger ".." AbsSignedInteger ;
-- subrange_specification ::= integer_type_name ’(’ subrange’)’ | subrange_type_name rules Subrange_specification ::= StateInteger_type_name "(" Subrange ")" | Subrange_type_name ;
-- subrange_spec_init ::= subrange_specification[’:=’ signed_integer] NoOptionalEqualsSignedInteger. OptionalEqualsSignedInteger ::= ; OptionalEqualsSignedIntegerValue. OptionalEqualsSignedInteger ::= ":=" AbsSignedInteger ; SubrangeSpecInit. Subrange_spec_init ::= Subrange_specification OptionalEqualsSignedInteger ;
-- subrange_type_declaration ::= subrange_type_name ’:’ subrange_spec_init SubrangeTypeDeclaration. Subrange_type_declaration ::= Subrange_type_name ":" Subrange_spec_init ;
-- enumerated_value ::= [enumerated_type_name ’#’] identifier NoOptionalEnumeratedTypeNameHash. OptionalEnumeratedTypeNameHash ::= ; OptionalEnumeratedTypeNameHashValue. OptionalEnumeratedTypeNameHash ::= Enumerated_type_name "#" ; EnumeratedValue. Enumerated_value ::= OptionalEnumeratedTypeNameHash Identifier ;
-- enumerated_specification ::= (’(’ enumerated_value {’,’ enumerated_value} ’)’) | enumerated_type_name
EnumeratedValueListEnd. Enumerated_value_list ::= Enumerated_value ; EnumeratedValueListElement. Enumerated_value_list ::= Enumerated_value "," Enumerated_value_list ; rules Enumerated_specification ::= "(" Enumerated_value_list ")" | Enumerated_type_name ;
-- enumerated_spec_init ::= enumerated_specification [’:=’ enumerated_value] NoOptionalEqualsEnumeratedValue. OptionalEqualsEnumeratedValue ::= ; OptionalEqualsEnumeratedValueValue. OptionalEqualsEnumeratedValue ::= ":=" Enumerated_value ; EnumeratedSpecInit. Enumerated_spec_init ::= Enumerated_specification OptionalEqualsEnumeratedValue ;
-- enumerated_type_declaration ::= enumerated_type_name ’:’ enumerated_spec_init EnumeratedTypeDeclaration. Enumerated_type_declaration ::= Enumerated_type_name ":" Enumerated_spec_init ;
-- single_element_type_declaration ::= simple_type_declaration | subrange_type_declaration | enumerated_type_declaration rules Single_element_type_declaration ::= Simple_type_declaration | Subrange_type_declaration | Enumerated_type_declaration ;
-- array_specification ::= array_type_name | ’ARRAY’ ’[’ subrange {’,’ subrange} ’]’ ’OF’ non_generic_type_name SubRangeListEnd. SubRangeList ::= Subrange ; SubRangeListElement. SubRangeList ::= Subrange "," SubRangeList ; rules Array_specification ::= Array_type_name | "ARRAY" "[" SubRangeList "]" "OF" Non_generic_type_name ;
-- structure_element_name ::= identifier StructureElementName. Structure_element_name ::= Identifier ;
-- structure_element_initialization ::= structure_element_name ’:=’ (constant | enumerated_value | array_initialization | structure_initialization) rules StructureElementInitializationValue ::= Constant | Enumerated_value | Array_initialization | Structure_initialization ; StructureElementInitialization. Structure_element_initialization ::= Structure_element_name ":=" StructureElementInitializationValue ;
-- structure_initialization ::= ’(’ structure_element_initialization {’,’ structure_element_initialization} ’)’ StructureElementInitializationListEnd. StructureElementInitializationList ::= Structure_element_initialization ; StructureElementInitializationListElement. StructureElementInitializationList ::= Structure_element_initialization "," StructureElementInitializationList ; StructureInitialization. Structure_initialization ::= "(" StructureElementInitializationList ")" ;
-- array_initial_element ::= constant | enumerated_value | structure_initialization | array_initialization rules Array_initial_element ::= Constant | Enumerated_value | Structure_initialization | Array_initialization ;
-- array_initial_elements ::= array_initial_element | integer ’(’[array_initial_element] ’)’ NoOptionalArrayInitialElement. OptionalArrayInitialElement ::= ; OptionalArrayInitialElementValue. OptionalArrayInitialElement ::= Array_initial_element ; rules Array_initial_elements ::= Array_initial_element | Integer "(" OptionalArrayInitialElement ")" ;
-- array_initialization::= ’[’ array_initial_elements {’,’ array_initial_elements} ’]’ ArrayInitialElementsListEnd. ArrayInitialElementsList ::= Array_initial_elements ; ArrayInitialElementsListElement. ArrayInitialElementsList ::= Array_initial_elements "," ArrayInitialElementsList ; ArrayInitialization. Array_initialization ::= "[" ArrayInitialElementsList "]" ;
-- array_spec_init ::= array_specification [’:=’ array_initialization] NoEqualsArrayInitialization. OptionalEqualsArrayOptimization ::= ; EqualsArrayInitialization. OptionalEqualsArrayOptimization ::= ":=" Array_initialization ; ArraySpecInit. Array_spec_init ::= Array_specification OptionalEqualsArrayOptimization ;
-- array_type_declaration ::= array_type_name ’:’ array_spec_init ArrayTypeDeclaration. Array_type_declaration ::= Array_type_name ":" Array_spec_init ;
-- initialized_structure ::=structure_type_name [’:=’ structure_initialization] NoOptionalEqualsStructureInitialization. OptionalEqualsStructureInitialization ::= ; OptionalEqualsStructureInitializationValue. OptionalEqualsStructureInitialization ::= ":=" Structure_initialization ; InitializedStructure. Initialized_structure ::= Structure_type_name OptionalEqualsStructureInitialization ;
-- structure_element_declaration ::= structure_element_name ’:’(simple_spec_init | subrange_spec_init | enumerated_spec_init | array_spec_init | initialized_structure) rules Structure_element_declaration ::= Structure_element_name ":" Simple_spec_init | Structure_element_name ":" Subrange_spec_init | Structure_element_name ":" Enumerated_spec_init Structure_element_name ":" Array_spec_init | Structure_element_name ":" Initialized_structure ;
-- structure_declaration ::=’STRUCT’ structure_element_declaration ’;’{structure_element_declaration ’;’}’END_STRUCT’ StructureElementListEnd. StructureElementList ::= Structure_element_declaration ";" ; StructureElementListElement. StructureElementList ::= Structure_element_declaration ";" StructureElementList ; StructureDeclaration. Structure_declaration ::= "STRUCT" StructureElementList "END_STRUCT" ;
-- structure_specification ::= structure_declaration | initialized_structure rules Structure_specification ::= Structure_declaration | Initialized_structure ;
-- structure_type_declaration ::= structure_type_name ’:’ structure_specification StructureTypeDeclaration. Structure_type_declaration ::= Structure_type_name ":" Structure_specification ;
-- string_type_declaration ::= string_type_name ’:’ (’STRING’|’WSTRING’) [’[’ integer ’]’] [’:=’ character_string] rules Elementary_string_type_name ::= "STRING"|"WSTRING" ; NoOptionalBracketsInteger. OptionalBracketsInteger ::= ; OptionalBracketsIntegerValue. OptionalBracketsInteger ::= "[" Integer "]" ; NoOptionalEqualsCharacterString. OptionalEqualsCharacterString ::= ; OptionalEqualsCharacterStringValue. OptionalEqualsCharacterString ::= ":=" Character_string ; StringTypeDeclaration. StateString_type_declaration ::= StateString_type_name ":" Elementary_string_type_name OptionalBracketsInteger OptionalEqualsCharacterString ;
-- type_declaration ::= single_element_type_declaration | array_type_declaration | structure_type_declaration | string_type_declaration rules Type_declaration ::= Single_element_type_declaration | Array_type_declaration | Structure_type_declaration | StateString_type_declaration ;
-- data_type_declaration ::= ’TYPE’ type_declaration ’;’ {type_declaration ’;’} ’END_TYPE’ TypeDeclarationListEnd. TypeDeclarationList ::= Type_declaration ";" ; TypeDeclarationListElement. TypeDeclarationList ::= Type_declaration ";" TypeDeclarationList ; DataTypeDeclaration. Data_type_declaration ::= "TYPE" TypeDeclarationList "END_TYPE" ;
-- variable_name ::= identifier VariableName. Variable_name ::= Identifier ;
-- var1_list ::= variable_name {’,’ variable_name} VariableNameListEnd. Var1_list ::= Variable_name ; VariableNameListElement. Var1_list ::= Variable_name "," Var1_list ;
-- edge_declaration ::= var1_list ’:’ ’BOOL’ (’R_EDGE’ | ’F_EDGE’) rules EdgeType ::= "R_EDGE" | "F_EDGE" ; EdgeDeclaration. Edge_declaration ::= Var1_list ":" "BOOL" EdgeType ;
-- fb_name ::= identifier FbName. Fb_name ::= Identifier ;
-- fb_name_list ::= fb_name {’,’ fb_name} FbNameListEnd. Fb_name_list ::= Fb_name ; FbNameListElement. Fb_name_list ::= Fb_name "," Fb_name_list ;
-- fb_name_decl ::= fb_name_list ’:’ function_block_type_name [ ’:=’ structure_initialization ] Fb_Name_Decl. Fb_name_decl ::= Fb_name_list ":" Function_block_type_name OptionalEqualsStructureInitialization ;
-- single_byte_string_spec ::= ’STRING’ [’[’ integer ’]’] [’:=’ single_byte_character_string] NoOptionalEqualsSingleByteCharacterString. OptionalEqualsSingleByteCharacterString ::= ; OptionalEqualsSingleByteCharacterStringValue. OptionalEqualsSingleByteCharacterString ::= ":=" Single_byte_character_string ; SingleByteStringSpec. Single_byte_string_spec ::= "STRING" OptionalBracketsInteger OptionalEqualsSingleByteCharacterString ;
-- single_byte_string_var_declaration ::= var1_list ’:’ single_byte_string_spec SingleByteStringVarDeclaration. Single_byte_string_var_declaration ::= Var1_list ":" Single_byte_string_spec ;
-- double_byte_string_spec ::= ’WSTRING’ [’[’ integer ’]’] [’:=’ double_byte_character_string] NoOptionalEqualsDoubleByteCharacterString. OptionalEqualsDoubleByteCharacterString ::= ; OptionalEqualsDoubleByteCharacterStringValue. OptionalEqualsDoubleByteCharacterString ::= ":=" AbsDouble_byte_character_string ; DoubleByteStringSpec. AbsDouble_byte_string_spec ::= "WSTRING" OptionalBracketsInteger OptionalEqualsDoubleByteCharacterString ;
-- double_byte_string_var_declaration ::= var1_list ’:’ double_byte_string_spec DoubleByteStringVarDeclaration. AbsDouble_byte_string_var_declaration ::= Var1_list ":" AbsDouble_byte_string_spec ;
-- string_var_declaration ::= single_byte_string_var_declaration | double_byte_string_var_declaration rules StateString_var_declaration ::= Single_byte_string_var_declaration | AbsDouble_byte_string_var_declaration ;
-- var_init_decl ::= var1_init_decl | array_var_init_decl | structured_var_init_decl | fb_name_decl | string_var_declaration rules Var_init_decl ::= Var1_init_decl | Array_var_init_decl | Structured_var_init_decl | Fb_name_decl | StateString_var_declaration ;
-- input_declaration ::= var_init_decl | edge_declaration rules Input_declaration ::= Var_init_decl | Edge_declaration ;
-- input_declarations ::= ’VAR_INPUT’ [’RETAIN’ | ’NON_RETAIN’] input_declaration ’;’ {input_declaration ’;’} ’END_VAR’ InputDeclarationListEnd. InputDeclarationList ::= Input_declaration ";" ; InputDeclarationListElement. InputDeclarationList ::= Input_declaration ";" InputDeclarationList ; rules InputDeclInit ::= "VAR_INPUT" | "VAR_INPUT" "RETAIN" | "VAR_INPUT" "NON_RETAIN" ; InputDeclarations. Input_declarations ::= InputDeclInit InputDeclarationList "END_VAR" ;
-- var1_init_decl ::= var1_list ’:’ (simple_spec_init | subrange_spec_init | enumerated_spec_init) rules SpecInit ::= Simple_spec_init | Subrange_spec_init | Enumerated_spec_init ; Var1InitDecl. Var1_init_decl ::= Var1_list ":" SpecInit ;
-- array_var_init_decl ::= var1_list ’:’ array_spec_init ArrayVarInitDecl. Array_var_init_decl ::= Var1_list ":" Array_spec_init ;
-- structured_var_init_decl ::= var1_list ’:’ initialized_structure StructuredVarInitDecl. Structured_var_init_decl ::= Var1_list ":" Initialized_structure ;
-- var1_declaration ::= var1_list ’:’ (simple_specification | subrange_specification | enumerated_specification) rules Var1Specification ::= Simple_specification | Subrange_specification | Enumerated_specification ; Var1Declaration. Var1_declaration ::= Var1_list ":" Var1Specification ;
-- array_var_declaration ::= var1_list ’:’ array_specification ArrayVarDeclaration. Array_var_declaration ::= Var1_list ":" Array_specification ;
-- structured_var_declaration ::= var1_list ’:’ structure_type_name StructuredVarDeclaration. Structured_var_declaration ::= Var1_list ":" Structure_type_name ;
-- temp_var_decl ::= var1_declaration | array_var_declaration | structured_var_declaration | string_var_declaration rules Temp_var_decl ::= Var1_declaration | Array_var_declaration | Structured_var_declaration | StateString_var_declaration ;
-- var_declaration ::= temp_var_decl | fb_name_decl rules Var_declaration ::= Temp_var_decl | Fb_name_decl ;
-- input_output_declarations ::= ’VAR_IN_OUT’ var_declaration ’;’ {var_declaration ’;’} ’END_VAR’ rules VarDeclarationList ::= Var_declaration ";" VarDeclarationList | Var_declaration ";" ; InputOutputDeclarations. Input_output_declarations ::= "VAR_IN_OUT" VarDeclarationList "END_VAR" ;
-- io_var_declarations ::= input_declarations | output_declarations | input_output_declarations rules Io_var_declarations ::= Input_declarations | Output_declarations | Input_output_declarations ;
-- var2_init_decl ::= var1_init_decl | array_var_init_decl | structured_var_init_decl | string_var_declaration rules Var2_init_decl ::= Var1_init_decl | Array_var_init_decl | Structured_var_init_decl | StateString_var_declaration ;
-- function_var_decls ::= ’VAR’ [’CONSTANT’] var2_init_decl ’;’ {var2_init_decl ’;’} ’END_VAR’ rules Var2InitDeclList ::= Var2_init_decl ";" | Var2_init_decl ";" Var2InitDeclList ; FunctionVarDecls. Function_var_decls ::= "VAR" OptionalConstantToken Var2InitDeclList "END_VAR" ;
-- location_prefix ::= ’I’ | ’Q’ | ’M’ rules Location_prefix ::= "I" | "Q" | "M" ;
-- size_prefix ::= NIL | ’X’ | ’B’ | ’W’ | ’D’ | ’L’ rules Size_prefix ::= "X" | "B" | "W" | "D" | "L" | ;
-- direct_variable ::= ’%’ location_prefix size_prefix integer {’.’ integer} rules IntegerList ::= Integer "." IntegerList | Integer ; DirectVariable. Direct_variable ::= "%" Location_prefix Size_prefix IntegerList ;
-- symbolic_variable ::= variable_name | multi_element_variable rules Symbolic_variable ::= Variable_name | Multi_element_variable ;
-- multi_element_variable ::= array_variable | structured_variable rules Multi_element_variable ::= Array_variable | Structured_variable ;
-- array_variable ::= subscripted_variable subscript_list ArrayVariable. Array_variable ::= Subscripted_variable Subscript_list ;
-- subscripted_variable ::= symbolic_variable SubscriptedVariable. Subscripted_variable ::= Symbolic_variable ;
-- subscript_list ::= ’[’ subscript {’,’ subscript} ’]’ rules SubscriptListS ::= Subscript "," SubscriptListS | Subscript ; SubscriptList. Subscript_list ::= "[" SubscriptListS "]" ;
-- record_variable ::= symbolic_variable RecordVariable. Record_variable ::= Symbolic_variable ;
-- field_selector ::= identifier FieldSelector. Field_selector ::= Identifier ;
-- structured_variable ::= record_variable ’.’ field_selector StructuredVariable. Structured_variable ::= Record_variable "." Field_selector ;
-- subscript ::= expression SubscriptType. Subscript ::= Expression ;
-- variable ::= direct_variable | symbolic_variable rules Variable ::= Direct_variable | Symbolic_variable ;
-- expression ::= xor_expression {’OR’ xor_expression} ExpressionType. Expression ::= XorOrList ; rules XorOrList ::= Xor_expression | Xor_expression "OR" XorOrList ;
-- xor_expression ::= and_expression {’XOR’ and_expression} XorExpression. Xor_expression ::= AndXorList ; rules AndXorList ::= And_expression | And_expression "XOR" AndXorList ;
-- and_expression ::= comparison {(’&’ | ’AND’) comparison} rules And ::= "&" | "AND" ; rules ComparisonAndList ::= Comparison | Comparison And ComparisonAndList ; AndExpression. And_expression ::= ComparisonAndList ;
-- comparison ::= equ_expression { (’=’ | ’<>’) equ_expression} rules EquComparator ::= "=" | "<>" ; rules EquExpressionComparissonList ::= Equ_expression | Equ_expression EquComparator EquExpressionComparissonList ; ComparisonType. Comparison ::= EquExpressionComparissonList ;
-- equ_expression ::= add_expression {comparison_operator add_expression} rules AddExpressionComparisonOperatorList ::= Add_expression | Add_expression Comparison_operator AddExpressionComparisonOperatorList ; EquExpression. Equ_expression ::= AddExpressionComparisonOperatorList ;
-- add_expression ::= term {add_operator term} rules Add_expression ::= Term | Term Add_operator Add_expression ;
-- term ::= power_expression {multiply_operator power_expression} rules Term ::= Power_expression | Power_expression Multiply_operator Term ;
-- power_expression ::= unary_expression {’’ unary_expression} rules Power_expression ::= Unary_expression | Unary_expression "" Power_expression ;
-- unary_expression ::= [unary_operator] primary_expression rules Unary_expression ::= Primary_expression | Unary_operator Primary_expression ;
-- primary_expression ::= constant | enumerated_value | variable | ’(’ expression ’)’ | function_name ’(’ param_assignment {’,’ param_assignment} ’)’ rules ParamAssignmentList ::= Param_assignment | Param_assignment "," ParamAssignmentList ; rules Primary_expression ::= Constant | Enumerated_value | Variable | "(" Expression ")" | Function_name "(" ParamAssignmentList ")" ;
-- comparison_operator ::= ’<’ | ’>’ | ’<=’ | ’>=’ ’ rules Comparison_operator ::= "<" | ">" | "<=" | ">=" ;
-- add_operator ::= ’+’ | ’-’ rules Add_operator ::= "+" | "-" ;
-- multiplyoperator ::= ’’ | ’/’ | ’MOD’ rules Multiplyoperator ::= "" | "/" | "MOD" ;
-- unary_operator ::= ’-’ | ’NOT’ rules Unary_operator ::= "-" | "NOT" ;
-- param_assignment ::= ([variable_name ’:=’] expression) | ([’NOT’] variable_name ’=>’ variable) rules OptionalVariableNameEquals ::= Variable_name ":=" | ; rules OptionalNot ::= "NOT" | ; rules Param_assignment ::= OptionalVariableNameEquals Expression | OptionalNot Variable_name "=>" Variable ;
-- assignment_statement ::= variable ’:=’ expression AssignmentStatement. Assignment_statement ::= Variable ":=" Expression ;
-- fb_invocation ::= fb_name ’(’ [param_assignment {’,’ param_assignment}]’)’ FbInvocation. Fb_invocation ::= Fb_name "(" ParamAssignmentList ")" ;
-- subprogram_control_statement ::= fb_invocation | ’RETURN’ rules Subprogram_control_statement ::= Fb_invocation | "RETURN" ;
-- if_statement ::= ’IF’ expression ’THEN’ statement_list {’ELSIF’ expression ’THEN’ statement_list} [’ELSE’ statement_list] ’END_IF’ rules ElsifRepetition ::= "ELSIF" Expression "THEN" Statement_list ElsifRepetition | ; rules OptionalElseStatement ::= "ELSE" Statement_list | ; IfStatement. If_statement ::= "IF" Expression "THEN" Statement_list ElsifRepetition OptionalElseStatement "END_IF" ;
-- case_statement ::= ’CASE’ expression ’OF’ case_element {case_element} [’ELSE’ statement_list] ’END_CASE’ rules CaseElementRepetition ::= Case_element | Case_element CaseElementRepetition ; CaseStatement. Case_statement ::= "CASE" Expression "OF" CaseElementRepetition OptionalElseStatement "END_CASE" ;
-- case_element ::= case_list ’:’ statement_list CaseElement. Case_element ::= Case_list ":" Statement_list ;
-- case_list ::= case_list_element {’,’ case_list_element} rules Case_list ::= Case_list_element "," Case_list | Case_list_element ;
-- case_list_element ::= subrange | signed_integer | enumerated_value rules Case_list_element ::= Subrange | AbsSignedInteger | Enumerated_value ;
-- selection_statement ::= if_statement | case_statement rules Selection_statement ::= If_statement | Case_statement ;
-- control_variable ::= identifier ControlVariable. Control_variable ::= Identifier ;
-- for_statement ::= ’FOR’ control_variable ’:=’ for_list ’DO’ statement_list ’END_FOR’ ForStatement. For_statement ::= "FOR" Control_variable ":=" For_list "DO" Statement_list "END_FOR" ;
-- for_list ::= expression ’TO’ expression [’BY’ expression] rules OptionalByExpression ::= "BY" Expression ; ForList. For_list ::= Expression "TO" Expression OptionalByExpression ;
-- while_statement ::= ’WHILE’ expression ’DO’ statement_list ’END_WHILE’ WhileStatement. While_statement ::= "WHILE" Expression "DO" Statement_list "END_WHILE" ;
-- repeat_statement ::= ’REPEAT’ statement_list ’UNTIL’ expression ’END_REPEAT’ RepeatStatement. Repeat_statement ::= "REPEAT" Statement_list "UNTIL" Expression "END_REPEAT" ;
-- exit_statement ::= ’EXIT’ ExitStatement. Exit_statement ::= "EXIT" ;
-- iteration_statement ::= for_statement | while_statement | repeat_statement | exit_statement rules Iteration_statement ::= For_statement | While_statement | Repeat_statement | Exit_statement ;
-- function_declaration ::= ’FUNCTION’ derived_function_name ’:’ (elementary_type_name | derived_type_name) { io_var_declarations | function_var_decls } function_body ’END_FUNCTION’ rules TypeName ::= Elementary_type_name | Derived_type_name ; rules IoVarOrFunctionVarDeclaration ::= Io_var_declarations | Function_var_decls ; rules IoVarOrFunctionVarDeclarations ::= IoVarOrFunctionVarDeclaration IoVarOrFunctionVarDeclarations | ; FunctionDeclaration. Function_declaration ::= "FUNCTION" Derived_function_name ":" TypeName IoVarOrFunctionVarDeclarations Function_body "END_FUNCTION" ;
-- function_body ::= ladder_diagram | function_block_diagram | instruction_list | statement_list |
-- Todo: check this rule, it seems plain wrong, it should define a list of variables rather than just one -- external_var_declarations ::= ’VAR_EXTERNAL’ [’CONSTANT’] ExternalVarDeclarations. External_var_declarations ::= "VAR_EXTERNAL" OptionalConstantToken ;
-- retentive_var_declarations ::= ’VAR’ ’RETAIN’ var_init_decl ’;’ {var_init_decl ’;’} ’END_VAR’ RetentiveVarDeclarations. Retentive_var_declarations ::= "VAR" "RETAIN" VarInitDeclList "END_VAR" ;
-- non_retentive_var_decls ::= ’VAR’ ’NON_RETAIN’ var_init_decl ’;’ {var_init_decl ’;’} ’END_VAR’ NonRetentiveVarDeclarations. Non_retentive_var_declarations ::= "VAR" "NON_RETAIN" VarInitDeclList "END_VAR" ;
-- temp_var_decls ::= ’VAR_TEMP’ temp_var_decl ’;’ {temp_var_decl ’;’} ’END_VAR’ rules TempVarDeclList ::= Temp_var_decl ";" | Temp_var_decl ";" TempVarDeclList ; TempVarDecls. Temp_var_decls ::= "VAR_TEMP" TempVarDeclList "END_VAR" ;
-- incompllocation ::= ’AT’ ’%’ (’I’ | ’Q’ | ’M’) ’’ rules IQM ::= "I" | "Q" | "M" ; IncomplLocation. Incompllocation ::= "AT" "%" IQM "" ;
-- var_spec ::= simple_specification | subrange_specification | enumerated_specification | array_specification | structure_type_name | ’STRING’ [’[’ integer ’]’] | ’WSTRING’ [’[’integer ’]’] rules Var_spec ::= Simple_specification | Subrange_specification | Enumerated_specification | Array_specification | Structure_type_name | "STRING" "[" Integer "]" | "WSTRING" "[" Integer "]" | "STRING" | "WSTRING" ;
-- incompl_located_var_decl ::= variable_name incompl_location ’:’ var_spec IncomplLocatedVarDecl. Incompl_located_var_decl ::= Variable_name Incompl_location ":" Var_spec ;
-- function_block_declaration ::= ’FUNCTION_BLOCK’ derived_function_block_name { io_var_declarations | other_var_declarations } function_block_body ’END_FUNCTION_BLOCK’ rules IoVarOrOtherVarDeclaration ::= Io_var_declarations | Other_var_declarations ; rules IoVarOrOtherVarDeclarations ::= IoVarOrOtherVarDeclaration IoVarOrOtherVarDeclarations | ; FunctionBlockDeclaration. Function_block_declaration ::= "FUNCTION_BLOCK" Derived_function_block_name IoVarOrOtherVarDeclarations Function_block_body "END_FUNCTION_BLOCK" ;
-- location ::= ’AT’ direct_variable LocationType. Location ::= "AT" Direct_variable ;
-- located_var_spec_init ::= simple_spec_init | subrange_spec_init | enumerated_spec_init | array_spec_init | initialized_structure | single_byte_string_spec | double_byte_string_spec rules Located_var_spec_init ::= Simple_spec_init | Subrange_spec_init | Enumerated_spec_init | Array_spec_init | Initialized_structure | Single_byte_string_spec | AbsDouble_byte_string_spec ;
-- program_access_decls ::= ’VAR_ACCESS’ program_access_decl ’;’ {program_access_decl ’;’ } ’END_VAR’ rules ProgramAccessDeclList ::= Program_access_decl ";" | Program_access_decl ";" ProgramAccessDeclList ; ProgramAccessDecls. Program_access_decls ::= "VAR_ACCESS" ProgramAccessDeclList "END_VAR" ;
-- program_access_decl ::= access_name ’:’ symbolic_variable ’:’ non_generic_type_name [direction] rules OptionalDiraction ::= Direction | ; ProgramAccessDecl. Program_access_decl ::= Access_name ":" Symbolic_variable ":" Non_generic_type_name OptionalDiraction ;
-- direction ::= ’READ_WRITE’ | ’READ_ONLY’ rules Direction ::= "READ_WRITE" | "READ_ONLY" ;
-- access_name ::= identifier AccessName. Access_name ::= Identifier ;
-- located_var_declarations ::= ’VAR’ [’CONSTANT’ | ’RETAIN’ | ’NON_RETAIN’] located_var_decl ’;’ {located_var_decl ’;’} ’END_VAR’ rules OptionalConstantOrRetainOrNonretain ::= "CONSTANT" | "RETAIN" | "NON_RETAIN" | ; rules LocatedVarList ::= Located_var_decl ";" | Located_var_decl ";" LocatedVarList ; LocatedVarDeclarations. Located_var_declarations ::= "VAR" OptionalConstantOrRetainOrNonretain LocatedVarList "END_VAR" ;
-- located_var_decl ::= [variable_name] location ’:’ located_var_spec_init rules OptionalVariableName ::= Variable_name | ; LocatedVarDecl. Located_var_decl ::= OptionalVariableName Location ":" Located_var_spec_init ;
-- global_var_name ::= identifier GlobalVarName. Global_var_name ::= Identifier ;
-- global_var_list ::= global_var_name {’,’ global_var_name} rules Global_var_list ::= Global_var_name | Global_var_name "," Global_var_list ;
-- global_var_spec ::= global_var_list | [global_var_name] location rules OptionalGlobalVarName ::= Global_var_name | ; rules Global_var_spec ::= Global_var_list | OptionalGlobalVarName Location ;
-- global_var_decl ::= global_var_spec ’:’ [ located_var_spec_init | function_block_type_name ] rules OptionalLocatedVarSpecInitOrFunctionBlockTypeName ::= Located_var_spec_init | Function_block_type_name ; GlobalVarDecl. Global_var_decl ::= Global_var_spec ":" OptionalLocatedVarSpecInitOrFunctionBlockTypeName ;
-- global_var_declarations ::= ’VAR_GLOBAL’ [’CONSTANT’ | ’RETAIN’] global_var_decl ’;’ {global_var_decl ’;’} ’END_VAR’ rules GlobalVarDeclList ::= Global_var_decl ";" | Global_var_decl ";" GlobalVarDeclList ; rules OptionalConstantOrRetain ::= "CONSTANT" | "RETAIN" | ; GlobalVarDeclarations. Global_var_declarations ::= "VAR_GLOBAL" OptionalConstantOrRetain GlobalVarDeclList "END_VAR" ;
-- task_name := identifier TaskName. Task_name ::= Identifier ;
-- resource_name ::= identifier ResourceName. Resource_name ::= Identifier ;
-- global_var_reference ::= [resource_name ’.’] global_var_name [’.’ structure_element_name] rules OptionalResourceNameDot ::= Resource_name "." | ; rules OptionalDotStructureElementName ::= "." Structure_element_name | ; GlobalVarReference. Global_var_reference ::= OptionalResourceNameDot Global_var_name OptionalDotStructureElementName ;
-- program_name ::= identifier ProgramName. Program_name ::= Identifier ;
-- program_output_reference ::= program_name ’.’ symbolic_variable ProgramOutputReference. Program_output_reference ::= Program_name "." Symbolic_variable ;
-- data_source ::= constant | global_var_reference | program_output_reference | direct_variable rules Data_source ::= Constant | Global_var_reference | Program_output_reference | Direct_variable ;
-- task_initialization ::= ’(’ [’SINGLE’ ’:=’ data_source ’,’] [’INTERVAL’ ’:=’ data_source ’,’] ’PRIORITY’ ’:=’ integer ’)’ rules OptionalSingleEqualsDataSource ::= "SINGLE" ":=" Data_source "," | ; rules OptionalIntervalEqualsDataSource ::= "INTERVAL" ":=" Data_source "," | ; TaskInitialization. Task_initialization ::= "(" OptionalSingleEqualsDataSource OptionalIntervalEqualsDataSource "PRIORITY" ":=" Integer ")" ;
-- task_configuration ::= ’TASK’ task_name task_initialization TaskConfiguration. Task_configuration ::= "TASK" Task_name Task_initialization ;
-- fb_task ::= fb_name ’WITH’ task_name FbTask. Fb_task ::= Fb_name "WITH" Task_name ;
-- prog_data_source ::= constant | enumerated_value | global_var_reference | direct_variable rules Prog_data_source ::= Constant | Enumerated_value | Global_var_reference | Direct_variable ;
-- data_sink ::= global_var_reference | direct_variable rules Data_sink ::= Global_var_reference | Direct_variable ;
-- prog_cnxn ::= symbolic_variable ’:=’ prog_data_source | symbolic_variable ’=>’ data_sink rules Prog_cnxn ::= Symbolic_variable ":=" Prog_data_source | Symbolic_variable "=>" Data_sink ;
-- prog_conf_element ::= fb_task | prog_cnxn rules Prog_conf_element ::= Fb_task | Prog_cnxn ;
-- prog_conf_elements ::= prog_conf_element {’,’ prog_conf_element} rules Prog_conf_elements ::= Prog_conf_element | Prog_conf_element "," Prog_conf_elements ;
-- program_configuration ::= ’PROGRAM’ [RETAIN | NON_RETAIN] program_name [’WITH’ task_name] ’:’ program_type_name [’(’ prog_conf_elements ’)’] rules OptionalWithTaskName ::= "WITH" Task_name | ; rules OptionalProgConfElementsDecl ::= "(" Prog_conf_elements ")" | ; rules ProgramConfigurationDeclInit ::= "PROGRAM" | "PROGRAM" "RETAIN" | "PROGRAM" "NON_RETAIN" ; ProgramConfiguration. Program_configuration ::= ProgramConfigurationDeclInit Program_name OptionalWithTaskName ":" Program_type_name OptionalProgConfElementsDecl ;
-- single_resource_declaration ::= {task_configuration ’;’} program_configuration ’;’ {program_configuration ’;’} rules TaskConfigurationList ::= Task_configuration ";" TaskConfigurationList | ; rules ProgramConfigurationList ::= Program_configuration ";" | Program_configuration ";" ProgramConfigurationList; SingleResourceDeclaration. Single_resource_declaration ::= TaskConfigurationList ProgramConfigurationList ;
-- resource_declaration ::= ’RESOURCE’ resource_name ’ON’ resource_type_name [global_var_declarations] single_resource_declaration ’END_RESOURCE’ rules OptionalGlobalVarDeclarations ::= Global_var_declarations | ; ResourceDeclaration. Resource_declaration ::= "RESOURCE" Resource_name "ON" Resource_type_name OptionalGlobalVarDeclarations Single_resource_declaration "END_RESOURCE" ;
-- access_path ::= [resource_name ’.’] direct_variable | [resource_name ’.’] [program_name ’.’] {fb_name’.’} symbolic_variable rules OptionalProgramNameDot ::= Program_name "." | ; rules FbNameDotList ::= Fb_name "." | ; rules Access_path ::= OptionalResourceNameDot Direct_variable | OptionalResourceNameDot OptionalProgramNameDot FbNameDotList Symbolic_variable ;
-- access_declaration ::= access_name ’:’ access_path ’:’ non_generic_type_name [direction] rules OptionalDirection ::= Direction | ; AccessDeclaration. Access_declaration ::= Access_name ":" Access_path ":" Non_generic_type_name Direction ;
-- access_declarations ::= ’VAR_ACCESS’ access_declaration ’;’ {access_declaration ’;’} ’END_VAR’ rules AccessDeclarationList ::= Access_declaration ";" | Access_declaration ";" AccessDeclarationList ; AccessDeclarations. Access_declarations ::= "VAR_ACCESS" AccessDeclarationList "END_VAR" ;
-- instance_specific_init ::= resource_name ’.’ program_name ’.’ {fb_name ’.’} ((variable_name [location] ’:’ located_var_spec_init) | (fb_name ’:’ function_block_type_name ’:=’ structure_initialization)) rules OptionalLocation ::= Location | ; rules VarOrFbInitialization ::= Variable_name OptionalLocation ":" Located_var_spec_init | Fb_name ":" Function_block_type_name ":=" Structure_initialization ; InstanceSpecificInit. Instance_specific_init ::= Resource_name "." Program_name "." FbNameDotList VarOrFbInitialization ;
-- instance_specific_initializations ::= ’VAR_CONFIG’ instance_specific_init ’;’ {instance_specific_init ’;’} ’END_VAR’ rules InstanceSpecificInitList ::= Instance_specific_init ";" | Instance_specific_init ";" InstanceSpecificInitList ; InstanceSpecificInitializations. Instance_specific_initializations ::= "VAR_CONFIG" InstanceSpecificInitList "END_VAR" ;
-- configuration_declaration ::= ’CONFIGURATION’ configuration_name [global_var_declarations](single_resource_declaration | %28resource_declaration {resource_declaration}%29) [access_declarations] [instance_specific_initializations] ’END_CONFIGURATION’ rules ResourceDeclarationList ::= Resource_declaration | Resource_declaration ResourceDeclarationList ; rules SingleResourceOrResourceListDeclaration ::= Single_resource_declaration | ResourceDeclarationList ; rules OptionalAccessDeclarations ::= Access_declarations | ; rules OptionalInstanceSpecificInitialization ::= Instance_specific_initializations | ; ConfigurationDeclaration. Configuration_declaration ::= "CONFIGURATION" Configuration_name OptionalGlobalVarDeclarations SingleResourceOrResourceListDeclaration OptionalAccessDeclarations OptionalInstanceSpecificInitialization "END_CONFIGURATION" ;
comment "(" ")" ;
The input program:
PROGRAM Main (* This is a test comment; *) ; END_PROGRAM
I'm not sure what exactly is the problem here. According to your screen shot, you to build the example program TestCommentTest.exe
successfully and it parses your example input.
When I tried it locally, I got the same result. I did get quite a few warning from bison, but no errors. Where does the content of your notepad comes from?
The notepad's content is bison's stderr's output when trying to parse the input program with YYDEBUG defined, it basically shows that it receives an $undefined token from flex when it reaches the comment. So my problem is happy (-haskell) is successfully parsing that file with that grammar but bison isn't (-cpp_stl)
I also noticed markdown has eaten a * in my grammar, comments are (* and *), not ( in comment "(" ")" ;
I didn't manage to reproduce this. What version of bnfc
are you using?
I'm using bnfc 2.7.1 with a modified version of flex 2.5.35 and bison 2.4.1, running on windows (they had to be altered to run on windows), I'm using these versions of flex and bison because they should be fairly well tested from being used in another compiler (plus, running on windows) but I don't discard the possibility of having a bug on them.
did you also get these lines in your lexer?
< YYINITIAL>"(" BEGIN COMMENT; < COMMENT>")" BEGIN YYINITIAL; < COMMENT>. /* BNFC multi-line comment _/; < COMMENT>[\n] ++yymylinenumber ; / BNFC multi-line comment */;
Actually, I found a bug on my generated lexer, lines 1796 to 1800 were:
case 142: YY_RULE_SETUP return BEGIN YYINITIAL; YY_BREAK
I changed to
case 142: YY_RULE_SETUP BEGIN YYINITIAL; YY_BREAK
ran the tests and it worked, so it's my flex
I'm working on a C++ compiler on windows environment with flex, and I just noticed the "comments" token works on my grammar when I generate haskell code, but doesn't when I do it for C++ code, when I run BNFC with -cpp option it seems to completely ignore the "comment" rule, causing a syntax error in my test case's comment