Enhanced C#
Language of your choice: library documentation
Public static fields | List of all members
Loyc.Ecs.EcsPrecedence Class Reference

Contains Precedence objects that represent the precedence rules of EC#. More...


Source file:

Remarks

Contains Precedence objects that represent the precedence rules of EC#.

Summary:
100+: Primary: x.y x::y f(x) a[i] etc.
90+: Prefix: + - ! ~ ++x –x (T)x
80+: Power: x**y
70+: Mult: * / %
60+: Add: + - (Shift is 56 but ideally would be 70)
50+: Range: .. (custom operators are 28 to 55)
40+: Compare: < > <= >= is as using == !=
30+: Bitwise &^| (Ideally would be 54..59)
20+: Conditional && || ^^
10+: Ternary
1: Assignment
-1: Lambda (only the right-hand side of '=>')

When printing an expression, we avoid emitting x | y == z because the ranges of == and | overlap. Instead EcsNodePrinter prints &lsquo;’|`(x, y == z). Admittedly this is rather ugly, but you can enable the ILNodePrinterOptions.AllowChangeParentheses option, which allows parenthesis to be added so that a Loyc tree with the structure &lsquo;’|`(x, y == z) is emitted as x | (y == z), even though the latter is a slightly different tree.

Most of the operators use a range of two adjacent numbers, e.g. 10..11. This represents a couple of ideas for future use in a compiler that allows you to define new operators; one idea is, you could give new operators the "same" precedence as existing operators, but make them immiscible with those operators... yet still make them miscible with another new operator. For instance, suppose you define two new operators glob and fup with PrecedenceRange 41..41 and 40..40 respectively. Then neither can be mixed with + and -, but they can be mixed with each other and fup has higher precedence. Maybe this is not very useful, but hey, why not? If simply incrementing a number opens up new extensibility features, I'm happy to do it. (I could have used a non-numeric partial ordering system to do the same thing, but it would have been more complex, and of questionable value.)

See also
Precedence

Public static fields

static readonly Precedence Substitute = new Precedence(106, 105, 105, 106)
 
static readonly Precedence Of = new Precedence(102)
 
static readonly Precedence Primary = new Precedence(100)
 
static readonly Precedence NullDot = new Precedence(99)
 
static readonly Precedence Prefix = new Precedence(91, 90, 90, 91)
 
static readonly Precedence Power = new Precedence(85)
 
static readonly Precedence Range = new Precedence(80)
 
static readonly Precedence Forward = new Precedence(78)
 
static readonly Precedence Switch = new Precedence(75)
 
static readonly Precedence Multiply = new Precedence(70)
 
static readonly Precedence Add = new Precedence(60)
 
static readonly Precedence Shift = new Precedence(56, 56, 56, 70)
 
static readonly Precedence Backtick = new Precedence(46, 72, 45, 73)
 
static readonly Precedence Compare3Way = new Precedence(42)
 
static readonly Precedence Compare = new Precedence(40)
 
static readonly Precedence IsAsUsing = new Precedence(40, 99, 40, 40)
 
static readonly new Precedence Equals = new Precedence(38)
 
static readonly Precedence AndBits = new Precedence(32, 32, 32, 45)
 
static readonly Precedence XorBits = new Precedence(30, 30, 32, 45)
 
static readonly Precedence OrBits = new Precedence(28, 28, 32, 45)
 
static readonly Precedence And = new Precedence(22)
 
static readonly Precedence Or = new Precedence(20)
 
static readonly Precedence OrIfNull = new Precedence(16)
 
static readonly Precedence PipeArrow = new Precedence(13)
 
static readonly Precedence IfElse = new Precedence(11, 10, 10, 11)
 
static readonly Precedence Assign = new Precedence(26, 0, 0, 1)
 
static readonly Precedence Lambda = new Precedence(85, -1, -2, -1)