Comment tweak

This commit is contained in:
2023-07-21 02:59:07 +10:00
parent b636ab9e31
commit 3782f2aaaa

View File

@@ -8,17 +8,17 @@ This header defines the parser structure which, after being initialized with a l
```c ```c
//generate bytecode from a given string //generate bytecode from a given string
const unsigned char* Toy_compileString(const char* source, size_t* size) { const unsigned char* Toy_compileString(const char* source, size_t* size) {
//declare the relevant instances //declare the relevant instances
Toy_Lexer lexer; Toy_Lexer lexer;
Toy_Parser parser; Toy_Parser parser;
Toy_Compiler compiler; Toy_Compiler compiler;
//initialize each of them //initialize each of them
Toy_initLexer(&lexer, source); Toy_initLexer(&lexer, source);
Toy_initParser(&parser, &lexer); Toy_initParser(&parser, &lexer);
Toy_initCompiler(&compiler); Toy_initCompiler(&compiler);
//when the parser returns NULL, it is finished //when the parser returns NULL, it is finished
Toy_ASTNode* node = Toy_scanParser(&parser); Toy_ASTNode* node = Toy_scanParser(&parser);
while(node != NULL) { while(node != NULL) {
//if the parser returns an error node, clean up and exit gracefully //if the parser returns an error node, clean up and exit gracefully
@@ -26,15 +26,15 @@ const unsigned char* Toy_compileString(const char* source, size_t* size) {
Toy_freeASTNode(node); Toy_freeASTNode(node);
Toy_freeCompiler(&compiler); Toy_freeCompiler(&compiler);
Toy_freeParser(&parser); Toy_freeParser(&parser);
//no need to clean the lexer //no need to clean the lexer
return NULL; return NULL;
} }
//write the node to the compiler //write the node to the compiler
Toy_writeCompiler(&compiler, node); Toy_writeCompiler(&compiler, node);
Toy_freeASTNode(node); Toy_freeASTNode(node);
//grab the next node //grab the next node
node = Toy_scanParser(&parser); node = Toy_scanParser(&parser);
} }