Skip to content

Commit d985dd2

Browse files
committed
Update documentation
1 parent 019123b commit d985dd2

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ For details, see [here](import).
505505
Some macros are prepared to customize the parser.
506506
The macro definition should be **in `%source` section** in the PEG source.
507507

508-
```
508+
```c
509509
%source {
510510
#define PCC_GETCHAR(auxil) get_character((auxil)->input)
511511
#define PCC_BUFFERSIZE 1024

import/code/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,51 @@ The concrete usage procedure is shown below.
114114
}
115115
```
116116
117+
#### Macros
118+
119+
Some macros are prepared to customize the behavior of memory allocation for AST nodes.
120+
The macro definition should be **in `%source` section** in the PEG source.
121+
122+
The following macros are available.
123+
124+
**`PCC_AST_MALLOC(`**_mgr_**`,`**_size_**`)`**
125+
126+
The function macro to allocate a memory block.
127+
The pointer to the instance of `pcc_ast_manager_t` that was passed to the API function `pcc_create()` can be retrieved from the argument _auxil_.
128+
It can be ignored if the instance does not concern memory allocation.
129+
The argument _size_ is the number of bytes to allocate.
130+
This macro must return a pointer to the allocated memory block, or `NULL` if no sufficient memory is available.
131+
132+
The default is defined as `PCC_MALLOC(mgr, size)`, which is used in the generated parser.
133+
134+
**`PCC_AST_REALLOC(`**_mgr_**`,`**_ptr_**`,`**_size_**`)`**
135+
136+
The function macro to reallocate the existing memory block.
137+
The pointer to the instance of `pcc_ast_manager_t` that was passed to the API function `pcc_create()` can be retrieved from the argument _auxil_.
138+
It can be ignored if the instance does not concern memory allocation.
139+
The argument _ptr_ is the pointer to the previously allocated memory block.
140+
The argument _size_ is the new number of bytes to reallocate.
141+
This macro must return a pointer to the reallocated memory block, or `NULL` if no sufficient memory is available.
142+
The contents of the memory block should be left unchanged in any case even if the reallocation fails.
143+
144+
The default is defined as `PCC_REALLOC(mgr, ptr, size)`, which is used in the generated parser.
145+
146+
**`PCC_AST_FREE(`**_mgr_**`,`**_ptr_**`)`**
147+
148+
The function macro to free the existing memory block.
149+
The pointer to the instance of `pcc_ast_manager_t` that was passed to the API function `pcc_create()` can be retrieved from the argument _auxil_.
150+
It can be ignored if the instance does not concern memory allocation.
151+
The argument _ptr_ is the pointer to the previously allocated memory block.
152+
This macro need not return a value.
153+
154+
The default is defined as `PCC_FREE(mgr, ptr)`, which is used in the generated parser.
155+
156+
**`PCC_AST_NODE_ARRAY_MIN_SIZE`**
157+
158+
The initial size (the number of nods) of the node arrays used in AST nodes.
159+
The arrays are expanded as needed.
160+
The default is `4`.
161+
117162
#### Example
118163
119164
An example which builds an AST and dumps it is shown here.

0 commit comments

Comments
 (0)