[Redbutton-devel] SF.net SVN: redbutton: [344] redbutton-author/trunk/ccc.y
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-08-24 08:56:57
|
Revision: 344
http://redbutton.svn.sourceforge.net/redbutton/?rev=344&view=rev
Author: skilvington
Date: 2007-08-24 01:56:51 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
add -l flag to select lexer or grammar output
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-23 18:50:46 UTC (rev 343)
+++ redbutton-author/trunk/ccc.y 2007-08-24 08:56:51 UTC (rev 344)
@@ -1,4 +1,5 @@
%{
+#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
@@ -50,6 +51,9 @@
struct buf oneormores; /* grammar section for Identifier+ rules */
} state;
+void usage(char *);
+void fatal(char *);
+
void add_item(enum item_type, char *);
void output_def(char *);
@@ -158,8 +162,28 @@
/* here we go ... */
int
-main(void)
+main(int argc, char *argv[])
{
+ char *prog_name = argv[0];
+ /* by default output the grammar */
+ bool show_lexer = false;
+ int arg;
+
+ while((arg = getopt(argc, argv, "l")) != EOF)
+ {
+ switch(arg)
+ {
+ case 'l':
+ show_lexer = true;
+ break;
+
+ default:
+ usage(prog_name);
+ break;
+ }
+ }
+
+ if(optind == argc)
state.items = NULL;
buf_init(&state.lexer);
state.tokens = NULL;
@@ -168,20 +192,33 @@
yyparse();
- printf("-- lex --\n");
- printf("%s", state.lexer.str);
+ if(show_lexer)
+ {
+ /* output lexer */
+ printf("%s", state.lexer.str);
+ }
+ else
+ {
+ /* output grammar */
+ print_tokens(state.tokens);
+ printf("%%%%\n");
+ printf("%s", state.grammar.str);
+ printf("%s", state.oneormores.str);
+ printf("%%%%\n");
+ }
- printf("-- yacc --\n");
- print_tokens(state.tokens);
- printf("%%%%\n");
- printf("%s", state.grammar.str);
- printf("%s", state.oneormores.str);
- printf("%%%%\n");
-
return EXIT_SUCCESS;
}
void
+usage(char *prog_name)
+{
+ fprintf(stderr, "Syntax: %s [-l]\n", prog_name);
+
+ exit(EXIT_FAILURE);
+}
+
+void
fatal(char *str)
{
yyerror(str);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|