EBNF (Extended Backus-Naur Form)
EBNF (Extended Backus-Naur Form)
Purpose of EBNF
1. =: Defines a rule.
○ Example: RuleName = Definition ;
2. ,: Specifies a sequence (order matters).
○ Example: "if", "(", Expression, ")" means these tokens must
appear in this order.
3. |: Specifies alternatives (OR condition).
○ Example: Condition = "true" | "false" ;
4. [ ... ]: Denotes optional elements.
○ Example: [ "else", Statement ] means the else part is optional.
5. { ... }: Denotes repetition (zero or more times).
○ Example: { Statement } means any number of Statements,
including none.
6. ( ... ): Groups elements for clarity.
○ Example: ( "public" | "private" | "protected" ) groups visibility
modifiers.
7. "...": Encloses literal characters or keywords.
○ Example: "if", "for" represent specific reserved words.
Example of EBNF
Syntax for an if-else statement in a programming language:
Advantages of EBNF