Version: 4.1.4.2
2 C Syntax
This library provides data types representing C abstract syntax, a C parser,
and macros for constructing C abstract syntax with a convenient parenthesized syntax.
It can be required via:
| (require (planet dherman/c:1:0/syntax)) |
2.1 Expressions
| (struct expr:lit (type value)) |
| type : symbol? |
| value : any |
| (struct expr:binop (op left right)) |
| op : symbol? |
| left : expr? |
| right : expr? |
2.2 Declarations
| (struct decl:type:tagged (type)) |
| type : (or/c type:struct? type:union? type:enum?) |
2.3 Types
| (struct type:ref (name)) |
| name : symbol? |
| (struct type:enum (tag variants)) |
| tag : (optional symbol?) |
| variants : list? |
| (struct type:array (type size)) |
| type : type? |
| size : expr? |
| (struct type:pointer (type)) |
| type : type? |
| (struct type:function (return args)) |
| return : type? |
| args : (listof type?) |
2.4 Utility Functions
Determines whether x is a type.
Determines whether x is an expression.
Determines whether x is a declaration.
2.5 S-Expression Syntax
|
| (struct tag-id) | | (struct tag-id (struct-field ...)) | | (struct (struct-field ...)) | | | | struct-field | | = | | [type field-id] | | | | | | | field-id |
|
|
| (union tag-id) | | (union tag-id (union-variant ...)) | | (union (union-variant ...)) | | | | union-variant | | = | | [type variant-id] | | | | | | | variant-id |
|
|
| (enum tag-id) | | (enum tag-id (enum-variant ...)) | | (enum (enum-variant ...)) | | | | enum-variant | | = | | [variant-id expr] | | | | | | | variant-id |
|
|
| (array type size) → type:array? |
| type : type? |
| size : expr? |
| (pointer type) → type:pointer? |
| type : type? |
2.6 Parsing
Parses a C declaration.
Parses a sequence of C declarations.
2.7 C Reader
The module
| (require (planet dherman/c:1:0/reader)) |
provides a reader for C syntax. Using this reader, it is possible to embed C syntax
directly into Scheme programs. For example:
| (define decls |
| #reader (planet dherman/c/reader) { |
| typedef int INT; |
| struct tm { |
| INT tm_sec; |
| INT tm_min; |
| INT tm_hour; |
| INT tm_mday; |
| INT tm_mon; |
| INT tm_year; |
| INT tm_wday; |
| INT tm_yday; |
| INT tm_isdst; |
| }; |
| }) |
The C reader produces a quoted literal list of declarations.