Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: Index Up: The Glish 2.7 User Manual DRAFT Previous: Glish Syntax and Grammar


Glish Syntax and Grammar

The Glish syntax is free-form.

#35545#> Comments begin with # and extend to the end of the line. Statements are formally terminated with semi-colons but in general Glish is able to infer the end of a statement and supply an implicit terminator at the end of a line. Identifiers are case-sensitive; record field names and event names have separate name spaces and may include keywords.

In the following grammar, some liberties are taken with the normal BNF form in order to simplify the presentation of the grammar. Outside of quotes, ()'s enclose a group of tokens, * indicates zero or more occurrences, and ? indicates zero or one occurrence. Terminals are surrounded with quotes or appear in uppercase.

glish:          statement
        |       error
        |

statement:      '{' statement* '}'
        |       TOK_LOCAL scope_list ';'
        |       TOK_GLOBAL scope_list ';'
        |       TOK_WIDER scope_list ';'
        |       TOK_WHENEVER event_list TOK_DO statement
        |       TOK_LINK event_list TOK_TO event_list ';'
        |       TOK_UNLINK event_list TOK_TO event_list ';'
        |       TOK_AWAIT event_list ';'
        |       TOK_AWAIT TOK_ONLY event_list ';'
        |       TOK_AWAIT TOK_ONLY event_list TOK_EXCEPT event_list ';'
        |       TOK_ACTIVATE ';'
        |       TOK_ACTIVATE expression ';'
        |       TOK_IF '(' expression ')' statement
        |       TOK_IF '(' expression ')' statement TOK_ELSE statement
        |       TOK_FOR '(' TOK_ID TOK_IN expression ')' statement
        |       TOK_WHILE '(' expression ')' statement
        |       TOK_NEXT ';'
        |       TOK_BREAK ';'
        |       TOK_RETURN ';'
        |       TOK_RETURN expression ';'
        |       TOK_EXIT ';'
        |       TOK_EXIT expression ';'
        |       TOK_PRINT actual_params? ';'
        |       TOK_FAIL expression? ';'
        |       expression ';'
        |       ';'

expression:     '(' expression ')'
        |       expression TOK_ASSIGN expression
        |       expression TOK_OR_OR expression
        |       expression TOK_AND_AND expression
        |       expression '|' expression
        |       expression '&' expression
        |       expression TOK_LT expression
        |       expression TOK_GT expression
        |       expression TOK_LE expression
        |       expression TOK_GE expression
        |       expression TOK_EQ expression
        |       expression TOK_NE expression
        |       TOK_LT expression TOK_GT
        |       expression '+' expression
        |       expression '-' expression
        |       expression '*' expression
        |       expression '/' expression
        |       expression'%' expression
|       expression '^' expression
        |       expression TOK_APPLYRX expression
        |       TOK_APPLYRX expression %prec '!'
|       '-' expression %prec '!'
|       '+' expression %prec '!'
|       '!' expression
        |       expression '[' subscript_list ']'
        |       expression '.' TOK_ID
        |       expression TOK_ATTR
        |       expression TOK_ATTR '[' expression ']'
        |       expression TOK_ATTR TOK_ID
        |       '[' '=' ']'
        |       '[' array_record_params? ']'
        |       expression ':' expression
        |       expression '(' opt_actual_params? ')'
        |       value_type expression %prec '^'
|       event '(' actual_params? ')'
        |       TOK_LAST_EVENT
        |       TOK_LAST_REGEX
        |       TOK_INCLUDE expression %prec '!'
|       function
        |       TOK_ID
        |       TOK_CONSTANT
        |       TOK_REGEX

scope_list:     ( scope_item ',' )* scope_item

scope_item:     TOK_ID TOK_ASSIGN expression
        |       TOK_ID

function:       function_head TOK_ID? '(' formal_params? ')' func_body

function_head:  TOK_FUNCTION
        |       TOK_SUBSEQUENCE

formal_params:  ( formal_param ',' )* formal_param

formal_param:   value_type? TOK_ID ( '=' expression )?
        |       TOK_ELLIPSIS ( '=' expression )?

actual_params:  ( actual_param ',' )* actual_param

actual_param:   expression
        |       TOK_ID '=' expression
        |       TOK_ELLIPSIS

opt_actual_params: opt_actual_params ',' actual_param
        |       opt_actual_params ','
        |       ','
        |       ',' actual_param
        |       actual_param

subscript_list: subscript_list ',' expression
        |       subscript_list ','
        |       ','
        |       ',' expression
        |       expression

array_record_params: ( array_record_param ',' )* array_record_param

array_record_param: expression
        |       TOK_CONST TOK_ID '=' expression
        |       TOK_ID '=' expression
        |       TOK_ELLIPSIS

func_body:      '{' statement* '}'
        |       expression %prec ','

event_list:     ( event ',' )* event

event:          expression TOK_ARROW '[' expression ']'
        |       expression TOK_ARROW TOK_ID
        |       expression TOK_ARROW '*'

value_type:     TOK_REF
        |       TOK_CONST
        |       TOK_VAL

next up previous contents index
Next: Index Up: The Glish 2.7 User Manual DRAFT Previous: Glish Syntax and Grammar   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15