Use function pointer to make parser more clear.
When every parse function want to recursively call another parse function, buildTree() will be call first.
It makes parse function more clear and more readable.
Example:
void parse_PS() {
if(lookahead == NT) {
buildTree(&parse_P, "P");
buildTree(&parse_PS, "PS");
} else if(lookahead == EOF) {
} else {
syntaxError();
}
}
void buildTree(void (*parseFunc)(), char *id) {
addChild(id);
// Simulate a tree
enterTree();
(*parseFunc)();
leaveTree();
}
Source: https://github.com/xsoameix/LL-1-table-builder/blob/develop/app/Parser.c
Written by Lien Chiang
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Compiler
Authors
Related Tags
#compiler
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#