!  Premier: Command Language Description file.
!  ==========================================
!  Version 3.10  20 May 1990
!
!  (c) Circle Software.
!

! Operator definitions.
! ====================

_append        = "APPEND";
_attach        = "ATTACH";
_assign        = "ASSIGN";
_beep          = "BEEP";
_break         = "BREAK";
_buffer        = "BUFFER";
_case          = "CASE";
_centrejust    = "CENTRE";
_clear         = "CLEAR";
_close         = ")"$;
_close_window  = "CLOSE";
_colour        = "COLOUR";
_column        = "COLUMN";
_command       = "COMMAND";
_controlcol    = "CONTCOL";
_copy          = "COPY";
_cut           = "CUT";
_data          = "DATA";
_datawindow    = "DATAWINDOW";
_debug         = "DEBUG";
_delete        = "DELETE";
_direction     = "DIRECTION";
_dispose       = "DISPOSE";
_do            = "DO";
_domacro       = "";
_dump          = "DUMP";
_edit          = "EDIT";
_end           = "END";
_endif         = "";
_endloop       = "";
_enter         = "ENTER";
_end_function  = "";
_end_key       = "";
_end_macro     = "";
_execute       = "EXECUTE";
_exit          = "EXIT";
_font          = "FONT";
_find          = "FIND";
_finder        = "FINDER";
_filer         = "FILER";
_filter        = "FILTER";
_flag          = "FLAG";
_footer        = "FOOTER";
_settype       = "SETTYPE";
_gap           = "GAP";
_goto          = "GOTO";
_header        = "HEADER";
_help          = "HELP";
_index         = "INDEX";
_insert        = "INSERT";
_justify       = "JUSTIFY";
_line          = "LINE";
_load          = "LOAD";
_margincol     = "MARGCOL";
_margins       = "MARGINS";
_marker        = "MARKER";
_markercol     = "MARKCOL";
_mark          = "MARK";
_menu          = "MENU";
_messages      = "MESSAGES";
_newint        = "";
_newstr        = "";
_cursor        = "CURSOR";
_noop          = "";
_offer         = "OFFER";
_open_window   = "OPEN";
_page          = "PAGE";
_papercol      = "PAPERCOL";
_paste         = "PASTE";
_print         = "PRINT";
_prompt        = "PROMPT";
_quit          = "QUIT";
_read          = "READ";
_record        = "RECORD";
_replace       = "REPLACE";
_replay        = "REPLAY";
_rewind        = "REWIND";
_rightjust     = "RIGHT";
_save          = "SAVE";
_savemarked    = "SAVEMARKED";
_scroll        = "SCROLL";
_search        = "SEARCH";
_seek          = "SEEK";
_select        = "SELECT";
_send          = "SEND";
_show          = "SHOW";
_skip          = "SKIP";
_spool         = "SPOOL";
_star          = "*";
_start         = "START";
_swapcase      = "SWAPCASE";
_syntax        = "SYNTAX";
_tab           = "TAB";
_tabs          = "TABS";
_type          = "TYPE";
_unmark        = "UNMARK";
_update        = "UPDATE";
_vdu           = "VDU";
_wait          = "WAIT";
_window        = "WINDOW";
_winddef       = "WINDOW";
_write         = "WRITE";

_open     #-1  = "(";
_comma    #1   = ","$;
_ass_int  #2   = "=";
_ass_str  #2   = "=";
_add_ass  #2   = "+=";
_sub_ass  #2   = "-=";
_mul_ass  #2   = "*=";
_div_ass  #2   = "/=";
_or       #4   = "OR";
_and      #5   = "AND";
_streq    #9   = "==";
_strneq   #9   = "<>";
_eq       #9   = "==";
_ne       #9   = "<>";
_gt       #10  = ">";
_lt       #10  = "<";
_ge       #10  = ">=";
_le       #10  = "<=";
_strlt    #10  = "<";
_strgt    #10  = ">";
_add      #12  = "+";
_concat   #12  = "+";
_sub      #12  = "-";
_div      #13  = "/";
_mult     #13  = "*";
_centre   #14  = "=";
_left     #14  = "<";
_not      #14  = "NOT";
_negate   #14  = "-";
_right    #14  = ">";
_key      #15  = "KEY";
_code     #15  = "|";
_string   #15  = "$";
_money    #15  = "%";
_hex      #15  = "&";
_value    #15  = "#";
_end_list #16  = "";
_if       #16  = "IF";
_defmacro #16  = "";
_strfunc  #16  = "";
_intfunc  #16  = "";
_else     #16  = "ELSE";
_loop     #16  = "REPEAT";

   
!  Pre-Defined operand types.
!  =========================

_macro                #16 =  name;

_integer_function     #16 =  name;
_integer_variable     #16 =  name;
_integer_constant     #16 =  [ hex_constant  decimal_constant ];

_string_function      #16 =  name;
_string_variable      #16 =  name;
_system_integer       #16 =  name;
_string_constant      #16 =  '"' string_character*96? '"'$;

_system_string        #16 =  name;
_system_function      #16 =  name;


!  Command definitions.
!  ===================

command = [ key  macro  buffer  window  winddef  goto  find  insert marker 
            markcol _mark copy  _unmark  select  skip  open  close delete load
            savemarked  save  page  paste _record _replay _exit _quit if cut 
            edit  cursor  assign  repeat  wait newint  newstr  defmacro  
            strfunc  intfunc  font  do  offer  index _command  search  clear  
            line  column  settype  update tab _beep
            messages  debug  prompt  dispose  direction  _end  _start 
            show  tabs  margins  scroll  type  _swapcase case  string  syntax  
            replace  colour  spool  _print  send  execute _filer _finder  _help
            filter _read  _datawindow  data  _append  seek _write _rewind 
            header  footer  vdu justify  break _rightjust _centrejust  gap 
            _enter menu flag papercol contcol margcol star _dump assignment ]
            _noop;


command_list = [ ( "{" command*? "}"$ )   command ];

assign   =  _assign   marker_name$  _comma   window_name$;
break    =  _break    "="? integer_expression$;
buffer   =  _buffer   _end_list new_name$ ( _comma  integer_expression)?;
case     =  _case     "="? integer_expression$;
clear    =  _clear    buffer_name$;
close    =  _close_window  window_name$;
colour   =  _colour   "="? integer_expression$;
column   =  _column   "="? integer_expression$;
contcol  =  _controlcol "="? integer_expression$;
copy     =  _copy   _end_list  marker_name? ( _comma  marker_name )*2?;
cursor   =  _cursor  integer_expression$;
cut      =  _cut    _end_list  marker_name? ( _comma  marker_name )*2?;
data     =  _data     "="? file_name$;
debug    =  _debug    integer_expression$;
delete   =  _delete;
direction=  _direction "="? string_expression$;
dispose  =  _dispose   object_name$;
do       =  _do        buffer_name$;
defmacro =  "MACRO"    new_name$  "="? _defmacro command_list$  _end_macro;

strfunc  =  "STR" "FUNCTION" new_name$ _strfunc   command_list?
                        "="$  string_expression$  _end_function;
intfunc  =  "INT" "FUNCTION" new_name$ _intfunc   command_list?
                        "="$  integer_expression$  _end_function;

edit     =  _edit     window_name$;
execute  =  _execute  string_expression$;
find     =  _find    string_expression$;
filter   =  _filter "="? _end_list field_number$  ( _comma filter_logic$ 
                       _comma  filter_operator$  _comma string_expression$ )?;
flag     =  _flag menu_name$ ( _comma integer_expression$ )*3;
font     =  _font     "="? integer_expression$;
footer   =  _footer   "="? string_expression$;
gap      =  _gap      "="? integer_expression$;
goto     =  _goto    marker_name$;
header   =  _header  "="? string_expression$;
if       =  _if _open condition$ _close command_list$ 
                               ( _else command_list )? _endif;
index    =  _index   field_number$;
insert   =  _insert  _end_list string_expression$ ( _comma marker_name$ )?;
justify  =  _justify "="? integer_expression$;
key      =  _key     integer_expression$  _noop "="?  command_list$  _end_key;
line     =  _line    "="?  integer_expression$;
load     =  _load    file_name$;
macro    =  _macro  _domacro;
margcol  =  _margincol "="? integer_expression$;
margins  =  _margins   "="? left_margin$ _comma right_margin$;
markcol  =  _markercol "="? integer_expression$;
marker   =  _marker  new_name$;
menu     =  _menu  new_name$ "="?  string_expression$;
messages =  _messages "="? integer_expression$;
newint   =  "INT" new_name$  _newint _noop _ass_int integer_expression$;
newstr   =  "STR" new_name$  _newstr _noop _ass_str string_expression$;
offer    =  _offer menu_name$;
open     =  _open_window  window_name$;
page     =  _page  _end_list "="?
                integer_expression$ ( _comma  integer_expression$ )*3
                ( _comma integer_expression )?;
papercol =  _papercol "="? integer_expression$;
paste    =  _paste   marker_name?;
prompt   =  _prompt string_expression$ _comma
                [ string_variable$ integer_variable$ system_str_variable$ ];
repeat   =  _loop    command_list  _endloop "UNTIL" condition$;
replace  =  _replace string_expression$;
savemarked = _savemarked file_name$;
save     =  _save    buffer_name$  file_name$;
seek     =  _seek    field_number$ _comma  string_expression$;
scroll   =  _scroll  "="? line_scroll_margin$  _comma  column_scroll_margin$;
search   =  _search  string_expression$;
select   =  _select  marker_name$;
send     =  _send    string_expression$;
settype  =  _settype "="? integer_expression$;
show     =  _show   _end_list show_item ( _comma show_item )*? ;
skip     =  _skip    string_expression$;
spool    =  _spool   file_name$;
star     =  _star    string_expression$;
string   =  _string  integer_expression$;
syntax   =  _syntax  string_expression$;
tab      =  _tab     "="? integer_expression$;
tabs     =  _tabs    "="? _end_list integer_expression$  
                           ( _comma  integer_expression )*15?;
type     =  _type    "="? integer_expression$;
update   =  _update  _end_list ( marker_name _comma marker_name$ )?;
vdu      =  _vdu     _end_list integer_constant$ ( _comma integer_constant )*?;
wait     =  _wait    integer_expression$;
window   =  _window  new_name$  "="?   integer_expression$ 
                              ( _comma integer_expression$ )*3;
winddef  =  _winddef new_name$;

system_function     = _system_function  _open integer_expression _close;
macro_name          =  string_expression;
file_name           =  string_expression;
integer_constant    = _integer_constant;
string_variable     = _string_variable;
integer_variable    = _integer_variable;
string_constant     = _string_constant;
object_name         =  string_expression;
left_margin         =  integer_expression;
right_margin        =  integer_expression;
line_scroll_margin  =  integer_expression;
column_scroll_margin=  integer_expression;
field_number        =  integer_expression;
filter_operator     =  integer_expression;
filter_logic        =  integer_expression;
new_name            =  string_expression;
window_name         =  string_expression;
marker_name         =  string_expression;
menu_name           =  string_expression;
buffer_name         =  string_expression;
system_str_variable =  system_function;
system_str_function =  system_function;

name            = <'a'-'z'>  <'a'-'z'  '0'-'9'  '$'  '.'  '_'>*31?;

esc_sequence    = <'\'> [ escape_char  numeric_char  print_character ];

escape_char     = < 'a'  'b'  'f'  'n'  'r'  't'  'v'  '\'  '"' >;
numeric_char    = [ ( digit$  digit*2? ) 
                    ( <'x'>  hex_digit$  hex_digit? ) ];

print_character = < 32  33  35-91  93-126 >;
hex_digit       = < '0'-'9'  'A'-'F'  'a'-'f' >;
digit           = < '0'-'9' >;

decimal_constant = digit digit*9?;
hex_constant     = <'0'><'x'> hex_digit hex_digit*7?;

variable_name    = [ _integer_variable  _string_variable ];
condition        = logical_expression ( logical_operator logical_expression )*?;
string_character = [ print_character  esc_sequence ];
show_item        = [ string_expression$  integer_expression$ ];

field_width      =  simple_integer;


! Assignment statements.
! =====================

assignment         = [ integer_assignment  string_assignment ];

integer_assignment = _integer_variable assignment_operator integer_expression;

string_assignment  = [ _string_variable system_str_variable ]
                           _ass_str  string_expression;

! Integer expressions.
! ===================

converted_integer  = _value  simple_string$;

simple_integer  = unary_operator? [ _integer_constant _system_integer  
                _integer_function _integer_variable parenthesised_expression ];

integer_item    = [ converted_integer simple_integer ];

arithmetic_expression = integer_item ( arithmetic_operator integer_item )*?;

numeric_logic_expression = 
               arithmetic_expression comparison_operator arithmetic_expression;

string_logic_expression = 
               string_expression string_comparison_operator string_expression;

logical_expression = [ numeric_logic_expression  string_logic_expression ];

integer_expression = [ arithmetic_expression logical_expression integer_item ];

parenthesised_expression = _open  integer_expression  _close ;


! String expressions.
! ==================

simple_string    = [ _string_constant  _string_function 
                     _string_variable  _system_string 
                      system_str_function  parenthesised_string ];

justified_string = field_width  justification_operator$  simple_string$;

converted_string = [ _string  _money  _code  _hex ]  simple_integer$;

string_item      = [ simple_string  converted_string  justified_string  ];

string_expression = string_item  ( string_operator string_item$ )*?;

parenthesised_string   = _open  string_expression  _close;



! Operators.
! =========

justification_operator = [ _left  _centre  _right ] ;

binary_operator       = [ logical_operator   arithmetic_operator ];

string_operator       = _concat;

string_comparison_operator = [ _streq  _strneq  _strlt  _strgt ] ;
                    
arithmetic_operator   = [ _add  _sub  _mult  _div ];

logical_operator      = [ _and  _or ];

comparison_operator   = [ _ne  _ge  _le  _eq  _gt  _lt ];

unary_operator        = [ _not  _negate ];

assignment_operator   = [ _ass_int  _add_ass  _sub_ass  _mul_ass  _div_ass ];

