Part 0: Introduction.
*********************

Felix has a rather complex expression grammar. It has a limited ability
to add new infix operators of a fixed precedence (although the
preprocessor directive appears to permit a choice of precedence level).

Now we have the extensible GLR parser available, it is time to
consider redesiging the expression grammar.

There are several aspects. First, we need to partition the
grammar between the compiler and the library. 

Second, we need to devise a way to specify semantic actions
which is better than the large number of hard coded ad hoc
terms currently supported in the compiler.

I want to begin discussion how we should make the new grammar
and extension system look, so please comment! Vent your
pet hates and complaints, make constructive and useless
suggestions, be prepared for controversy,  be willing to make
radical suggestions!


Part 1. The existing grammar (roughly)

expr:
  | LET pattern EQUAL expr IN expr
  | rvalue

rvalue:
  | lambda

lambda:
  | dollar_apply
  | adjectives FUNCTION tvarlist lambda_fun_args opt_type_expr EQUAL
compound
  | adjectives FUNCTION tvarlist lambda_fun_args opt_type_expr
EQRIGHTARROW expr
  | adjectives PROCEDURE tvarlist lambda_fun_args compound
  | adjectives PROCEDURE tvarlist compound

dollar_apply:
  | tuple UNLESS expr THEN dollar_apply
  | tuple DOLLAR dollar_apply
  | tuple

tuple:
  | or_condition tuple_suffix
  | or_condition

tuple_suffix:
  | COMMA or_condition tuple_suffix
  | COMMA or_condition

typeexpr: or_condition

or_condition:
  | and_condition OR or_list
  | and_condition

and_condition:
  | not_condition AND and_list
  | not_condition

not_condition:
  | notop not_condition
  | comparison

comparison:
  | sum cmp_op sum cmp_item_list
  | sum cmp_op sum
  | as_expr

as_expr:
  | as_expr AS NAME
  | setunion

setunion:
  | user10 VBARVBAR setunion_list
  | user10

setunion_list:
  | user10 VBARVBAR setunion_list
  | user10

user10:
  | user10 USER10 setintersection
  | setintersection

setintersection:
  | arrow AMPERAMPER setintersection_list
  | arrow

setintersection_list:
  | arrow AMPERAMPER setintersection_list
  | arrow

arrow:
  | case_literal RIGHTARROW arrow
  | case_literal LONGRIGHTARROW arrow
  | case_literal

case_literal:
  | CASE INTEGER
  | CASE INTEGER OF sum
  | CASE NAME OF sum
  | bor

bor:
  | bor SLOSHVBAR bxor
  | bxor

bxor:
  | bxor SLOSHCIRCUMFLEX band
  | band

band:
  | band SLOSHAMPER shift
  | shift

shift:
  | shift LEFTSHIFT sum
  | shift RIGHTSHIFT sum
  | sum

/* sum formation is 'psuedo-associative' */
sum:
  | subtraction PLUS sum_list
  | subtraction

sum_list:
  | subtraction PLUS sum_list
  | subtraction

subtraction:
  | subtraction MINUS product
  | product

/* product formation is 'psuedo-associative' */
product:
  | term STAR product_list
  | term

/* division is left associative: note higher precedence
the product, so that
a * b/c * d -> a * (b/c) * d
*/

term:
  | term SLASH power
  | term PERCENT power
  | prefixed
/* note weird recursion here: we need to support
-x ** -x = -(x**(-x))
*/

prefixed:
  | LVAL power
  | EXCLAMATION power
  | PLUS power
  | MINUS power
  | TILDE power
  | power

/* exponentiation is right associative */
power:
  | superscript STARSTAR prefixed
  | superscript

superscript:
  | superscript CIRCUMFLEX refr
  | refr

refr:
  | UNION LBRACE type_sum_items2 RBRACE
  | STRUCT compound
  | AMPER refr
  | STAR refr
  | DEREF refr
  | NEW refr
  | application

/* applications is left associative */
application:
  | application coercion
  | CASENO coercion
  | MACRO CTOR NAME coercion
  | coercion

coercion:
  | coercion COLON factor
  | suffixed_name
  | factor

factor:
  | hash_name
  | factor DOT LSQB expr RSQB
  | factor DOT LSQB expr TO expr RSQB
  | factor DOT LSQB expr TO RSQB
  | factor DOT LSQB TO expr RSQB
  | factor DOT simple_name_parts
  | factor DOTRIGHTARROW simple_name_parts
  | factor DOT LPAR INTEGER RPAR

hash_name:
  | HASH hash_name
  | the_name

the_name:
  | NOEXPAND qualified_name
  | THE qualified_name
  | qualified_name
  | QUEST NAME
  | atom

qualified_name:
  | qualified_name COLONCOLON simple_name_parts
  | simple_name_parts

cond:
  | IF expr THEN expr else_part ENDIF

atom:
  | UNDERSCORE
  | CALLBACK LSQB qualified_name RSQB
  | DOTDOTDOT
  | type_match_expr
  | expr_code_prefix NAME
  | expr_code_prefix STRING
  | LSQBAR expr RSQBAR
  | LBRACE expr RBRACE
  | glr_parse
  | match_expr
  | regmatch_expr
  | typecase
  | compound
  | LPAR expr RPAR
  | LPAR RPAR
  | literal
  | cond
  | FSTRING
  | QSTRING
  | USERLB expr USERRB

literal:
  | integer_literal
  | string_literal
  | float_literal

integer_literal:
  | INTEGER

float_literal:
  | FLOAT

string_literal:
  | STRING
  | WSTRING
  | USTRING
  | CSTRING

simple_name_parts:
  | NAME LSQB expr RSQB
  | identifier

identifier:
  | NAME

suffixed_name:
  | qualified_name OF factor
-- 
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
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to