Skip to content

Commit 4722ec4

Browse files
committed
docs: add comments for some parser routines
1 parent 2cfff24 commit 4722ec4

3 files changed

Lines changed: 56 additions & 12 deletions

File tree

sources/compiler.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,19 +424,32 @@ int ParenthesesTest(UBYTE *sin)
424424
/*
425425
#] ParenthesesTest :
426426
#[ SkipAName :
427-
428-
Skips a name and gives a pointer to the object after the name.
429-
If there is not a proper name, it returns a zero pointer.
430-
In principle the brackets match already, so the `if ( *s == 0 )'
431-
code is not really needed, but you never know how the program
432-
is extended later.
433427
*/
434428

429+
/**
430+
* Skips a name and gives a pointer to the character after the name.
431+
* If there is not a proper name, it emits a compiler message and then returns
432+
* a null pointer.
433+
* This function supports formal names (e.g., `[x+a]`) and $-variables
434+
* in addition to ordinary identifiers.
435+
*
436+
* @note The brackets are assumed to be matched already.
437+
*
438+
* @param[in] s Pointer to a null-terminated input string that starts
439+
* with a name.
440+
* @return Pointer to the character after the name, or a null pointer
441+
* if the name is invalid.
442+
*/
435443
UBYTE *SkipAName(UBYTE *s)
436444
{
437445
UBYTE *t = s;
438446
if ( *s == '[' ) {
439447
SKIPBRA1(s)
448+
/*
449+
In principle the brackets match already, so the `if ( *s == 0 )'
450+
code is not really needed, but you never know how the program
451+
is extended later.
452+
*/
440453
if ( *s == 0 ) {
441454
MesPrint("&Illegal name: '%s'",t);
442455
return(0);

sources/ftypes.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ typedef int (*TFUN)();
187187
typedef int (*TFUN1)();
188188
#endif
189189

190+
/*
191+
Flags used in the compiler's KEYWORD tables.
192+
*/
190193

191194
#define NOAUTO 0
192-
#define PARTEST 1
193-
#define WITHAUTO 2
195+
#define PARTEST 1 /* parentheses test */
196+
#define WITHAUTO 2 /* auto-declaration */
194197

195198
#define ALLVARIABLES -1
196199
#define SYMBOLONLY 1

sources/tools.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,17 @@ UBYTE *strDup1(UBYTE *instring, char *ifwrong)
19181918
#[ EndOfToken :
19191919
*/
19201920

1921+
/**
1922+
* Skips over alphanumeric characters to find the end of the token.
1923+
*
1924+
* @note This function does not handle formal names (e.g., `[x+a]`).
1925+
* To handle them, use `SkipAName` instead.
1926+
*
1927+
* @param[in] s Pointer to a null-terminated input buffer.
1928+
* @return Pointer to the first non-alphanumeric character (i.e., the
1929+
* character immediately after the token), or the null
1930+
* terminator if the token reaches the end of the string.
1931+
*/
19211932
UBYTE *EndOfToken(UBYTE *s)
19221933
{
19231934
UBYTE c;
@@ -1930,6 +1941,17 @@ UBYTE *EndOfToken(UBYTE *s)
19301941
#[ ToToken :
19311942
*/
19321943

1944+
/**
1945+
* Skips over non-alphanumeric characters to find the start of a token.
1946+
*
1947+
* @note This function does not handle formal names (e.g., `[x+a]`).
1948+
* To handle them, consider simply skipping whitespace, e.g., by using
1949+
* `SkipSpaces`.
1950+
*
1951+
* @param[in] s Pointer to a null-terminated input buffer.
1952+
* @return Pointer to the first alphanumeric character (i.e., the start
1953+
* of the token), or the null terminator if none is found.
1954+
*/
19331955
UBYTE *ToToken(UBYTE *s)
19341956
{
19351957
UBYTE c;
@@ -1940,11 +1962,17 @@ UBYTE *ToToken(UBYTE *s)
19401962
/*
19411963
#] ToToken :
19421964
#[ SkipField :
1943-
1944-
Skips from s to the end of a declaration field.
1945-
par is the number of parentheses that still has to be closed.
19461965
*/
1947-
1966+
1967+
/**
1968+
* Skips from `s` to the end of a declaration field
1969+
* (e.g., `x`, `1+2*[x+a]`, or `f({x,[x+a]},1)`).
1970+
*
1971+
* @param[in] s Pointer to a null-terminated input buffer.
1972+
* @param[in] level Number of parentheses that still have to be closed.
1973+
* @return Pointer to the character after the field, which is either
1974+
* a comma at level 0 or the null terminator.
1975+
*/
19481976
UBYTE *SkipField(UBYTE *s, int level)
19491977
{
19501978
while ( *s ) {

0 commit comments

Comments
 (0)