Part 2 .. Notes on the Grammar
******************************

A. Please see:

http://code.felix-lang.org/wiki/Expressions

for another summary of expressions.

B. Expression grammar is basically 4 forms:

  prefixop expr
  expr postfixop
  expr infixop expr
  atom

In this formulation, atom or operator can be compound,
for example:

  let expr in expr

is really a prefix form, with prefixop = let expr in.

C. A general rule for operators is that they can be
prefix and infix (for example minus sign -) or they
can be postfix and infix, but not both prefix and
postfix. This means each operator can be given two
meanings.

D. Precedence rules run into problems with terms like

  - ! f + x

if ! has lower precedence than +, but - has higher precedence
than +, because the inner term resolves to

  !(f+x)

but since - has higher precedence than + we'd also expect

  (-(!f)) + x

and we can't have both. Some terms are also weirdly
balanced for example:

  - x ** - y

means

  - (x ** (-y))

The moral is that designing a good expression grammar is not so easy!

E. Felix also has an interesting issue, that + and * are used for type
annotations:

  x * y * z

is a tuple. Now tuple formation is not associative, and
in fact we do not have an infix operator * here, but
an 3-ary product. I call this kind of operator a chain
operator. In Felix,

  a + b - c + d

is actually

  a + (b - c) + d

because - is left associative, + is a chain operator,
and - has a higher precedence than +. Similarly,
the division operator / has higher precedence than *,
which may cause a couple of surprises in floating point
calculations!

F. I took a decision some time to ago that type expressions
and executable expression would use precisely the same grammar,
so the type + can't be treated differently to the executable +.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to