home *** CD-ROM | disk | FTP | other *** search
-
- Ctax programs are a series of commands, each a definition or a statement.
-
- command -> definition
- command -> statement
-
- For example:
-
- definitions:
-
- scm x;
-
- scm
- avg (a, b)
- {
- return (a + b) / 2;
- }
-
-
- statements:
-
- 1 + 2;
- avg (4, 9);
-
-
-
- The interpreter reads commands interactively, evaluates them, and
- prints the result. For example:
-
- ctax> scm avg (a, b) { return (a + b) / 2; }
- avg
- ctax> avg (0, 10);
- 5
-
- When loading a source file, ctax reads commands one at a time and evaluates
- them as read, but does not print the result.
-
-
-
- Definition commands are used to create variables and perhaps define
- a value for them.
-
-
- 1. definition -> 'scm' symbol_list ';'
- 2. definition -> 'scm' <id> '=' initializer ';'
- 3. definition -> 'scm' <id> '(' parameter_list ')' opt_doc opt_interaction body
- 4. definition -> 'struct' <id> opt_superclass '{' field_list '}' ';'
- symbol_list -> <id>
- symbol_list -> symbol_list ',' <id>
-
-
- Examples and explanations:
-
- 1. scm a, b, c;
- Declares new variables, initially set to 0.
- Note that "scm" is the "univeral type" -- all
- values can be stored in a variable of type "scm".
-
- At the moment, procedures, parameters and variables
- can *only* be of type "scm", though in the future this
- restriction will be relaxed and optional type-checking
- provided.
-
- 2. scm a = 1 + x;
- Declare and initialize a single variable.
-
-
- 3. scm
- avg (a, b)
- {
- scm t;
-
- t = a + b;
- return t / 2;
- }
-
- Declare a new procedure. Note that the body of the procedure
- has a section of local declarations followed by a section of
- statements.
-
- 4. struct user_record
- {
- scm name;
- scm uid;
- scm homedir;
- scm passwd;
- scm shell;
- };
-
- Declare a new structure type. Note that currently all fields must be
- of type 'scm', the universal type, but this restriction will be
- relaxed in the future.
-
-
- Definitions such as the above can occur either globally, at the top
- level, or inside of a block, before any statements.
-
-
-
- Here are structure declarations in detail.
-
- definition -> 'struct' <id> opt_superclass '{' field_list '}' ';'
- opt_superclass -> ':' <id>
- opt_superclass -> /* empty */
- field_list -> <id> ';'
- field_list -> 'scm' <id> ';'
- field_list -> field_list <id> ';'
- field_list -> field_list 'scm' <id> ';'
- field_list -> /* empty */
-
-
- Examples:
-
- struct point
- {
- x;
- y;
- };
-
- struct point_3 : point
- {
- z;
- };
-
- struct verbose_point
- {
- scm x;
- scm y;
- scm z;
- };
-
- Note that, at present, unlike C, you can not delcare variables and define
- structure types in the same command. There is no syntax for fields which
- are arrays or sub-structures. There aren't unions. All of these restrictions
- are likely to be relaxed in the future.
-
- The fundamental operation on structures is field access:
-
- some_point->x;
-
- Field access is polymorphic -- it works on any structure with a field of
- the right name. Thus with:
-
- struct big
- {
- scm x;
- scm y;
- };
-
- struct little
- {
- scm y;
- scm x;
- };
-
- scm
- get_x (a_struct)
- {
- return a_struct->x;
- }
-
- get_x can be called on structs of both type "struct big" and type
- "struct little".
-
- In the current implementation, when get_x is called, it caches the location
- of field x. So, if get_x is called again on the same structure type (or
- on any structure type with "x" in the same position), field access is pretty
- fast. If get_x is called on a new type, there is a short linear search to find
- the field.
-
- In the future, ctax will permit programmers to declare variable to be
- of specific types. That will permit both optional static type
- checking and very fast structure access.
-
-
-
- Here are procedure definitions in detail.
-
- definition -> 'scm' <id> '(' parameter_list ')' body
- parameter_list -> <id>
- parameter_list -> 'scm' <id>
- parameter_list -> parameter_list ',' <id>
- parameter_list -> parameter_list ',' 'scm' <id>
- parameter_list -> /* empty */
- body -> '{' local_definition_list statement_list '}'
- local_definition_list -> definition
- local_definition_list -> local_definition_list definition
- local_definition_list -> /* empty */
- statement_list -> statement
- statement_list -> statement_list statement
-
- Several examples have already been shown, for example:
-
- scm
- avg (scm a, scm b)
- {
- scm c;
-
- c = a + b;
- return c / 2;
- }
-
- It is mandatory to declare a return type, and currenly the only
- return type permitted is the universal type, "scm".
- It is optional to declare types of parameters, currently the
- only type permitted is "scm".
-
- Local declarations must preceed statements and have the same syntax
- as top-level declarations.
-
- Variable scoping is lexical. That is, a variable is looked for first
- in the innermost local declarations, then moving out through local
- scopes through parameters and finally global variables.
-
-
-
- Statements in detail:
-
- statement -> expression ';'
- statement -> 'if' '(' expression ')' statement opt_else
- statement -> 'while' '(' expression ')' statement
- statement -> 'for' '(' exp1 ';' exp1 ';' exp1 ')' statement
- statement -> 'do' statement 'while' '(' expression ')' ';'
- statement -> '{' local_definition_list statement_list '}'
- statement -> 'return' opt_expression ';'
- statement -> 'break' ';'
- statement -> 'continue' ';'
- opt_expression -> expression
- opt_expression -> /* empty */
- opt_else -> 'else' statement
- opt_else -> /* empty */
-
- These are all just what you would expect from C, except that the
- expression syntax has some differences.
-
-
- Expressions are similar to C, but with some ommissions and extensions.
-
- Expression syntax that overlaps with C:
-
- expression -> exp1
- exp1 -> exp
- exp1 -> exp1 ',' exp
- exp -> '-' exp
- exp -> '!' exp
- exp -> '~' exp
- exp -> '(' exp1 ')'
- exp -> exp '(' arg_list ')'
- opt_params -> '(' arg_list ')'
- opt_params -> /* empty */
- exp -> exp '->' <id>
- exp -> exp '[' exp ']'
- exp -> exp '=' exp
- exp -> exp '*' exp
- exp -> exp '/' exp
- exp -> exp '%' exp
- exp -> exp '+' exp
- exp -> exp '-' exp
- exp -> exp '<<' exp
- exp -> exp '>>' exp
- exp -> exp '>>?' exp
- exp -> exp '==' exp
- exp -> exp '!=' exp
- exp -> exp '<=' exp
- exp -> exp '>=' exp
- exp -> exp '<' exp
- exp -> exp '>' exp
- exp -> exp '&' exp
- exp -> exp '^' exp
- exp -> exp '|' exp
- exp -> exp '&&' exp
- exp -> exp '||' exp
- exp -> exp '?' exp ':' exp
- exp -> <number>
- exp -> <char>
- exp -> <string>
- exp -> <id>
- arg_list -> exp
- arg_list -> arg_list ',' exp
- arg_list -> /* empty */
-
-
- Some operators come with a corresponding generic form. This version
- of the operator can be extended by your program to apply to any type
- in arbitrary ways. (On the other hand, there is a performance penalty
- for using these hyper-general operators.)
-
- The overloading mechanism is not yet documented.
-
- exp -> '!:' exp
- exp -> '~:' exp
- exp -> exp '->:' <id>
- exp -> exp '[:' exp ']:'
- exp -> exp '=:' exp
- exp -> exp '*:' exp
- exp -> exp '/:' exp
- exp -> exp '%:' exp
- exp -> exp '+:' exp
- exp -> exp '-:' exp
- exp -> exp '<<:' exp
- exp -> exp '==:' exp
- exp -> exp '!=:' exp
- exp -> exp '<=:' exp
- exp -> exp '>=:' exp
- exp -> exp '<:' exp
- exp -> exp '>:' exp
- exp -> exp '&:' exp
- exp -> exp '^:' exp
- exp -> exp '|:' exp
- exp -> exp '&&:' exp
- exp -> exp '||:' exp
-
-
-
- Expressions have some extensions that are not much like C
- at all.
-
-
- exp -> '@:' <id>
-
- example: @:fnord
-
- This is a way to write a "keyword" (c.f. scm.info).
- A keyword is simply a self-evaluating symbolic value.
-
- exp -> '@'<string>
-
- example: @"(+ 1 2)"
-
- This is a way to write an arbitrary, readable, Scheme
- value. The example expression is a three element list (not
- the number 3).
-
- exp -> '@' '(' arg_list ')'
-
- example: @( x0 + vx, y0 + vy, z0 + vz)
-
- This constructs a list. The example constructs
- a three element list.
-
- exp -> '@' '[' arg_list ']'
-
- example: @[ x0 + vx, y0 + vy, z0 + vz]
-
- This constructs a vector (an array). The example constructs
- a three element vector.
-
- exp -> '@bit[' arg_list ']'
- exp -> '@uing[' arg_list ']'
- exp -> '@int[' arg_list ']'
- exp -> '@float[' arg_list ']'
- exp -> '@double[' arg_list ']'
- exp -> '@complex[' arg_list ']'
-
- example: @int[ x0 + vx, y0 + vy, z0 + vz]
-
- These construct uniform arrays of various sorts (cf scm.info).
-
- exp -> '@\(' param_list ')' body
-
- example: @\(a, b) { return a + b; }
-
- This constructs an anonymous procedure.
-
-
- exp -> 'new' 'struct' <id> opt_params
-
- example: p = new struct point (3, 4);
- p2 = new struct point;
-
- Allocate a new structure.
-
-
- exp -> '(' ctax_struct_lx ctax_id_lx ')'
-
- example: p_type = (struct point);
-
- Return a type object for a structure type.
-
-
- exp -> '(' ctax_struct_lx ctax_id_lx opt_superclass '{' field_list '}' ')'
-
-
- example: p_type = (struct point { scm x; scm y; );
-
- Return a new anonymous type object for a structure type.
-
-