I am attempting to build a clone of the asli interpreter found here GitHub - ARM-software/asl-interpreter: Example implementation of Arm’s Architecture Specification Language (ASL)
What I found with this language is that the precedence of all operators is not defined. It is up to the user to define the precedence by using brackets. This is a language feature to enforce readability. However, it does add a complication.
The language is implemented using Dijkstra’s shunting yard algorithm as opposed to creating (what I consider) traditional syntax trees using the grammar to describe the precedence between operators such as:
expr → mul_expr (+ mul_expr)*
mul_expr → atom (* atom)*
atom → NUMBER
The grammar describes that * has higher precedence than +.
The issue with ASL is that the precedence rules are not so straightforward. Arithmetic operations take precedence over comparisons which take precedence over boolean operators.
With the exceptions that:
^, *, [+ -] have their precedence defined (in order of increasing precedence) and can be mixed with
themselves and with operators of a different priority class (but not the same priority class).
1 ^ 2 - 3 + 4 * 5 is VALID
1 + 1 == 4 *5 is VALID - == is of different class than + and *
1 + 2 << 5 is INVALID - << is of the same class as +
1 DIV 5 * 10 is INVALID - DIV is of the same class as *
Associative operators with their precedence not defined cannot be mixed with other operators other than themselves:
‘10’ AND ‘11’ AND ‘11’ AND ‘10’ is VALID
‘10’ AND ‘11’ OR ‘01’ is INVALID
Given these rules, I would like to hear people’s views on whether this can be described using grammar?