/*	EXPR_PAR.PGN produces EXPR_PAR.C.
	Copyright (C) 1992	Keith L. Robertson	All Rights Reserved

	Grammar file for the EXPR expression evaluator PGEN example.
	Modify .PGN and reproduce .C using "PGEN -IC EXPR_PAR.PGN >EXPR_PAR.C"
*/
#include "expr_lex.h"	/* Lexical analyzer for expr. */
#include "expr_sem.h"	/* Semantic action declarations. */
#define		STACK_INC	20
[  # Tokens
	REAL,		IDENTIFIER,
	','  COMMA,	';'  SEMICOLON,
	'='  EQUAL 1r,
	'('  OPEN_P,	')'  CLOSE_P,
	'+'  PLUS  2,	'-'  MINUS 2,
	'*'  TIMES 3,	'/'  DIVIDE 3,
	'^'  POWER 4,	'?'  QUESTION,
	LIST,
	KILL,
	LISP,
	HELP,
]

#-----------------
Session
	| { [Command] ';' ... }
		# ';' is a required separator, optional terminator.
		# Empty command (";;") is harmless.
	;
Command
	| Expression		@ expr_print
	| KILL Kill_ID_List	@ finish_kill
	| LIST			@ list
	| LISP [LISP]		@ lisp
	| HELP			@ session_help
	| '?'			@ session_help
	| error			@ session_error
	;

Kill_ID_List
	| { Kill_ID [','] ... }+
		# ',' is an optional separator, invalid as a terminator.
	;
Kill_ID
	| IDENTIFIER				@ kill_ident
	;

Expression
	| IDENTIFIER '=' Expression		@ expr_assign
	| '(' Expression ')'			@ expr_paren
	| IDENTIFIER '(' Expression ')'		@ function_call
	| 5  Unary  Expression			@ unary
	|    Expression '^'	Expression	@ power
	| 3  Expression Binary2	Expression	@ binary2
	| 2  Expression Binary1	Expression	@ binary1
	| IDENTIFIER				@ look_up_ident
	| REAL
	;

Binary2
	| '*'
	| '/'
	;
Binary1
	| '+'
	| '-'
	;
Unary
	| Binary1
	;
