[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 Lexical structure

Gauche extends R5RS Scheme parser in some ways:

Nested block comments (SRFI-30)

A text surrounded by '#|' and '|#' becomes a comment. It can be nested.

Numeric literals

Either integral part or fraction part of inexact real numbers can be omitted if it is zero, i.e. 30., .25, -.4 are read as real numbers. The number reader recognizes '#' as insignificant digits. Complex numbers can be written both in the rectangular format (e.g. 1+0.3i) and in the polar format (e.g. 3.0@1.57). Inexact real numbers include the positive infinity, the negative infinity, and NaN, which are represented as +inf.0, -inf.0 and +nan.0, respectively. (-nan.0 is also read as NaN.)

Symbol names

Symbol names are case sensitive by default (See section Case-sensitivity). Symbol name can begin with digits, '+' or '-', as long as the entire token doesn't consist valid number syntax. Other weird characters can be included in a symbol name by surrounding it with '|', e.g. '|this is a symbol|'. See section Symbols, for details.

Character literal by character code

Character literals can be written using its code, by #\xNN (Gauche internal code) or #\uNN (Unicode). See section Characters, for details.

Extended sharp syntax

Many more special tokens begins with '#' are defined. See the table below.

The table below lists sharp-syntaxes.

#!

[R6RS][SRFI-22] It is either a beginning of an interpreter line (shebang) of a script, or a special token that affects the mode of the reader. See `hash-bang token' section below.

#", ##, #$, #%, #&, #'

Unused.

#(

[R5RS] Introduces a vector.

#)

Unused.

#*

If followed by a double quote, denotes an incomplete string. See section Strings.

#+

Unused.

#,

[SRFI-10] Introduces reader constructor syntax.

#-, #.

Unused.

#/

Introduces a literal regular expression. See section Regular expression.

#0#9

[SRFI-38] Shared substructure definition and reference.

#:

Unused

#;

[SRFI-62] S-expression comment. Reads next one S-expression and discard it.

#<

Introduces an unreadable object.

#=, #>

Unused.

#?

Introduces debug macros. See section Debugging.

#@

Unused.

#a

Unused.

#b

[R5RS] Binary number prefix.

#c

Unused.

#d

[R5RS] Decimal number prefix.

#e

[R5RS] Exact number prefix.

#f

[R5RS] Boolean false, or introducing SRFI-4 uniform vector. See section gauche.uvector - Uniform vectors.

#g, #h

Unused.

#i

[R5RS] Inxact number prefix.

#j, #k, #l, #m, #n

Unused.

#o

[R5RS] Octal number prefix.

#p, #q, #r

Unused.

#s

[SRFI-4] introducing SRFI-4 uniform vector. See section gauche.uvector - Uniform vectors.

#t

[R5RS] Boolean true.

#u

[SRFI-4] introducing SRFI-4 uniform vector. See section gauche.uvector - Uniform vectors.

#v, #w

Unused.

#x

[R5RS] Hexadecimal number prefix.

#y, #z

Unused.

#[

Introduces a literal character set. See section Character Set.

#\

[R5RS] Introduces a literal character. See section Characters.

#], #^, #_

Unused.

#`

Introduces an interpolated string. See section String interpolation.

#{

Unused.

#|

[SRFI-30] Introduces a block comment. Comment ends by matching '|#'.

#}, #~

Unused.

Hash-bang token

A character sequence #! has two completely different semantics, depending on how and where it occurs.

If a file begins with #!/ or #! (hash, bang, and a space), then the reader assumes it is an interpreter line (shebang) of a script and ignores the rest of characters until the end of line. (Actually the source doesn't need to be a file. The reader checks whether it is the beginning of a port.)

Other than the above case, #!identifier is read as a token with special meanings. This kind token can be a special directive for the reader, instead of read as a datum.

By default, three of such tokens are recognized. #!fold-case and #!no-fold-case switches the reader's case sensitivity; #!fold-case makes the reader case insensitive, and #!no-fold-case makes it case sensitive. (Also see Case-sensitivity).

The token #!r6rs is introduced in R6RS and used to indicate the program is strictly conforms R6RS. Gauche doesn't support R6RS, and currently it issues warning when it sees #!r6rs token, though it keeps reading on.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Shiro Kawai on October, 7 2008 using texi2html 1.78.