Next: , Previous: , Up: Grammar   [Contents][Index]


4.10 Complete programs

A complete coNCePTuaL program consists of zero or more header declarations (see Header declarations), each terminated with a ‘.’, followed by one or more complex statements (see Complex statements), each also terminated with a ‘.’. More formally, coNCePTuaL’s top-level nonterminal is the <program>:

<program> ::= ( <version_decl> | <param_decl> | <backend_decl> [‘.’])*
( <top_level_complex_stmt> [‘.’])+
<top_level_complex_stmt> ::= <complex_stmt>

Because a <complex_stmt> can reduce to a <simple_stmt>, the most basic, complete coNCePTuaL program would be a <simple_stmt> with a terminating period:

ALL TASKS self OUTPUT "Hello from task " AND self AND "!".

A fuller example might contain multiple header declarations and multiple <complex_stmt>s:

# A complete coNCePTuaL program
# By Scott Pakin <pakin@lanl.gov>

REQUIRE LANGUAGE VERSION "1.5".

maxval IS "Maximum value to loop to" AND COMES FROM "--maxval" OR
  "-v" WITH DEFAULT 100.

step IS "Increment after each iteration" AND COMES FROM "--step" OR
  "-s" WITH DEFAULT 1.

TASK 0 OUTPUTS "Looping from 0 to " AND maxval AND " by " AND step
  AND "...".

FOR EACH loopvar IN {0, step, ..., maxval}
  TASK 0 OUTPUTS "    " AND loopvar.

TASK 0 OUTPUTS "Wasn't that fun?".

Technically, the ‘.’ is optional; the language is unambiguous without it. However, for aesthetic purposes it is recommended that you terminate sentences with a period, just like in a natural language. An exception would be when a <complex_stmt> ends with a curly brace. The ‘}.’ syntax is unappealing so a simple ‘}’ should be used instead. See Examples, for further examples.


Next: , Previous: , Up: Grammar   [Contents][Index]

Scott Pakin, pakin@lanl.gov