[Redbutton-devel] SF.net SVN: redbutton: [358] redbutton-author/trunk/ccc.y
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-08-29 16:07:54
|
Revision: 358
http://redbutton.svn.sourceforge.net/redbutton/?rev=358&view=rev
Author: skilvington
Date: 2007-08-29 09:07:46 -0700 (Wed, 29 Aug 2007)
Log Message:
-----------
generate parser header file
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-29 15:09:30 UTC (rev 357)
+++ redbutton-author/trunk/ccc.y 2007-08-29 16:07:46 UTC (rev 358)
@@ -55,6 +55,8 @@
struct str_list *oneormores; /* grammar section for Identifier+ rules */
struct buf parse_fns; /* parse_Xxx() C functions for the parser */
struct buf is_fns; /* is_Xxx() C functions for the parser */
+ struct buf parse_hdr; /* parse_Xxx() prototypes for the parser */
+ struct buf is_hdr; /* is_Xxx() C prototypes for the parser */
} state;
int yyparse(void);
@@ -179,9 +181,10 @@
char *prog_name = argv[0];
bool show_lexer = false;
bool show_parser = false;
+ bool show_header = false;
int arg;
- while((arg = getopt(argc, argv, "lp")) != EOF)
+ while((arg = getopt(argc, argv, "lph")) != EOF)
{
switch(arg)
{
@@ -193,6 +196,10 @@
show_parser = true;
break;
+ case 'h':
+ show_header = true;
+ break;
+
default:
usage(prog_name);
break;
@@ -209,6 +216,8 @@
state.oneormores = NULL;
buf_init(&state.parse_fns);
buf_init(&state.is_fns);
+ buf_init(&state.parse_hdr);
+ buf_init(&state.is_hdr);
yyparse();
@@ -223,6 +232,12 @@
printf("%s", state.parse_fns.str);
printf("%s", state.is_fns.str);
}
+ else if(show_header)
+ {
+ /* output C header file */
+ printf("%s", state.parse_hdr.str);
+ printf("%s", state.is_hdr.str);
+ }
else
{
/* output grammar */
@@ -239,7 +254,7 @@
void
usage(char *prog_name)
{
- fprintf(stderr, "Syntax: %s [-l] [-p]\n", prog_name);
+ fprintf(stderr, "Syntax: %s [-l|-p|-h]\n", prog_name);
exit(EXIT_FAILURE);
}
@@ -298,6 +313,7 @@
buf_append(&state.grammar, ";\n\n");
/* C code for the parse_Xxx functions */
+ buf_append(&state.parse_hdr, "void parse_%s(struct state *);\n", name);
buf_append(&state.parse_fns, "void parse_%s(struct state *state)\n{\n", name);
/* count how many items make it up */
nitems = 0;
@@ -469,6 +485,7 @@
buf_append(&state.parse_fns, "}\n\n");
/* C code for the is_Xxx functions */
+ buf_append(&state.is_hdr, "bool is_%s(token_t);\n", name);
buf_append(&state.is_fns, "bool is_%s(token_t tok)\n{\n", name);
nitems = 0;
for(item=state.items; item; item=item->next)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|