# OpenEuphoria Manual

## Euphoria v4.1

routine or constant name search

| Up |  |  | TOC | Index
<< 4 Language Reference | < 4.8 Special Top-Level Statements | Up: 5 Formal Syntax | 5.2 Euphoria Internals > | 6 Mini-Guides >>

## 5.1 Formal Syntax

### 5.1.1 Basics

The syntax of Euphoria is described using a form of BNF notation.

    ALPHA ==: ('a' - 'z') | ('A' - 'Z')
    DIGIT ==: ('0' - '9')
    USCORE ==: '_'
    EOL ==: new line character

    IDENTIFIER ==: ( ALPHA | USCORE ) [(AlPHA | DIGIT | USCORE) ... ]

    EXPRESSION ==: NUMEXPR | STREXPR | SEQEXPR | BOOLEXPR

    NUMEXPR ==: (an expression that evaluates to an atom)

    STREXPR ==: (an expression that evaluates to a string sequence)

    SEQEXPR ==: (an expression that evaluates to an sequence)

    BOOLEXPR ==: (an expression that evaluates to an atom in which zero represents
                  falsehood and non-zero represents truth)

    BINARYEXPR ==: [ EXPRESSION BINOP EXPRESSION ]

    BINOP ==: 'and' | 'or' | 'xor' | '+' | '-' | '*' | '/'

    UNARYEXPR ==: [ UNARYOP EXPRESSION ]

    UNARYOP ==: 'not' | '-'

    STATEMENT ==:

    STMTBLK ==: STATEMENT [STATEMENT ...]

    LABEL       ==:  'label' STRINGLIT

    LISTDELIM   ==:  ','

    STRINGLIT   ==: SIMPLESTRINGLIT | RAWSTRINGLIT

    SIMPLESTRINGLIT ==: SSLITSTART [ (CHAR | ESCCHAR) ... ] SSLITEND
    SSLITSTART  ==: '"'
    SSLITEND    ==: '"'
    CHAR        ==: (any byte value)
    ESCCHAR     ==: ESCLEAD ( 't' | 'n' | 'r' | '\' | '"' \ ''')
    ESCLEAD     ==: '\'

    RAWSTRINGLIT ==: DQRAWSTRING | BQRAWSTRING
    DQRAWSTRING ==: '"""' [ MARGINSTR ] [CHAR ...] '"""'
    BQRAWSTRING ==: '`' [ MARGINSTR ] [CHAR ...] '`'
    MARGINSTR  ==: '_' ...

    SCOPETYPE ==: 'global' | 'public' | 'export' | 'override'

    DATATYPE ==: 'atom' | 'integer' | 'sequence' | 'object' | IDENTIFER

### 5.1.2 Statements

#### 5.1.2.1 Directives

INCLUDESTMT
WITHSTMT
NAMESPACE

#### 5.1.2.2 Variables, Constants, Enums

VARDECLARE
CONSTDECLARE
ENUMDECLARE
SLICING

#### 5.1.2.3 Flow Control

IFSTMT
SWITCHSTMT
BREAKSTMT
CONTINUESTMT
RETRYSTMT
EXITSTMT
FALLTHRUSTMT
FORSTMT
WHILESTMT
LOOPSTMT
GOTOSTMT
CALL
IFDEFSTMT

#### 5.1.2.4 Routines

PROCDECLARE
FUNCDECLARE
TYPEDECLARE
RETURN

#### 5.1.2.5 include

INCLUDESTMT

     INCLUDESTMT  ==:  'include' FILEREF [ 'as' NAMESPACEID ] EOL
     FILEREF  ==:  A file path that may be enclosed in double-quotes.
     NAMESPACEID ==: IDENTIFIER

NOTE that after the file reference, the only text allowed is the keyword 'as' or the start of a comment. Nothing else is permitted on the same text line.

See Also: include statement

### 5.1.3 Sequence Slice

SLICING

    SLICE      ==: SLICESTART INTEXPRESSION SLICEDELIM INTEXPRESSION SLICEEND
    SLICESTART ==: '['
    SLICEDELIM ==: '..'
    SLICEEND   ==: ']'

See Also: Slicing of Sequences

### 5.1.4 if

IFSTMT

     IFSTMT  ==:  IFTEST [ ELSIF ...] [ELSE] ENDIF
     IFTEST  ==:  'if' ATOMEXPR [ LABEL ] 'then' [ STMTBLOCK ]
     ELSIF   ==:  'elsif' ATOMEXPR 'then' [ STMTBLOCK ]
     ELSE    ==:  'else' [ STMTBLOCK ]
     ENDIF   ==:  'end' 'if'

See Also: if statement

### 5.1.5 ifdef

IFDEFSTMT

     IFDEFSTMT  ==:  IFDEFTEST [ ELSDEFIF ...] [ELSEDEF] ENDDEFIF
     IFDEFTEST  ==:  'ifdef' DEFEXPR 'then' [ STMTBLOCK ]
     ELSDEFIF   ==:  'elsifdef' DEFEXPR 'then' [ STMTBLOCK ]
     ELSEDEF    ==:  'elsedef' [ STMTBLOCK ]
     ENDDEFIF   ==:  'end' 'ifdef'
     DEFEXPR    ==:  DEFTERM [ DEFOP DEFTERM ]
     DEFTERM    ==:  [ 'not' IDENTIFIER ]
     DEFOP      ==:  'and' | 'or'

See Also: ifdef statement

#### 5.1.5.1 switch

SWITCHSTMT

     SWITCHSTMT  ==:  SWITCHTEST CASE [ CASE ...] [ CASEELSE ] [ ENDSWITCH ]
     SWITCHTEST  ==:  'switch' EXPRESSION [ WITHFALL ] [ LABEL ] 'do'
     WITHFALL    ==:  ('with' | 'without') 'fallthru'
     CASE        ==:  'case' CASELIST 'then' [ STMTBLOCK ]
     CASELIST    ==:  EXPRESSION [(LISTDELIM EXPRESSION) ...]
     CASEELSE    ==:  'case' 'else'
     ENDSWITCH   ==:  'end' 'switch'

See Also: switch statement

### 5.1.6 break

BREAKSTMT

     BREAKSTMT       ==:  'break' [ STRINGLIT ]

See Also: break statement

### 5.1.7 continue

CONTINUESTMT

     CONTINUESTMT       ==:  'continue' [ STRINGLIT ]

See Also: continue statement

### 5.1.8 retry

RETRYSTMT

     RETRYSTMT       ==:  'retry' [ STRINGLIT ]

See Also: retry statement

### 5.1.9 exit

EXITSTMT

     EXITSTMT       ==:  'exit' [ STRINGLIT ]

See Also: exit statement

### 5.1.10 fallthru

FALLTHRUSTMT

     FALLTHRUSTMT       ==:  'fallthru'

See Also: switch statement

### 5.1.11 for

FORSTMT

     FORSTMT ==: 'for' FORIDX [ LABEL ] 'do' [STMTBLK] 'end' 'for'
     FORIDX  ==: IDENTIFIER '=' NUMEXPR 'to' NUMEXPR ['by' NUMEXPR]

See Also: for statement

### 5.1.12 while

WHILESTMT

    WHILESTMT ==:
            'while' BOOLEXPR [WITHENTRY] [LABEL] 'do' STMTBLK [ENTRY] 'end' 'while'
    WITHENTRY ==: 'with' 'entry'
    ENTRY ==: 'entry' [STMTBLK]

See Also: while statement

### 5.1.13 loop

LOOPSTMT

    LOOPSTMT ==:
       'loop' [WITHENTRY] [LABEL] 'do' STMTBLK [ENTRY] 'until' BOOLEXPR 'end' 'loop'

See Also: loop until statement

### 5.1.14 goto

GOTOSTMT

     GOTOSMT ==: 'goto' LABEL

See Also: goto statement

### 5.1.15 declare a variable

VARDECLARE

    VARDECLARE ==: [SCOPETYPE] DATATYPE IDENTLIST
    IDENTLIST ==: IDENT [',' IDENTLIST]
    IDENT ==: IDENTIFIER [ '=' EXPRESSION ]

Notes:

- The type of the `EXPRESSION` must be compatable with the `DATATYPE`.

### 5.1.16 declare a constant

CONSTDECLARE

    CONSTDECLARE ==: [SCOPETYPE] 'constant' IDENTLIST

### 5.1.17 declare an enumerated value

ENUMDECLARE

    ENUMDECLARE ==: [SCOPETYPE] [ ENUMVAL | ENUMTYPE ]
    ENUMVAL ==: 'enum' ['by' ENUMDELTA ] IDENTLIST
    ENUMDELTA ==: [ '+' | '-' | '*' | '/' ] NUMEXPR
    ENUMTYPE ==: 'enum' 'type' ['by' ENUMDELTA ] IDENTLIST 'end' 'type'

### 5.1.18 call a procedure or function

CALL Used to call (invoke) either a procedure or a function.

    CALL ==: IDENTIFIER '(' [ARGLIST] ')'
    ARGLIST ==: ARGUMENT [',' ARGLIST]

See Also: procedures functions

### 5.1.19 declare a procedure

PROCDECLARE

    PROCDECLARE ==: [SCOPETYPE] 'procedure' IDENTIFIER '(' [PARMLIST] ')' [STMTBLK] 'end' 'procedure'
    PARMLIST ==: PARAMETER [',' PARMLIST]
    PARAMETER ==: DATATYPE IDENTIFER

Notes:

- The `procedure` statement block must not contain a `return` statememt.

See Also: procedures

### 5.1.20 declare a function

FUNCDECLARE

    FUNCDECLARE ==: [SCOPETYPE] 'function' IDENTIFIER '(' [PARMLIST] ')' [STMTBLK] 'end' 'function'
    PARMLIST ==: PARAMETER [',' PARMLIST]
    PARAMETER ==: DATATYPE IDENTIFER

Notes:

- The `function` statement block must contain a `return` statememt.

See Also: functions

### 5.1.21 declare a user defined type

TYPEDECLARE

    TYPEDECLARE ==: [SCOPETYPE] 'type' IDENTIFIER '(' PARAMETER ')' [STMTBLK] 'end' 'type'
    PARAMETER ==: DATATYPE IDENTIFER

Notes:

- The `type` statement block must contain a `return` statememt.
- It must return an integer; 0 means that the supplied argument is not of the correct type.

See Also: types

### 5.1.22 return the result of a function

RETURN

    RETURN ==: 'return' EXPRESSION

See Also: types

### 5.1.23 default namespace

    NAMESPACE ==: 'namespace' IDENTIFIER EOL

See Also: Using namespaces

### 5.1.24 with options

WITHSTMT

    WITHSTMT ==: [ "with" | "without" ] WITHOPTION
    WITHOPTION ==: [ "profile" | "profile_time" | "trace" | "batch" |
                     "type_check" | "indirect_includes" | "inline" | WITHWARNING ]
    WITHWARNING ==: "warning" [ WARNOPT]
    WARNOPT ==: SETWARN | ADDWARN | SAVEWARN | RESTOREWARN | STRICTWARN
    SETWARN ==: ['='] '{' WARNLIST '}'
    ADDWARN ==: ['+=' | '&='] '{' WARNLIST '}'
    SAVEWARN ==: 'save'
    RESTOREWARN ==: 'restore'
    STRICTWARN ==: 'strict'

See Also: with / without

| Up |  |  | TOC | Index
<< 4 Language Reference | < 4.8 Special Top-Level Statements | Up: 5 Formal Syntax | 5.2 Euphoria Internals > | 6 Mini-Guides >>