Skip to content

5 The Language

Spydr edited this page Apr 1, 2022 · 9 revisions

5 - The Lanugage

5.1 - Lexical Conventions

CSpydr is free-from, meaning that spaces and comments are ignored, except in strings, in characters and as delimiters between tokens. Spaces are recognized as whitespaces, carriage returns and tabs. Only ASCII characters are accepted.

Identifiers consist of a series of alphanumeric characters or underscores, not starting with a digit. Next to that, CSpydr is case-sensitive. meaning that myid and myID are two different identifiers. When compiled with the C backend identifiers may not start with __csp_. CSpydr has a series of keywords, which cannot be used as identifiers

Keywords:

true      false  nil    let     fn
loop      while  for    if      else
ret       match  type   struct  union
enum      import const  extern  macro
namespace sizeof typeof alignof break
continue  noop   len    asm     using
with

Symbols:

++  +=  +   --  -=  -   *=  *
%=  %   /=  /   &=  &&  &   ^
^=  <<= >>= <<  >>  ||  |=  |>
|   ==  =>  =   !=  !   >=  <=
<-  <   >   (   )   {   }   [
]   ~   ,   ;   _   ::  ... ²
³   $ `

Strings & Characters:

String literals are delimited by double quotes (") and can contain any amount of any character except non-escaped double quotes. Character literals are delimited by single quotes (') and can only contain one single character, or an escape sequence. These escape sequences include the following:

Literal characters Interpreted character
\a Bell (alert)
\b Backspace
\f Form Feed
\n Newline
\r Carriage return
\t Horizontal Tab
\v Vertical Tab
' Single Quote
" Double Quote
\ Backslash
\0 Null character

Numbers:

An integer constant can be written as decimal, hexadecimal, binary or octal. Floating-point constants can only be written in decimal and must include a radix point. All number literals can contain as many underscores _ as you like for better visual parsing. Examples of valid numerical constants are the following:

99   1        1_000_000
0xff 0xabcdef 0x3d
0o77 0o7234   0o0
0b11 0b10010  0b11011
1.2  3.1415  1_234.567 

Comments:

Comments can be either single-line or blocks. Single-line comments are denoted by a hashtag # and include the rest of the line, while block comments are denoted by #[ and go on until ]#.

5.2 - Variables, Members and Arguments

Clone this wiki locally