Extended Backus-Naur Operation Order Form

I am creating a formal specification for a very simple rule language, very simple. I want to use EBNF as it is a standard, but I cannot figure out how to specify the order of operations. Here is the specification so far.

rule = statement, { ('AND'|'OR'), statement}; variable = '$',alphabetic character, {alphabetic character | digit}; statement = variable, [ 'count',[white space ],'>',[white space],number ]; alphabetic character = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" ; number = [ "-" ] , digit , { digit } ; digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; white space = ? white space characters ? ; 

The question I have is how to show that things should be evaluated in brackets first. So something like this

 $strap AND ($greenSticker count > 5 OR ($greenSticker AND $redSticker)) 

Most languages โ€‹โ€‹seem to have a common feature, but my Google skills don't let me, and I can't find an example.

+4
source share
1 answer

Given this as a simplified example of LL grammar:

 expression -> (+|-|ฮต) term ((+|-) term)* term -> factor ((*|/) factor)* factor -> var | number | (expression) 

As you can see, operators with a lower priority ( + and - ) are in a more general rule than operators with a higher priority ( * and / ). It's about creating the right parse tree. But, as a rule, โ€œexternalโ€ or more general rules have lower priority, therefore, the addition and subtraction operators are placed next to the term , because the term must be additionally obtained. If you look at more complex grammars, you will see that this has an extreme limit in order to have proper priority.

+11
source

Source: https://habr.com/ru/post/973503/


All Articles