leandros / packcc Goto Github PK
View Code? Open in Web Editor NEWPackCC is a packrat parser generator for C.
Home Page: https://leandros.github.io/PackCC
License: MIT License
PackCC is a packrat parser generator for C.
Home Page: https://leandros.github.io/PackCC
License: MIT License
The generated parsers don't compile as C++, because of one call that implicitly casts from void*
to a concrete pointer. It's easy to fix by changing the type-cast from (void *)
to pcc_action_t)
:
diff --git a/src/packcc.c b/src/packcc.c
index dc6b8ed..a514fea 100644
--- a/src/packcc.c
+++ b/src/packcc.c
@@ -2561,7 +2561,7 @@ code_reach_t generate_thunking_action_code(
fputs("pcc_value_t null;\n", gen->stream);
}
write_characters(gen->stream, ' ', indent);
- fprintf(gen->stream, "pcc_thunk_t *thunk = pcc_thunk__create_leaf(ctx->auxil, (void *)pcc_action_%s_%d, %d, %d);\n",
+ fprintf(gen->stream, "pcc_thunk_t *thunk = pcc_thunk__create_leaf(ctx->auxil, (pcc_action_t)pcc_action_%s_%d, %d, %d);\n",
gen->rule->data.rule.name, index, gen->rule->data.rule.vars.len, gen->rule->data.rule.capts.len);
{
int i;
I've written a grammar but it's failing even on trivial inputs. I've boiled the grammar down to the following simple test case:
%prefix "test"
property <-
( IDENTIFIER '.' )? IDENTIFIER { printf("PROPERTY: %s\n", $0);}
IDENTIFIER <-
[a-zA-Z_] [a-zA-Z_0-9]*
%%
int main() {
test_context_t *ctx = test_create(NULL);
return test_parse(ctx, NULL);
}
This is able to parse input foo.bar
but fails on foo
:
$ packcc test.packcc && cc test.c -o test && echo "foo.bar" | ./test
PROPERTY: foo.bar
$ packcc test.packcc && cc test.c -o test && echo "foo" | ./test
Syntax error
It looks as though the parser is unable to recover from the failure to match the ( IDENTIFIER '.' )
rule. I suspect it isn't backtracking in the input, so when it hits the second IDENTIFIER
there's nothing left to parse.
Here's evidence in favor of that. If I change the property
rule to this:
property <-
( IDENTIFIER '.' )? ' ' IDENTIFIER
the parser will successfully parse the input foo bar
, which is incorrect. So it appears that it consumed the foo
, failed to match a .
, then went on without backtracking and matched the space and bar
.
This seems like a really elementary failure. Is this software considered stable or is it just an experiment? (I'm not trying to be sarcastic. I've put experimental stuff up on Github, there's nothing wrong with that. I just try to label it as such. I'm trying to use PackCC for a work project and don't want to waste more time trying to debug it if it's not ready...)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.