On this page:
2.1 Parenthetical C
declare
function
struct
8.12

2 Internals🔗ℹ

This section describes the internals of Rince as a reference for developers. The interfaces here may change at any time. Do not use these in external code.

2.1 Parenthetical C🔗ℹ

The parser transforms C syntax into the S-expressions described here.

syntax

(declare maybe-storage-class base-type decl ...)

 
maybe-storage-class = 
  | #:extern
  | #:static
  | #:auto
  | #:register
     
decl = declarator
  | declarator = initializer
Declares type tags and variables. A declarator is a type expression with the variable identifier in place of the base type.

For example:

C

 

Racket

extern int x, y = 1;

 

(declare #:extern int x y = 1)

int * const p;

 

(declare int (const (ptr p)))

int (*f)(int);

 

(declare int (ptr (function f ([int]))))

struct { int x; } s;

 

(declare (struct ([int x])) s)

struct foo { int x; };

 

(declare (struct foo ([int x])))

struct foo;

 

(declare (struct foo))

int f(void);

 

(declare int (function f ([void])))

syntax

(function ret-type args)

(function maybe-storage-class ret-type id args body)
 
args = (arg ...)
  | (arg ... ...)
     
arg = [type]
  | [base-type declarator]
The first form specifies a function type or forms part of a declarator.

The second form defines a function.

As in C, an unspecified argument list is (), and an empty argument list is ([void]). Unspecified trailing arguments are represented by ... at the end of the list.

syntax

(struct maybe-tag (member-decl ...))

(struct tag)
 
member-decl = [base-type declarator ...+]
Specifies a struct type.

The first form defines a (possibly anonymous) struct type.

The second form refers to a previously defined struct type, or (as the base type in a declaration) declares a new struct tag.