[Redbutton-devel] SF.net SVN: redbutton: [336] redbutton-author/trunk/ccc.y
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-08-23 11:53:33
|
Revision: 336
http://redbutton.svn.sourceforge.net/redbutton/?rev=336&view=rev
Author: skilvington
Date: 2007-08-23 04:12:14 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
output the yacc grammar for everthing expect [optional] items
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-23 10:03:26 UTC (rev 335)
+++ redbutton-author/trunk/ccc.y 2007-08-23 11:12:14 UTC (rev 336)
@@ -29,7 +29,7 @@
char *name;
};
-/* build up the separate parts of the ouput file in these buffers */
+/* build up the separate parts of the output file in these buffers */
struct buf
{
char *str; /* the buffer */
@@ -67,7 +67,7 @@
/* here we go ... */
void print_tokens(struct token *);
-void add_token(struct token **, char *);
+char *add_token(struct token **, char *);
char *unquote(char *);
void buf_init(struct buf *);
@@ -134,25 +134,54 @@
{
struct item *item;
struct item *next;
+ char *tok_name;
buf_append(&state.grammar, name);
- buf_append(&state.grammar, ":\n");
+ buf_append(&state.grammar, ":\n\t");
for(item=state.items; item; item=item->next)
{
switch(item->type)
{
case IT_LITERAL:
- add_token(&state.tokens, item->name);
+ tok_name = add_token(&state.tokens, item->name);
+ buf_append(&state.grammar, tok_name);
+ buf_append(&state.grammar, item->next ? " " : "\n\t");
break;
case IT_IDENTIFIER:
+ buf_append(&state.grammar, item->name);
+ /* do we need all the items, or just one of them */
+ if(state.and_items)
+ buf_append(&state.grammar, item->next ? " " : "\n\t");
+ else
+ buf_append(&state.grammar, item->next ? "\n\t|\n\t" : "\n\t");
break;
case IT_OPTIONAL:
+buf_append(&state.grammar, "[FIXME:");
+buf_append(&state.grammar, item->name);
+buf_append(&state.grammar, "] ");
break;
case IT_ONEORMORE:
+ /* add "IdentifierOneOrMore" to the grammar */
+ buf_append(&state.grammar, item->name);
+ buf_append(&state.grammar, "OneOrMore");
+ /* do we need all the items, or just one of them */
+ if(state.and_items)
+ buf_append(&state.grammar, item->next ? " " : "\n\t");
+ else
+ buf_append(&state.grammar, item->next ? "\n\t|\n\t" : "\n\t");
+ /* now create the IdentifierOneOrMore rule */
+ buf_append(&state.oneormores, item->name);
+ buf_append(&state.oneormores, "OneOrMore:\n\t");
+ buf_append(&state.oneormores, item->name);
+ buf_append(&state.oneormores, "\n\t|\n\t");
+ buf_append(&state.oneormores, item->name);
+ buf_append(&state.oneormores, "OneOrMore ");
+ buf_append(&state.oneormores, item->name);
+ buf_append(&state.oneormores, "\n\t;\n\n");
break;
default:
@@ -161,7 +190,7 @@
}
}
- buf_append(&state.grammar, "\t;\n\n");
+ buf_append(&state.grammar, ";\n\n");
/* free the items */
item = state.items;
@@ -189,7 +218,7 @@
return;
}
-void
+char *
add_token(struct token **head, char *quoted)
{
struct token *t = malloc(sizeof(struct token));
@@ -209,7 +238,7 @@
{
free(t->name);
free(t);
- return;
+ return list->name;
}
list = list->next;
}
@@ -227,7 +256,7 @@
list->next = t;
}
- return;
+ return t->name;
}
char *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|