redbutton-devel Mailing List for RedButton MHEG Engine (Page 12)
Brought to you by:
skilvington
You can subscribe to this list here.
| 2006 |
Jan
(1) |
Feb
(4) |
Mar
(27) |
Apr
(6) |
May
(46) |
Jun
(45) |
Jul
(7) |
Aug
(4) |
Sep
(7) |
Oct
(5) |
Nov
(10) |
Dec
(11) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(49) |
Feb
(29) |
Mar
(35) |
Apr
(43) |
May
(23) |
Jun
(4) |
Jul
(1) |
Aug
(58) |
Sep
(66) |
Oct
(27) |
Nov
(15) |
Dec
(1) |
| 2008 |
Jan
(11) |
Feb
|
Mar
(8) |
Apr
|
May
|
Jun
(30) |
Jul
(1) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
(3) |
Dec
(6) |
| 2009 |
Jan
(6) |
Feb
(1) |
Mar
(2) |
Apr
(5) |
May
(2) |
Jun
(1) |
Jul
(7) |
Aug
|
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(6) |
| 2010 |
Jan
(6) |
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(6) |
Sep
(4) |
Oct
|
Nov
(11) |
Dec
(4) |
| 2011 |
Jan
|
Feb
(11) |
Mar
(8) |
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
(2) |
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <ski...@us...> - 2007-08-30 16:29:31
|
Revision: 361
http://redbutton.svn.sourceforge.net/redbutton/?rev=361&view=rev
Author: skilvington
Date: 2007-08-30 09:29:28 -0700 (Thu, 30 Aug 2007)
Log Message:
-----------
use the token names
Modified Paths:
--------------
redbutton-author/trunk/parser.h.footer
Modified: redbutton-author/trunk/parser.h.footer
===================================================================
--- redbutton-author/trunk/parser.h.footer 2007-08-30 16:16:25 UTC (rev 360)
+++ redbutton-author/trunk/parser.h.footer 2007-08-30 16:29:28 UTC (rev 361)
@@ -1,10 +1,10 @@
-#define is_INVALID(TOK) (TOK == 1)
-#define is_INTEGER(TOK) (TOK == 2)
-#define is_BOOLEAN(TOK) (TOK == 3)
-#define is_STRING(TOK) (TOK == 4)
-#define is_QPRINTABLE(TOK) (TOK == 5)
-#define is_BASE64(TOK) (TOK == 6)
-#define is_Null(TOK) (TOK == 7)
+#define is_INVALID(TOK) (TOK == INVALID)
+#define is_INTEGER(TOK) (TOK == INTEGER)
+#define is_BOOLEAN(TOK) (TOK == BOOLEAN)
+#define is_STRING(TOK) (TOK == STRING)
+#define is_QPRINTABLE(TOK) (TOK == QPRINTABLE)
+#define is_BASE64(TOK) (TOK == BASE64)
+#define is_Null(TOK) (TOK == Null)
#endif /* __NEW_PARSER_H__ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-30 16:16:32
|
Revision: 360
http://redbutton.svn.sourceforge.net/redbutton/?rev=360&view=rev
Author: skilvington
Date: 2007-08-30 09:16:25 -0700 (Thu, 30 Aug 2007)
Log Message:
-----------
generate C code for a parser rather than a yacc grammar
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-author/trunk/ccc.y
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/parser.l.footer
redbutton-author/trunk/parser.l.header
Added Paths:
-----------
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.footer
redbutton-author/trunk/parser.h.header
redbutton-author/trunk/tokens.h.header
Removed Paths:
-------------
redbutton-author/trunk/parser.y.footer
redbutton-author/trunk/parser.y.header
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-08-30 08:30:55 UTC (rev 359)
+++ redbutton-author/trunk/Makefile 2007-08-30 16:16:25 UTC (rev 360)
@@ -10,40 +10,25 @@
OBJS= mhegc.o \
lex.parser.o \
- parser.tab.o \
+ parser.o \
utils.o
TARDIR=`basename ${PWD}`
-mhegc: ${OBJS}
+mhegc: parser.h ${OBJS}
${CC} ${CFLAGS} -o mhegc ${OBJS} ${LIBS}
-mhegc.o: mhegc.c parser.tab.h
- ${CC} ${CFLAGS} -c mhegc.c
-
-parser.tab.h: parser.tab.c
-
ccc: ccc.y ccc.l asn1type.o
${LEX} -i -t ccc.l > lex.ccc.c
${YACC} -b ccc -d ccc.y
${CC} ${CFLAGS} -o ccc lex.ccc.c ccc.tab.c asn1type.o
-parser.l: parser.l.header parser.l.footer grammar ccc
- cat parser.l.header > parser.l
- cat grammar | ./ccc -l >> parser.l
- cat parser.l.footer >> parser.l
-
-parser.y: parser.y.header parser.y.footer grammar ccc
- cat parser.y.header > parser.y
- cat grammar | ./ccc >> parser.y
- cat parser.y.footer >> parser.y
-
-lex.parser.c: parser.l
+lex.parser.o parser.o parser.h: parser.l.* parser.c.* parser.h.* tokens.h.* grammar ccc
+ cat grammar | ./ccc -l parser.l -p parser.c -h parser.h -t tokens.h
${LEX} -i -t parser.l > lex.parser.c
+ ${CC} ${CFLAGS} -c lex.parser.c
+ ${CC} ${CFLAGS} -c parser.c
-parser.tab.c: parser.y
- ${YACC} -b parser -d parser.y
-
.c.o:
${CC} ${CFLAGS} -c $<
@@ -51,7 +36,7 @@
install -m 755 mhegc ${DESTDIR}/bin
clean:
- rm -f mhegc ccc lex.*.c *.tab.[ch] parser.l parser.y *.o core
+ rm -f mhegc ccc lex.ccc.c ccc.tab.[ch] lex.parser.c parser.[lch] tokens.h *.o core
tar:
make clean
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-30 08:30:55 UTC (rev 359)
+++ redbutton-author/trunk/ccc.y 2007-08-30 16:16:25 UTC (rev 360)
@@ -7,6 +7,8 @@
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
+#include <limits.h>
+#include <errno.h>
#include "asn1type.h"
@@ -51,14 +53,15 @@
bool and_items; /* true => identifier must contain all items */
struct buf lexer; /* lex output file */
struct str_list *tokens; /* "%token" section of the yacc output file */
- struct buf grammar; /* grammar section of the yacc output file */
- 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;
+/* header for files we generate */
+#define STANDARD_HEADER "/*\n * This file was automatically generated. Do not Edit!\n */\n\n"
+
int yyparse(void);
int yylex(void);
@@ -68,18 +71,17 @@
void add_item(enum item_type, char *);
void output_def(char *);
-void output_item(struct item *, bool);
void print_tokens(struct str_list *);
char *add_token(struct str_list **, char *);
char *unquote(char *);
-void print_oneormores(struct str_list *);
-void add_oneormore(struct str_list **, char *);
-
void buf_init(struct buf *);
void buf_append(struct buf *, char *, ...);
+FILE *safe_fopen(char *, char *);
+void file_append(FILE *, char *);
+
/* input line we are currently parsing */
int yylineno = 1;
@@ -179,28 +181,35 @@
main(int argc, char *argv[])
{
char *prog_name = argv[0];
- bool show_lexer = false;
- bool show_parser = false;
- bool show_header = false;
+ char *lexer_name = NULL;
+ char *parser_name = NULL;
+ char *header_name = NULL;
+ char *tokens_name = NULL;
int arg;
struct str_list *t;
+ char header[PATH_MAX];
+ char footer[PATH_MAX];
- while((arg = getopt(argc, argv, "lph")) != EOF)
+ while((arg = getopt(argc, argv, "l:p:h:t:")) != EOF)
{
switch(arg)
{
case 'l':
- show_lexer = true;
+ lexer_name = optarg;
break;
case 'p':
- show_parser = true;
+ parser_name = optarg;
break;
case 'h':
- show_header = true;
+ header_name = optarg;
break;
+ case 't':
+ tokens_name = optarg;
+ break;
+
default:
usage(prog_name);
break;
@@ -213,8 +222,6 @@
state.items = NULL;
buf_init(&state.lexer);
state.tokens = NULL;
- buf_init(&state.grammar);
- state.oneormores = NULL;
buf_init(&state.parse_fns);
buf_init(&state.is_fns);
buf_init(&state.parse_hdr);
@@ -222,43 +229,98 @@
yyparse();
- if(show_lexer)
+
+ /*
+ * add parse_Xxx functions for the tokens
+ * #define is_Xxx functions for the tokens
+ */
+ for(t=state.tokens; t; t=t->next)
{
- /* output lexer */
- printf("%s", state.lexer.str);
+ buf_append(&state.parse_fns, "void parse_%s(struct state *state)\n{\n", t->name);
+buf_append(&state.parse_fns, "// TODO\n");
+ buf_append(&state.parse_fns, "}\n\n", t->name);
+ /* parse_Xxx prototype */
+ buf_append(&state.parse_hdr, "void parse_%s(struct state *);\n", t->name);
+ /* #define is_Xxx function */
+ buf_append(&state.is_hdr, "#define is_%s(TOK)\t(TOK == %s)\n", t->name, t->name);
}
- else if(show_parser)
+
+ /* output lexer */
+ if(lexer_name != NULL)
{
- /* output C code */
- printf("%s", state.parse_fns.str);
- printf("%s", state.is_fns.str);
+ FILE *lexer_file = safe_fopen(lexer_name, "w");
+ fprintf(lexer_file, STANDARD_HEADER);
+ /* output the header if there is one */
+ snprintf(header, sizeof(header), "%s.header", lexer_name);
+ file_append(lexer_file, header);
+ /* output our stuff */
+ fprintf(lexer_file, "%s", state.lexer.str);
+ /* output the footer if there is one */
+ snprintf(footer, sizeof(footer), "%s.footer", lexer_name);
+ file_append(lexer_file, footer);
+ fclose(lexer_file);
}
- else if(show_header)
+
+ /* output parser C code */
+ if(parser_name != NULL)
{
- /* output C header file */
- printf("%s", state.parse_hdr.str);
- printf("%s", state.is_hdr.str);
- /* add is_Xxx functions for the tokens */
- for(t=state.tokens; t; t=t->next)
- printf("#define is_%s(TOK)\t(TOK == %s)\n", t->name, t->name);
+ FILE *parser_file = safe_fopen(parser_name, "w");
+ fprintf(parser_file, STANDARD_HEADER);
+ /* output the header if there is one */
+ snprintf(header, sizeof(header), "%s.header", parser_name);
+ file_append(parser_file, header);
+ /* output our stuff */
+ fprintf(parser_file, "%s", state.parse_fns.str);
+ fprintf(parser_file, "%s", state.is_fns.str);
+ /* output the footer if there is one */
+ snprintf(footer, sizeof(footer), "%s.footer", parser_name);
+ file_append(parser_file, footer);
+ fclose(parser_file);
}
- else
+
+ /* output parser header file */
+ if(header_name != NULL)
{
- /* output grammar */
- print_tokens(state.tokens);
- printf("%%%%\n");
- printf("%s", state.grammar.str);
- print_oneormores(state.oneormores);
- printf("%%%%\n");
+ FILE *header_file = safe_fopen(header_name, "w");
+ fprintf(header_file, STANDARD_HEADER);
+ /* output the header if there is one */
+ snprintf(header, sizeof(header), "%s.header", header_name);
+ file_append(header_file, header);
+ /* output our stuff */
+ fprintf(header_file, "%s", state.parse_hdr.str);
+ fprintf(header_file, "%s", state.is_hdr.str);
+ /* output the footer if there is one */
+ snprintf(footer, sizeof(footer), "%s.footer", header_name);
+ file_append(header_file, footer);
+ fclose(header_file);
}
+ /* output a header file defining the tokens for the lexer */
+ if(tokens_name != NULL)
+ {
+ unsigned int tok_val;
+ FILE *tokens_file = safe_fopen(tokens_name, "w");
+ fprintf(tokens_file, STANDARD_HEADER);
+ /* output the header if there is one */
+ snprintf(header, sizeof(header), "%s.header", tokens_name);
+ file_append(tokens_file, header);
+ /* output our stuff */
+ tok_val = 256;
+ for(t=state.tokens; t; t=t->next)
+ fprintf(tokens_file, "#define %s\t%u\n", t->name, tok_val++);
+ /* output the footer if there is one */
+ snprintf(footer, sizeof(footer), "%s.footer", tokens_name);
+ file_append(tokens_file, footer);
+ fclose(tokens_file);
+ }
+
return EXIT_SUCCESS;
}
void
usage(char *prog_name)
{
- fprintf(stderr, "Syntax: %s [-l|-p|-h]\n", prog_name);
+ fprintf(stderr, "Syntax: %s [-l <lexer-file>] [-p <parser-c-file>] [-h <parser-h-file>] [-t <tokens-file>]\n", prog_name);
exit(EXIT_FAILURE);
}
@@ -298,6 +360,10 @@
new_item->type = type;
new_item->include = true;
+ /* if it is a literal, make a token for it */
+ if(new_item->type == IT_LITERAL)
+ add_token(&state.tokens, new_item->name);
+
return;
}
@@ -308,14 +374,6 @@
struct item *next;
unsigned int nitems;
- buf_append(&state.grammar, "%s:\n\t", name);
-
- /* output each item that makes up this identifier */
- for(item=state.items; item; item=item->next)
- output_item(item, true);
-
- 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);
@@ -573,74 +631,6 @@
}
void
-output_item(struct item *item, bool recurse)
-{
- char *tok_name;
- struct item *rest;
-
- switch(item->type)
- {
- case IT_LITERAL:
- tok_name = add_token(&state.tokens, item->name);
- buf_append(&state.grammar, tok_name);
- break;
-
- case IT_IDENTIFIER:
- buf_append(&state.grammar, item->name);
- break;
-
- case IT_OPTIONAL:
- if(recurse)
- {
- /*
- * we are an optional item,
- * so first output the remaining items
- * this creates a rule which does not including us
- */
- item->include = false;
- for(rest=item->next; rest; rest=rest->next)
- output_item(rest, true);
- /* or it with a rule which does contain us */
- if(item->next == NULL)
- buf_append(&state.grammar, "\n\t");
- buf_append(&state.grammar, "|\n\t");
- /*
- * now output the items before us and output ourself,
- * this constructs a rule including us
- */
- item->include = true;
- for(rest=state.items; rest!=item; rest=rest->next)
- output_item(rest, false);
- buf_append(&state.grammar, item->name);
- }
- else if(item->include)
- {
- buf_append(&state.grammar, item->name);
- }
- break;
-
- case IT_ONEORMORE:
- /* add "OneOrMoreIdentifier" to the grammar */
- buf_append(&state.grammar, "OneOrMore%s", item->name);
- /* add the OneOrMoreIdentifier to our list */
- add_oneormore(&state.oneormores, item->name);
- break;
-
- default:
- fatal("Unexpected item type");
- break;
- }
-
- /* do we need all the items, or just one of them */
- if(state.and_items)
- buf_append(&state.grammar, item->next ? (item->include ? " " : "") : "\n\t");
- else
- buf_append(&state.grammar, item->next ? "\n\t|\n\t" : "\n\t");
-
- return;
-}
-
-void
print_tokens(struct str_list *t)
{
while(t)
@@ -751,47 +741,6 @@
return output;
}
-void
-print_oneormores(struct str_list *list)
-{
- while(list)
- {
- /* output the OneOrMoreIdentifier rule */
- printf("OneOrMore%s:\n", list->name);
- printf("\t%s\n", list->name);
- printf("\t|\n");
- printf("\tOneOrMore%s %s\n", list->name, list->name);
- printf("\t;\n\n");
- list = list->next;
- }
-
- return;
-}
-
-void
-add_oneormore(struct str_list **head, char *name)
-{
- struct str_list *list;
-
- /* check we haven't got it already */
- for(list=*head; list; list=list->next)
- {
- if(strcmp(list->name, name) == 0)
- return;
- }
-
- /* take a copy of the string */
- if((list = malloc(sizeof(struct str_list))) == NULL
- || (list->name = strdup(name)) == NULL)
- fatal("Out of memory");
-
- /* add it to the head of the list */
- list->next = *head;
- *head = list;
-
- return;
-}
-
#define INIT_BUF_SIZE 1024
void
@@ -834,4 +783,47 @@
return;
}
+FILE *
+safe_fopen(char *path, char *mode)
+{
+ FILE *f;
+ if((f = fopen(path, mode)) == NULL)
+ {
+ fprintf(stderr, "Unable to open %s: %s\n", path, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ return f;
+}
+
+void
+file_append(FILE *out, char *path)
+{
+ FILE *append = fopen(path, "r");
+ char buf[BUFSIZ];
+ size_t nread;
+
+ /* don't care if the file does not exist */
+ if(append == NULL)
+ {
+ if(errno == ENOENT)
+ return;
+ fprintf(stderr, "Unable to read %s: %s\n", path, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ /* we are using stdio, so copy in BUFSIZ blocks */
+ while(!feof(append))
+ {
+ nread = fread(buf, 1, sizeof(buf), append);
+ if(fwrite(buf, 1, nread, out) != nread)
+ {
+ fprintf(stderr, "Unable to append %s: %s", path, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ return;
+}
+
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-08-30 08:30:55 UTC (rev 359)
+++ redbutton-author/trunk/mhegc.c 2007-08-30 16:16:25 UTC (rev 360)
@@ -23,17 +23,15 @@
#include <stdio.h>
#include <stdlib.h>
-#include "parser.tab.h"
+#include "parser.h"
-int yyparse(void);
-extern int yydebug;
-
int
main(int argc, char *argv[])
{
- yydebug=1;
- yyparse();
+ struct state state;
+ parse_InterchangedObject(&state);
+
return EXIT_SUCCESS;
}
Added: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header (rev 0)
+++ redbutton-author/trunk/parser.c.header 2007-08-30 16:16:25 UTC (rev 360)
@@ -0,0 +1,53 @@
+#include <stdio.h>
+
+#include "parser.h"
+#include "tokens.h"
+
+int yylineno = 1;
+
+int yylex(void);
+
+void
+yyerror(const char *str)
+{
+ fprintf(stderr, "Error: %s at line %d\n", str, yylineno);
+}
+
+int
+yywrap(void)
+{
+ return 1;
+}
+
+/*
+ * parser functions for the predefined types
+ */
+
+void parse_INTEGER(struct state *state)
+{
+}
+
+void parse_BOOLEAN(struct state *state)
+{
+}
+
+
+void parse_STRING(struct state *state)
+{
+}
+
+
+void parse_QPRINTABLE(struct state *state)
+{
+}
+
+
+void parse_BASE64(struct state *state)
+{
+}
+
+
+void parse_Null(struct state *state)
+{
+}
+
Added: redbutton-author/trunk/parser.h.footer
===================================================================
--- redbutton-author/trunk/parser.h.footer (rev 0)
+++ redbutton-author/trunk/parser.h.footer 2007-08-30 16:16:25 UTC (rev 360)
@@ -0,0 +1,10 @@
+#define is_INVALID(TOK) (TOK == 1)
+#define is_INTEGER(TOK) (TOK == 2)
+#define is_BOOLEAN(TOK) (TOK == 3)
+#define is_STRING(TOK) (TOK == 4)
+#define is_QPRINTABLE(TOK) (TOK == 5)
+#define is_BASE64(TOK) (TOK == 6)
+#define is_Null(TOK) (TOK == 7)
+
+#endif /* __NEW_PARSER_H__ */
+
Added: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header (rev 0)
+++ redbutton-author/trunk/parser.h.header 2007-08-30 16:16:25 UTC (rev 360)
@@ -0,0 +1,8 @@
+#ifndef __NEW_PARSER_H__
+#define __NEW_PARSER_H__
+
+#include <stdbool.h>
+
+struct state { int dummy; };
+typedef int token_t;
+
Modified: redbutton-author/trunk/parser.l.footer
===================================================================
--- redbutton-author/trunk/parser.l.footer 2007-08-30 08:30:55 UTC (rev 359)
+++ redbutton-author/trunk/parser.l.footer 2007-08-30 16:16:25 UTC (rev 360)
@@ -1,2 +1,21 @@
. return INVALID;
%%
+
+/* don't use #define in case they are macros too */
+token_t
+next_token(void)
+{
+ return yylex();
+}
+
+void
+unget_token(token_t tok)
+{
+ unput(tok);
+}
+
+void
+parse_error(char *err)
+{
+ yyerror(err);
+}
Modified: redbutton-author/trunk/parser.l.header
===================================================================
--- redbutton-author/trunk/parser.l.header 2007-08-30 08:30:55 UTC (rev 359)
+++ redbutton-author/trunk/parser.l.header 2007-08-30 16:16:25 UTC (rev 360)
@@ -1,15 +1,14 @@
%{
-#include <string.h>
-#define YYSTYPE char *
-#include "parser.tab.h"
+#include "parser.h"
+#include "tokens.h"
extern int yylineno;
%}
%%
-([-0-9][0-9]*)|(0x[0-9a-f]+) yylval = strdup(yytext); return INTEGER;
-true|false yylval = strdup(yytext); return BOOLEAN;
-\"((\\\")|[^"])*\" yylval = strdup(yytext); return STRING;
-'[^']*' yylval = strdup(yytext); return QPRINTABLE;
-`[^`]*` yylval = strdup(yytext); return BASE64;
+([-0-9][0-9]*)|(0x[0-9a-f]+) return INTEGER;
+true|false return BOOLEAN;
+\"((\\\")|[^"])*\" return STRING;
+'[^']*' return QPRINTABLE;
+`[^`]*` return BASE64;
null return Null;
[\n\r\f] yylineno ++;
[ \t]+ /* ignore whitespace */
Deleted: redbutton-author/trunk/parser.y.footer
===================================================================
--- redbutton-author/trunk/parser.y.footer 2007-08-30 08:30:55 UTC (rev 359)
+++ redbutton-author/trunk/parser.y.footer 2007-08-30 16:16:25 UTC (rev 360)
@@ -1 +0,0 @@
-
Deleted: redbutton-author/trunk/parser.y.header
===================================================================
--- redbutton-author/trunk/parser.y.header 2007-08-30 08:30:55 UTC (rev 359)
+++ redbutton-author/trunk/parser.y.header 2007-08-30 16:16:25 UTC (rev 360)
@@ -1,33 +0,0 @@
-%{
-#include <stdio.h>
-#include <string.h>
-
-#define YYSTYPE char *
-#define YYERROR_VERBOSE
-#define YYDEBUG 1
-
-int yylex(void);
-
-int yylineno = 1;
-
-void
-yyerror(const char *str)
-{
- fprintf(stderr, "Error: %s at line %d\n", str, yylineno);
-}
-
-int
-yywrap(void)
-{
- return 1;
-}
-
-%}
-
-%token INTEGER
-%token BOOLEAN
-%token STRING
-%token QPRINTABLE
-%token BASE64
-%token Null
-%token INVALID
Added: redbutton-author/trunk/tokens.h.header
===================================================================
--- redbutton-author/trunk/tokens.h.header (rev 0)
+++ redbutton-author/trunk/tokens.h.header 2007-08-30 16:16:25 UTC (rev 360)
@@ -0,0 +1,7 @@
+#define INVALID 1
+#define INTEGER 2
+#define BOOLEAN 3
+#define STRING 4
+#define QPRINTABLE 5
+#define BASE64 6
+#define Null 7
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-30 08:31:08
|
Revision: 359
http://redbutton.svn.sourceforge.net/redbutton/?rev=359&view=rev
Author: skilvington
Date: 2007-08-30 01:30:55 -0700 (Thu, 30 Aug 2007)
Log Message:
-----------
generate is_Xxx functions for the tokens
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-29 16:07:46 UTC (rev 358)
+++ redbutton-author/trunk/ccc.y 2007-08-30 08:30:55 UTC (rev 359)
@@ -183,6 +183,7 @@
bool show_parser = false;
bool show_header = false;
int arg;
+ struct str_list *t;
while((arg = getopt(argc, argv, "lph")) != EOF)
{
@@ -237,6 +238,9 @@
/* output C header file */
printf("%s", state.parse_hdr.str);
printf("%s", state.is_hdr.str);
+ /* add is_Xxx functions for the tokens */
+ for(t=state.tokens; t; t=t->next)
+ printf("#define is_%s(TOK)\t(TOK == %s)\n", t->name, t->name);
}
else
{
@@ -498,7 +502,7 @@
if(item->type == IT_LITERAL)
{
char *tok_name = unquote(item->name);
- buf_append(&state.is_fns, "\treturn (tok == %s);\n", tok_name);
+ buf_append(&state.is_fns, "\treturn is_%s(tok);\n", tok_name);
free(tok_name);
}
else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <ski...@us...> - 2007-08-29 15:09:35
|
Revision: 357
http://redbutton.svn.sourceforge.net/redbutton/?rev=357&view=rev
Author: skilvington
Date: 2007-08-29 08:09:30 -0700 (Wed, 29 Aug 2007)
Log Message:
-----------
generate is_Xxx() parser functions
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-28 20:41:58 UTC (rev 356)
+++ redbutton-author/trunk/ccc.y 2007-08-29 15:09:30 UTC (rev 357)
@@ -297,7 +297,7 @@
buf_append(&state.grammar, ";\n\n");
- /* C code for the parser */
+ /* C code for the parse_Xxx functions */
buf_append(&state.parse_fns, "void parse_%s(struct state *state)\n{\n", name);
/* count how many items make it up */
nitems = 0;
@@ -466,8 +466,77 @@
break;
}
}
- buf_append(&state.parse_fns, "}\n\n", name);
+ buf_append(&state.parse_fns, "}\n\n");
+ /* C code for the is_Xxx functions */
+ buf_append(&state.is_fns, "bool is_%s(token_t tok)\n{\n", name);
+ nitems = 0;
+ for(item=state.items; item; item=item->next)
+ nitems ++;
+ if(nitems == 1
+ || state.items->type == IT_LITERAL)
+ {
+ /* check if the first item matches the token */
+ item = state.items;
+ if(item->type == IT_LITERAL)
+ {
+ char *tok_name = unquote(item->name);
+ buf_append(&state.is_fns, "\treturn (tok == %s);\n", tok_name);
+ free(tok_name);
+ }
+ else
+ {
+ buf_append(&state.is_fns, "\treturn is_%s(tok);\n", item->name);
+ }
+ }
+ else
+ {
+ switch(asn1type(name))
+ {
+ case ASN1TYPE_CHOICE:
+ case ASN1TYPE_ENUMERATED:
+ case ASN1TYPE_SET:
+ /* check if any of the items match the token */
+ buf_append(&state.is_fns, "\treturn ");
+ for(item=state.items; item; item=item->next)
+ {
+ if(item->type != IT_IDENTIFIER && item->type != IT_OPTIONAL)
+ fatal("is_fns: expecting Identifier or [Identifier]");
+ buf_append(&state.is_fns, "is_%s(tok)", item->name);
+ /* is it the last one */
+ if(item->next)
+ buf_append(&state.is_fns, "\n\t || ");
+ else
+ buf_append(&state.is_fns, ";\n");
+ }
+ break;
+
+ case ASN1TYPE_SEQUENCE:
+ /* check if the first item matches the token */
+ item = state.items;
+ if(item->type == IT_LITERAL)
+ {
+ char *tok_name = unquote(item->name);
+ buf_append(&state.is_fns, "\treturn (tok == %s);\n", tok_name);
+ free(tok_name);
+ }
+ else if(item->type == IT_IDENTIFIER)
+ {
+ buf_append(&state.is_fns, "\treturn is_%s(tok);\n", item->name);
+ }
+ else
+ {
+ fatal("SEQUENCE but first item not Literal or Identifier");
+ }
+ break;
+
+ default:
+ fatal("Illegal ASN1TYPE");
+ break;
+ }
+ }
+ buf_append(&state.is_fns, "}\n\n");
+
/* free the items */
item = state.items;
while(item)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-28 20:42:03
|
Revision: 356
http://redbutton.svn.sourceforge.net/redbutton/?rev=356&view=rev
Author: skilvington
Date: 2007-08-28 13:41:58 -0700 (Tue, 28 Aug 2007)
Log Message:
-----------
get ready to generate the is_Xxx() functions
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-28 20:37:47 UTC (rev 355)
+++ redbutton-author/trunk/ccc.y 2007-08-28 20:41:58 UTC (rev 356)
@@ -53,7 +53,8 @@
struct str_list *tokens; /* "%token" section of the yacc output file */
struct buf grammar; /* grammar section of the yacc output file */
struct str_list *oneormores; /* grammar section for Identifier+ rules */
- struct buf parser; /* C code for the parser */
+ struct buf parse_fns; /* parse_Xxx() C functions for the parser */
+ struct buf is_fns; /* is_Xxx() C functions for the parser */
} state;
int yyparse(void);
@@ -206,7 +207,8 @@
state.tokens = NULL;
buf_init(&state.grammar);
state.oneormores = NULL;
- buf_init(&state.parser);
+ buf_init(&state.parse_fns);
+ buf_init(&state.is_fns);
yyparse();
@@ -218,7 +220,8 @@
else if(show_parser)
{
/* output C code */
- printf("%s", state.parser.str);
+ printf("%s", state.parse_fns.str);
+ printf("%s", state.is_fns.str);
}
else
{
@@ -295,7 +298,7 @@
buf_append(&state.grammar, ";\n\n");
/* C code for the parser */
- buf_append(&state.parser, "void parse_%s(struct state *state)\n{\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;
/* skip literals at the start */
@@ -313,33 +316,33 @@
item = state.items;
while(item && item->type == IT_LITERAL)
{
-buf_append(&state.parser, "// TODO: eat %s\n\n", item->name);
+buf_append(&state.parse_fns, "// TODO: eat %s\n\n", item->name);
item = item->next;
}
- buf_append(&state.parser, "\ttoken_t next = next_token();\n\n");
+ buf_append(&state.parse_fns, "\ttoken_t next = next_token();\n\n");
if(item->type == IT_IDENTIFIER)
{
- buf_append(&state.parser, "\t/* %s */\n", item->name);
- buf_append(&state.parser, "\tif(is_%s(next))\n", item->name);
- buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
- buf_append(&state.parser, "\telse\n");
- buf_append(&state.parser, "\t\tparse_error(\"Expecting %s\");\n", item->name);
+ buf_append(&state.parse_fns, "\t/* %s */\n", item->name);
+ buf_append(&state.parse_fns, "\tif(is_%s(next))\n", item->name);
+ buf_append(&state.parse_fns, "\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parse_fns, "\telse\n");
+ buf_append(&state.parse_fns, "\t\tparse_error(\"Expecting %s\");\n", item->name);
}
else if(item->type == IT_OPTIONAL)
{
- buf_append(&state.parser, "\t/* [%s] */\n", item->name);
- buf_append(&state.parser, "\tif(is_%s(next))\n", item->name);
- buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parse_fns, "\t/* [%s] */\n", item->name);
+ buf_append(&state.parse_fns, "\tif(is_%s(next))\n", item->name);
+ buf_append(&state.parse_fns, "\t\tparse_%s(state);\n", item->name);
}
else if(item->type == IT_ONEORMORE)
{
- buf_append(&state.parser, "\t/* %s+ */\n", item->name);
- buf_append(&state.parser, "\twhile(is_%s(next))\n", item->name);
- buf_append(&state.parser, "\t{\n");
- buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
- buf_append(&state.parser, "\t\tnext = next_token();\n");
- buf_append(&state.parser, "\t}\n");
- buf_append(&state.parser, "\n\tunget_token(next);\n");
+ buf_append(&state.parse_fns, "\t/* %s+ */\n", item->name);
+ buf_append(&state.parse_fns, "\twhile(is_%s(next))\n", item->name);
+ buf_append(&state.parse_fns, "\t{\n");
+ buf_append(&state.parse_fns, "\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parse_fns, "\t\tnext = next_token();\n");
+ buf_append(&state.parse_fns, "\t}\n");
+ buf_append(&state.parse_fns, "\n\tunget_token(next);\n");
}
else
{
@@ -348,7 +351,7 @@
item = item->next;
while(item)
{
-buf_append(&state.parser, "\n// TODO: eat %s\n", item->name);
+buf_append(&state.parse_fns, "\n// TODO: eat %s\n", item->name);
item = item->next;
}
}
@@ -361,26 +364,26 @@
/* assert */
if(state.and_items)
fatal("CHOICE or ENUMERATED type, but and_items set");
- buf_append(&state.parser, "\ttoken_t next = next_token();\n\n");
- buf_append(&state.parser, "\t/* CHOICE or ENUMERATED */\n");
+ buf_append(&state.parse_fns, "\ttoken_t next = next_token();\n\n");
+ buf_append(&state.parse_fns, "\t/* CHOICE or ENUMERATED */\n");
item = state.items;
for(item=state.items; item; item=item->next)
{
/* is it the first */
if(item == state.items)
- buf_append(&state.parser, "\t");
+ buf_append(&state.parse_fns, "\t");
else
- buf_append(&state.parser, "\telse ");
+ buf_append(&state.parse_fns, "\telse ");
if(item->type == IT_IDENTIFIER)
{
- buf_append(&state.parser, "if(is_%s(next))\n", item->name);
- buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parse_fns, "if(is_%s(next))\n", item->name);
+ buf_append(&state.parse_fns, "\t\tparse_%s(state);\n", item->name);
}
else if(item->type == IT_LITERAL)
{
char *tok_name = unquote(item->name);
- buf_append(&state.parser, "if(is_%s(next))\n", tok_name);
- buf_append(&state.parser, "\t\tparse_%s(state);\n", tok_name);
+ buf_append(&state.parse_fns, "if(is_%s(next))\n", tok_name);
+ buf_append(&state.parse_fns, "\t\tparse_%s(state);\n", tok_name);
free(tok_name);
}
else
@@ -388,42 +391,42 @@
fatal("CHOICE/ENUMERATED but not Identifier or Literal");
}
}
- buf_append(&state.parser, "\telse\n");
- buf_append(&state.parser, "\t\tparse_error(\"Unexpected token\");\n");
+ buf_append(&state.parse_fns, "\telse\n");
+ buf_append(&state.parse_fns, "\t\tparse_error(\"Unexpected token\");\n");
break;
case ASN1TYPE_SET:
/* assert */
if(!state.and_items)
fatal("SET but and_items not set");
- buf_append(&state.parser, "\ttoken_t next;\n\n");
+ buf_append(&state.parse_fns, "\ttoken_t next;\n\n");
item = state.items;
while(item && item->type == IT_LITERAL)
{
-buf_append(&state.parser, "// TODO: eat %s\n\n", item->name);
+buf_append(&state.parse_fns, "// TODO: eat %s\n\n", item->name);
item = item->next;
}
- buf_append(&state.parser, "\t/* SET */\n");
- buf_append(&state.parser, "\twhile(true)\n\t{\n");
- buf_append(&state.parser, "\t\tnext = next_token();\n");
+ buf_append(&state.parse_fns, "\t/* SET */\n");
+ buf_append(&state.parse_fns, "\twhile(true)\n\t{\n");
+ buf_append(&state.parse_fns, "\t\tnext = next_token();\n");
while(item && item->type != IT_LITERAL)
{
if(item->type != IT_IDENTIFIER && item->type != IT_OPTIONAL)
fatal("SET but not Identifier or Optional");
- buf_append(&state.parser, "\t\t/* %s */\n", item->name);
- buf_append(&state.parser, "\t\tif(is_%s(next))\n\t\t{\n", item->name);
- buf_append(&state.parser, "\t\t\tparse_%s(state);\n", item->name);
- buf_append(&state.parser, "\t\t\tcontinue;\n\t\t}\n");
+ buf_append(&state.parse_fns, "\t\t/* %s */\n", item->name);
+ buf_append(&state.parse_fns, "\t\tif(is_%s(next))\n\t\t{\n", item->name);
+ buf_append(&state.parse_fns, "\t\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parse_fns, "\t\t\tcontinue;\n\t\t}\n");
item = item->next;
}
/* didn't match any items, must be the end of the SET */
- buf_append(&state.parser, "\t\telse\n\t\t{\n");
- buf_append(&state.parser, "\t\t\tbreak;\n\t\t}\n");
- buf_append(&state.parser, "\t}\n");
+ buf_append(&state.parse_fns, "\t\telse\n\t\t{\n");
+ buf_append(&state.parse_fns, "\t\t\tbreak;\n\t\t}\n");
+ buf_append(&state.parse_fns, "\t}\n");
/* eat any trailing literals */
while(item && item->type == IT_LITERAL)
{
-buf_append(&state.parser, "\n// TODO: eat %s\n", item->name);
+buf_append(&state.parse_fns, "\n// TODO: eat %s\n", item->name);
item = item->next;
}
break;
@@ -432,27 +435,27 @@
/* assert */
if(!state.and_items)
fatal("SEQUENCE but and_items not set");
- buf_append(&state.parser, "\t/* SEQUENCE */\n");
- buf_append(&state.parser, "\ttoken_t next;\n");
+ buf_append(&state.parse_fns, "\t/* SEQUENCE */\n");
+ buf_append(&state.parse_fns, "\ttoken_t next;\n");
item = state.items;
for(item=state.items; item; item=item->next)
{
if(item->type != IT_IDENTIFIER && item->type != IT_LITERAL && item->type != IT_OPTIONAL)
fatal("SEQUENCE but not Identifier, Literal or Optional");
- buf_append(&state.parser, "\n\t/* %s */\n", item->name);
+ buf_append(&state.parse_fns, "\n\t/* %s */\n", item->name);
if(item->type == IT_LITERAL)
{
-buf_append(&state.parser, "// TODO: eat %s\n", item->name);
+buf_append(&state.parse_fns, "// TODO: eat %s\n", item->name);
}
else
{
- buf_append(&state.parser, "\tnext = next_token();\n");
- buf_append(&state.parser, "\tif(is_%s(next))\n", item->name);
- buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parse_fns, "\tnext = next_token();\n");
+ buf_append(&state.parse_fns, "\tif(is_%s(next))\n", item->name);
+ buf_append(&state.parse_fns, "\t\tparse_%s(state);\n", item->name);
if(item->type != IT_OPTIONAL)
{
- buf_append(&state.parser, "\telse\n");
- buf_append(&state.parser, "\t\tparse_error(\"Expecting %s\");\n", item->name);
+ buf_append(&state.parse_fns, "\telse\n");
+ buf_append(&state.parse_fns, "\t\tparse_error(\"Expecting %s\");\n", item->name);
}
}
}
@@ -463,7 +466,7 @@
break;
}
}
- buf_append(&state.parser, "}\n\n", name);
+ buf_append(&state.parse_fns, "}\n\n", name);
/* free the items */
item = state.items;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-28 20:37:51
|
Revision: 355
http://redbutton.svn.sourceforge.net/redbutton/?rev=355&view=rev
Author: skilvington
Date: 2007-08-28 13:37:47 -0700 (Tue, 28 Aug 2007)
Log Message:
-----------
generate SET parser functions
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-28 16:15:53 UTC (rev 354)
+++ redbutton-author/trunk/ccc.y 2007-08-28 20:37:47 UTC (rev 355)
@@ -395,7 +395,8 @@
case ASN1TYPE_SET:
/* assert */
if(!state.and_items)
- fatal("SET type, but and_items not set");
+ fatal("SET but and_items not set");
+ buf_append(&state.parser, "\ttoken_t next;\n\n");
item = state.items;
while(item && item->type == IT_LITERAL)
{
@@ -403,13 +404,34 @@
item = item->next;
}
buf_append(&state.parser, "\t/* SET */\n");
-buf_append(&state.parser, "// TODO: SET\n");
+ buf_append(&state.parser, "\twhile(true)\n\t{\n");
+ buf_append(&state.parser, "\t\tnext = next_token();\n");
+ while(item && item->type != IT_LITERAL)
+ {
+ if(item->type != IT_IDENTIFIER && item->type != IT_OPTIONAL)
+ fatal("SET but not Identifier or Optional");
+ buf_append(&state.parser, "\t\t/* %s */\n", item->name);
+ buf_append(&state.parser, "\t\tif(is_%s(next))\n\t\t{\n", item->name);
+ buf_append(&state.parser, "\t\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parser, "\t\t\tcontinue;\n\t\t}\n");
+ item = item->next;
+ }
+ /* didn't match any items, must be the end of the SET */
+ buf_append(&state.parser, "\t\telse\n\t\t{\n");
+ buf_append(&state.parser, "\t\t\tbreak;\n\t\t}\n");
+ buf_append(&state.parser, "\t}\n");
+ /* eat any trailing literals */
+ while(item && item->type == IT_LITERAL)
+ {
+buf_append(&state.parser, "\n// TODO: eat %s\n", item->name);
+ item = item->next;
+ }
break;
case ASN1TYPE_SEQUENCE:
/* assert */
if(!state.and_items)
- fatal("SEQUENCE type, but and_items not set");
+ fatal("SEQUENCE but and_items not set");
buf_append(&state.parser, "\t/* SEQUENCE */\n");
buf_append(&state.parser, "\ttoken_t next;\n");
item = state.items;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-28 16:16:02
|
Revision: 354
http://redbutton.svn.sourceforge.net/redbutton/?rev=354&view=rev
Author: skilvington
Date: 2007-08-28 09:15:53 -0700 (Tue, 28 Aug 2007)
Log Message:
-----------
try generating C code for the compiler rather than a yacc grammar
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-author/trunk/ccc.y
Added Paths:
-----------
redbutton-author/trunk/asn1type.c
redbutton-author/trunk/asn1type.h
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-08-26 10:40:33 UTC (rev 353)
+++ redbutton-author/trunk/Makefile 2007-08-28 16:15:53 UTC (rev 354)
@@ -23,10 +23,10 @@
parser.tab.h: parser.tab.c
-ccc: ccc.y ccc.l
+ccc: ccc.y ccc.l asn1type.o
${LEX} -i -t ccc.l > lex.ccc.c
${YACC} -b ccc -d ccc.y
- ${CC} ${CFLAGS} -o ccc lex.ccc.c ccc.tab.c
+ ${CC} ${CFLAGS} -o ccc lex.ccc.c ccc.tab.c asn1type.o
parser.l: parser.l.header parser.l.footer grammar ccc
cat parser.l.header > parser.l
Added: redbutton-author/trunk/asn1type.c
===================================================================
--- redbutton-author/trunk/asn1type.c (rev 0)
+++ redbutton-author/trunk/asn1type.c 2007-08-28 16:15:53 UTC (rev 354)
@@ -0,0 +1,220 @@
+/*
+ * asn1type.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "asn1type.h"
+
+#define MATCH(NAME, TYPE) if(strcmp(name, #NAME) == 0) return ASN1TYPE_ ## TYPE;
+
+enum asn1type
+asn1type(char *name)
+{
+ MATCH(InterchangedObject, CHOICE)
+ MATCH(Group, SET) // MATCH(GroupClass, SET)
+ MATCH(StandardIdentifier, SEQUENCE)
+ MATCH(GroupItem, CHOICE)
+ MATCH(ApplicationClass, SET)
+ MATCH(DefaultAttribute, CHOICE)
+ MATCH(FontBody, CHOICE)
+ MATCH(SceneClass, SET)
+ MATCH(SceneCoordinateSystem, SEQUENCE)
+ MATCH(AspectRatio, SEQUENCE)
+ MATCH(NextScene, SEQUENCE)
+ MATCH(Ingredient, SET) // MATCH(IngredientClass, SET)
+ MATCH(ContentBody, CHOICE)
+ MATCH(ReferencedContent, SEQUENCE)
+ MATCH(LinkClass, SET)
+ MATCH(LinkCondition, SEQUENCE)
+ MATCH(EventTypeEnum, ENUMERATED) // MATCH(EventType, ENUMERATED)
+ MATCH(EventDataBody, CHOICE) // MATCH(EventData, CHOICE)
+ MATCH(Program, SET) // MATCH(ProgramClass, SET)
+ MATCH(ResidentProgramClass, SET)
+ MATCH(RemoteProgramClass, SET)
+ MATCH(InterchangedProgramClass, SET)
+ MATCH(PaletteClass, SET)
+ MATCH(FontClass, SET)
+ MATCH(CursorShapeClass, SET)
+ MATCH(Variable, SET) // MATCH(VariableClass, SET)
+ MATCH(OriginalValueBody, CHOICE) // MATCH(OriginalValue, CHOICE)
+ MATCH(BooleanVariableClass, SET)
+ MATCH(IntegerVariableClass, SET)
+ MATCH(OctetStringVariableClass, SET)
+ MATCH(ObjectRefVariableClass, SET)
+ MATCH(ContentRefVariableClass, SET)
+ MATCH(PresentableClass, SET)
+ MATCH(TokenManagerClass, SET)
+ MATCH(Movement, SEQUENCE)
+ MATCH(TokenGroupBody, SET) // MATCH(TokenGroupClass, SET)
+ MATCH(TokenGroupItem, SEQUENCE)
+ MATCH(ActionSlot, CHOICE)
+ MATCH(ListGroupClass, SET)
+ MATCH(Visible, SET) // MATCH(VisibleClass, SET)
+ MATCH(BoxSize, SEQUENCE) // MATCH(OriginalBoxSize, SEQUENCE)
+ MATCH(BitmapClass, SET)
+ MATCH(LineArtBody, SET) // MATCH(LineArtClass, SET)
+ MATCH(RectangleClass, SET)
+ MATCH(DynamicLineArtClass, SET)
+ MATCH(TextBody, SET) // MATCH(TextClass, SET)
+ MATCH(JustificationEnum, ENUMERATED) // MATCH(Justification, ENUMERATED)
+ MATCH(LineOrientationEnum, ENUMERATED) // MATCH(LineOrientation, ENUMERATED)
+ MATCH(StartCornerEnum, ENUMERATED) // MATCH(StartCorner, ENUMERATED)
+ MATCH(StreamClass, SET)
+ MATCH(StreamComponent, CHOICE)
+ MATCH(StorageEnum, ENUMERATED) // MATCH(Storage, ENUMERATED)
+ MATCH(AudioClass, SET)
+ MATCH(VideoClass, SET)
+ MATCH(TerminationEnum, ENUMERATED) // MATCH(Termination, ENUMERATED)
+ MATCH(RTGraphicsClass, SET)
+ MATCH(Interactible, SET) // MATCH(InteractibleClass, SET)
+ MATCH(SliderClass, SET)
+ MATCH(OrientationEnum, ENUMERATED) // MATCH(Orientation, ENUMERATED)
+ MATCH(SliderStyleEnum, ENUMERATED) // MATCH(SliderStyle, ENUMERATED)
+ MATCH(EntryFieldClass, SET)
+ MATCH(InputTypeEnum, ENUMERATED) // MATCH(InputType, ENUMERATED)
+ MATCH(HyperTextClass, SET)
+ MATCH(Button, SET) // MATCH(ButtonClass, SET)
+ MATCH(HotspotClass, SET)
+ MATCH(PushButtonBody, SET) // MATCH(PushButtonClass, SET)
+ MATCH(SwitchButtonClass, SET)
+ MATCH(ButtonStyleEnum, ENUMERATED) // MATCH(ButtonStyle, ENUMERATED)
+ MATCH(ActionClass, SEQUENCE)
+ MATCH(ElementaryAction, CHOICE)
+ MATCH(Add, SEQUENCE)
+ MATCH(AddItem, SEQUENCE)
+ MATCH(Append, SEQUENCE)
+ MATCH(Call, SEQUENCE)
+ MATCH(CallActionSlot, SEQUENCE)
+ MATCH(Clone, SEQUENCE)
+ MATCH(CloseConnection, SEQUENCE)
+ MATCH(DelItem, SEQUENCE)
+ MATCH(DeselectItem, SEQUENCE)
+ MATCH(Divide, SEQUENCE)
+ MATCH(DrawArc, SEQUENCE)
+ MATCH(DrawLine, SEQUENCE)
+ MATCH(DrawOval, SEQUENCE)
+ MATCH(DrawPolygon, SEQUENCE)
+ MATCH(DrawPolyline, SEQUENCE)
+ MATCH(DrawRectangle, SEQUENCE)
+ MATCH(DrawSector, SEQUENCE)
+ MATCH(Fork, SEQUENCE)
+ MATCH(GetAvailabilityStatus, SEQUENCE)
+ MATCH(GetBoxSize, SEQUENCE)
+ MATCH(GetCellItem, SEQUENCE)
+ MATCH(GetCursorPosition, SEQUENCE)
+ MATCH(GetEngineSupport, SEQUENCE)
+ MATCH(GetEntryPoint, SEQUENCE)
+ MATCH(GetFillColour, SEQUENCE)
+ MATCH(GetFirstItem, SEQUENCE)
+ MATCH(GetHighlightStatus, SEQUENCE)
+ MATCH(GetInteractionStatus, SEQUENCE)
+ MATCH(GetItemStatus, SEQUENCE)
+ MATCH(GetLabel, SEQUENCE)
+ MATCH(GetLastAnchorFired, SEQUENCE)
+ MATCH(GetLineColour, SEQUENCE)
+ MATCH(GetLineStyle, SEQUENCE)
+ MATCH(GetLineWidth, SEQUENCE)
+ MATCH(GetListItem, SEQUENCE)
+ MATCH(GetListSize, SEQUENCE)
+ MATCH(GetOverwriteMode, SEQUENCE)
+ MATCH(GetPortion, SEQUENCE)
+ MATCH(GetPosition, SEQUENCE)
+ MATCH(GetRunningStatus, SEQUENCE)
+ MATCH(GetSelectionStatus, SEQUENCE)
+ MATCH(GetSliderValue, SEQUENCE)
+ MATCH(GetTextContent, SEQUENCE)
+ MATCH(GetTextData, SEQUENCE)
+ MATCH(GetTokenPosition, SEQUENCE)
+ MATCH(GetVolume, SEQUENCE)
+ MATCH(Modulo, SEQUENCE)
+ MATCH(Move, SEQUENCE)
+ MATCH(MoveTo, SEQUENCE)
+ MATCH(Multiply, SEQUENCE)
+ MATCH(OpenConnection, SEQUENCE)
+ MATCH(PutBefore, SEQUENCE)
+ MATCH(PutBehind, SEQUENCE)
+ MATCH(ReadPersistent, SEQUENCE)
+ MATCH(ScaleBitmap, SEQUENCE)
+ MATCH(ScaleVideo, SEQUENCE)
+ MATCH(ScrollItems, SEQUENCE)
+ MATCH(SelectItem, SEQUENCE)
+ MATCH(SendEvent, SEQUENCE)
+ MATCH(SetBoxSize, SEQUENCE)
+ MATCH(SetCachePriority, SEQUENCE)
+ MATCH(SetCounterEndPosition, SEQUENCE)
+ MATCH(SetCounterPosition, SEQUENCE)
+ MATCH(SetCounterTrigger, SEQUENCE)
+ MATCH(SetCursorPosition, SEQUENCE)
+ MATCH(SetCursorShape, SEQUENCE)
+ MATCH(SetData, SEQUENCE)
+ MATCH(SetEntryPoint, SEQUENCE)
+ MATCH(SetFillColour, SEQUENCE)
+ MATCH(SetFirstItem, SEQUENCE)
+ MATCH(SetFontRef, SEQUENCE)
+ MATCH(SetHighlightStatus, SEQUENCE)
+ MATCH(SetInteractionStatus, SEQUENCE)
+ MATCH(SetLabel, SEQUENCE)
+ MATCH(SetLineColour, SEQUENCE)
+ MATCH(SetLineStyle, SEQUENCE)
+ MATCH(SetLineWidth, SEQUENCE)
+ MATCH(SetOverwriteMode, SEQUENCE)
+ MATCH(SetPaletteRef, SEQUENCE)
+ MATCH(SetPortion, SEQUENCE)
+ MATCH(SetPosition, SEQUENCE)
+ MATCH(SetSliderValue, SEQUENCE)
+ MATCH(SetSpeed, SEQUENCE)
+ MATCH(SetTimer, SEQUENCE)
+ MATCH(NewTimer, SEQUENCE)
+ MATCH(SetTransparency, SEQUENCE)
+ MATCH(SetVariable, SEQUENCE)
+ MATCH(SetVolume, SEQUENCE)
+ MATCH(Step, SEQUENCE)
+ MATCH(StorePersistent, SEQUENCE)
+ MATCH(Subtract, SEQUENCE)
+ MATCH(TestVariable, SEQUENCE)
+ MATCH(ToggleItem, SEQUENCE)
+ MATCH(TransitionTo, SEQUENCE)
+ MATCH(ConnectionTagOrNull, CHOICE)
+ MATCH(ComparisonValue, CHOICE)
+ MATCH(EmulatedEventData, CHOICE)
+ MATCH(NewColour, CHOICE)
+ MATCH(NewContent, CHOICE)
+ MATCH(NewFont, CHOICE)
+ MATCH(NewReferencedContent, SEQUENCE)
+ MATCH(NewContentSize, CHOICE)
+ MATCH(NewVariableValue, CHOICE)
+ MATCH(Parameter, CHOICE)
+ MATCH(Point, SEQUENCE)
+ MATCH(Rational, SEQUENCE)
+ MATCH(ObjectReference, CHOICE)
+ MATCH(ExternalReference, SEQUENCE)
+ MATCH(IndirectReference, CHOICE)
+ MATCH(GenericObjectReference, CHOICE)
+ MATCH(GenericContentReference, CHOICE)
+ MATCH(GenericInteger, CHOICE)
+ MATCH(GenericBoolean, CHOICE)
+ MATCH(GenericOctetString, CHOICE)
+ MATCH(Colour, CHOICE)
+ MATCH(XYPosition, SEQUENCE)
+ MATCH(SetInputReg, SEQUENCE) // MATCH(SetInputRegister, SEQUENCE)
+ MATCH(SetCellPosition, SEQUENCE)
+ MATCH(SetBitmapDecodeOffset, SEQUENCE)
+ MATCH(GetBitmapDecodeOffset, SEQUENCE)
+ MATCH(SetBackgroundColour, SEQUENCE)
+ MATCH(SetTextColour, SEQUENCE)
+ MATCH(SetFontAttributes, SEQUENCE)
+ MATCH(SetVideoDecodeOffset, SEQUENCE)
+ MATCH(GetVideoDecodeOffset, SEQUENCE)
+ MATCH(SetSliderParameters, SEQUENCE)
+ MATCH(GetFocusPosition, SEQUENCE)
+ MATCH(SetFocusPosition, SEQUENCE)
+ MATCH(OctetString, CHOICE);
+
+ fprintf(stderr, "Unknown ASN1 type: %s\n", name);
+ exit(EXIT_FAILURE);
+
+ return ASN1TYPE_UNKNOWN;
+}
Added: redbutton-author/trunk/asn1type.h
===================================================================
--- redbutton-author/trunk/asn1type.h (rev 0)
+++ redbutton-author/trunk/asn1type.h 2007-08-28 16:15:53 UTC (rev 354)
@@ -0,0 +1,19 @@
+/*
+ * asn1type.h
+ */
+
+#ifndef __ASN1TYPE_H__
+#define __ASN1TYPE_H__
+
+enum asn1type
+{
+ ASN1TYPE_UNKNOWN,
+ ASN1TYPE_CHOICE,
+ ASN1TYPE_ENUMERATED,
+ ASN1TYPE_SET,
+ ASN1TYPE_SEQUENCE
+};
+
+enum asn1type asn1type(char *);
+
+#endif /* __ASN1TYPE_H__ */
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-26 10:40:33 UTC (rev 353)
+++ redbutton-author/trunk/ccc.y 2007-08-28 16:15:53 UTC (rev 354)
@@ -8,6 +8,8 @@
#include <stdarg.h>
#include <ctype.h>
+#include "asn1type.h"
+
#define YYSTYPE char *
/* build up a list of items that define the current identifier */
@@ -51,6 +53,7 @@
struct str_list *tokens; /* "%token" section of the yacc output file */
struct buf grammar; /* grammar section of the yacc output file */
struct str_list *oneormores; /* grammar section for Identifier+ rules */
+ struct buf parser; /* C code for the parser */
} state;
int yyparse(void);
@@ -173,11 +176,11 @@
main(int argc, char *argv[])
{
char *prog_name = argv[0];
- /* by default output the grammar */
bool show_lexer = false;
+ bool show_parser = false;
int arg;
- while((arg = getopt(argc, argv, "l")) != EOF)
+ while((arg = getopt(argc, argv, "lp")) != EOF)
{
switch(arg)
{
@@ -185,6 +188,10 @@
show_lexer = true;
break;
+ case 'p':
+ show_parser = true;
+ break;
+
default:
usage(prog_name);
break;
@@ -199,6 +206,7 @@
state.tokens = NULL;
buf_init(&state.grammar);
state.oneormores = NULL;
+ buf_init(&state.parser);
yyparse();
@@ -207,6 +215,11 @@
/* output lexer */
printf("%s", state.lexer.str);
}
+ else if(show_parser)
+ {
+ /* output C code */
+ printf("%s", state.parser.str);
+ }
else
{
/* output grammar */
@@ -223,7 +236,7 @@
void
usage(char *prog_name)
{
- fprintf(stderr, "Syntax: %s [-l]\n", prog_name);
+ fprintf(stderr, "Syntax: %s [-l] [-p]\n", prog_name);
exit(EXIT_FAILURE);
}
@@ -271,6 +284,7 @@
{
struct item *item;
struct item *next;
+ unsigned int nitems;
buf_append(&state.grammar, "%s:\n\t", name);
@@ -280,6 +294,155 @@
buf_append(&state.grammar, ";\n\n");
+ /* C code for the parser */
+ buf_append(&state.parser, "void parse_%s(struct state *state)\n{\n", name);
+ /* count how many items make it up */
+ nitems = 0;
+ /* skip literals at the start */
+ item = state.items;
+ while(item && item->type == IT_LITERAL)
+ item = item->next;
+ /* don't count literals at the end */
+ while(item && item->type != IT_LITERAL)
+ {
+ nitems ++;
+ item = item->next;
+ }
+ if(nitems == 1)
+ {
+ item = state.items;
+ while(item && item->type == IT_LITERAL)
+ {
+buf_append(&state.parser, "// TODO: eat %s\n\n", item->name);
+ item = item->next;
+ }
+ buf_append(&state.parser, "\ttoken_t next = next_token();\n\n");
+ if(item->type == IT_IDENTIFIER)
+ {
+ buf_append(&state.parser, "\t/* %s */\n", item->name);
+ buf_append(&state.parser, "\tif(is_%s(next))\n", item->name);
+ buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parser, "\telse\n");
+ buf_append(&state.parser, "\t\tparse_error(\"Expecting %s\");\n", item->name);
+ }
+ else if(item->type == IT_OPTIONAL)
+ {
+ buf_append(&state.parser, "\t/* [%s] */\n", item->name);
+ buf_append(&state.parser, "\tif(is_%s(next))\n", item->name);
+ buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
+ }
+ else if(item->type == IT_ONEORMORE)
+ {
+ buf_append(&state.parser, "\t/* %s+ */\n", item->name);
+ buf_append(&state.parser, "\twhile(is_%s(next))\n", item->name);
+ buf_append(&state.parser, "\t{\n");
+ buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
+ buf_append(&state.parser, "\t\tnext = next_token();\n");
+ buf_append(&state.parser, "\t}\n");
+ buf_append(&state.parser, "\n\tunget_token(next);\n");
+ }
+ else
+ {
+ fatal("nitems==1 but not Identifier/[Identifier]/Identifier+");
+ }
+ item = item->next;
+ while(item)
+ {
+buf_append(&state.parser, "\n// TODO: eat %s\n", item->name);
+ item = item->next;
+ }
+ }
+ else
+ {
+ switch(asn1type(name))
+ {
+ case ASN1TYPE_CHOICE:
+ case ASN1TYPE_ENUMERATED:
+ /* assert */
+ if(state.and_items)
+ fatal("CHOICE or ENUMERATED type, but and_items set");
+ buf_append(&state.parser, "\ttoken_t next = next_token();\n\n");
+ buf_append(&state.parser, "\t/* CHOICE or ENUMERATED */\n");
+ item = state.items;
+ for(item=state.items; item; item=item->next)
+ {
+ /* is it the first */
+ if(item == state.items)
+ buf_append(&state.parser, "\t");
+ else
+ buf_append(&state.parser, "\telse ");
+ if(item->type == IT_IDENTIFIER)
+ {
+ buf_append(&state.parser, "if(is_%s(next))\n", item->name);
+ buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
+ }
+ else if(item->type == IT_LITERAL)
+ {
+ char *tok_name = unquote(item->name);
+ buf_append(&state.parser, "if(is_%s(next))\n", tok_name);
+ buf_append(&state.parser, "\t\tparse_%s(state);\n", tok_name);
+ free(tok_name);
+ }
+ else
+ {
+ fatal("CHOICE/ENUMERATED but not Identifier or Literal");
+ }
+ }
+ buf_append(&state.parser, "\telse\n");
+ buf_append(&state.parser, "\t\tparse_error(\"Unexpected token\");\n");
+ break;
+
+ case ASN1TYPE_SET:
+ /* assert */
+ if(!state.and_items)
+ fatal("SET type, but and_items not set");
+ item = state.items;
+ while(item && item->type == IT_LITERAL)
+ {
+buf_append(&state.parser, "// TODO: eat %s\n\n", item->name);
+ item = item->next;
+ }
+ buf_append(&state.parser, "\t/* SET */\n");
+buf_append(&state.parser, "// TODO: SET\n");
+ break;
+
+ case ASN1TYPE_SEQUENCE:
+ /* assert */
+ if(!state.and_items)
+ fatal("SEQUENCE type, but and_items not set");
+ buf_append(&state.parser, "\t/* SEQUENCE */\n");
+ buf_append(&state.parser, "\ttoken_t next;\n");
+ item = state.items;
+ for(item=state.items; item; item=item->next)
+ {
+ if(item->type != IT_IDENTIFIER && item->type != IT_LITERAL && item->type != IT_OPTIONAL)
+ fatal("SEQUENCE but not Identifier, Literal or Optional");
+ buf_append(&state.parser, "\n\t/* %s */\n", item->name);
+ if(item->type == IT_LITERAL)
+ {
+buf_append(&state.parser, "// TODO: eat %s\n", item->name);
+ }
+ else
+ {
+ buf_append(&state.parser, "\tnext = next_token();\n");
+ buf_append(&state.parser, "\tif(is_%s(next))\n", item->name);
+ buf_append(&state.parser, "\t\tparse_%s(state);\n", item->name);
+ if(item->type != IT_OPTIONAL)
+ {
+ buf_append(&state.parser, "\telse\n");
+ buf_append(&state.parser, "\t\tparse_error(\"Expecting %s\");\n", item->name);
+ }
+ }
+ }
+ break;
+
+ default:
+ fatal("Illegal ASN1TYPE");
+ break;
+ }
+ }
+ buf_append(&state.parser, "}\n\n", name);
+
/* free the items */
item = state.items;
while(item)
@@ -556,3 +719,4 @@
return;
}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-26 11:09:42
|
Revision: 352
http://redbutton.svn.sourceforge.net/redbutton/?rev=352&view=rev
Author: skilvington
Date: 2007-08-26 03:10:07 -0700 (Sun, 26 Aug 2007)
Log Message:
-----------
allow format strings in buf_append
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-24 16:07:40 UTC (rev 351)
+++ redbutton-author/trunk/ccc.y 2007-08-26 10:10:07 UTC (rev 352)
@@ -1,9 +1,11 @@
%{
+#define _GNU_SOURCE /* for vasprintf */
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <ctype.h>
#define YYSTYPE char *
@@ -70,7 +72,7 @@
void add_oneormore(struct str_list **, char *);
void buf_init(struct buf *);
-void buf_append(struct buf *, char *);
+void buf_append(struct buf *, char *, ...);
/* input line we are currently parsing */
int yylineno = 1;
@@ -270,8 +272,7 @@
struct item *item;
struct item *next;
- buf_append(&state.grammar, name);
- buf_append(&state.grammar, ":\n\t");
+ buf_append(&state.grammar, "%s:\n\t", name);
/* output each item that makes up this identifier */
for(item=state.items; item; item=item->next)
@@ -342,8 +343,7 @@
case IT_ONEORMORE:
/* add "OneOrMoreIdentifier" to the grammar */
- buf_append(&state.grammar, "OneOrMore");
- buf_append(&state.grammar, item->name);
+ buf_append(&state.grammar, "OneOrMore%s", item->name);
/* add the OneOrMoreIdentifier to our list */
add_oneormore(&state.oneormores, item->name);
break;
@@ -413,10 +413,7 @@
}
/* add it to the lex output file */
- buf_append(&state.lexer, quoted);
- buf_append(&state.lexer, "\treturn ");
- buf_append(&state.lexer, t->name);
- buf_append(&state.lexer, ";\n");
+ buf_append(&state.lexer, "%s\treturn %s;\n", quoted, t->name);
return t->name;
}
@@ -531,10 +528,17 @@
}
void
-buf_append(struct buf *b, char *app_str)
+buf_append(struct buf *b, char *fmt, ...)
{
- size_t app_len = strlen(app_str);
+ va_list ap;
+ char *app_str;
+ size_t app_len;
+ va_start(ap, fmt);
+ if((app_len = vasprintf(&app_str, fmt, ap)) < 0)
+ fatal("Out of memory or illegal format string");
+ va_end(ap);
+
/* +1 for the \0 terminator */
while(b->nalloced < b->len + app_len + 1)
{
@@ -547,6 +551,8 @@
b->len += app_len;
b->str[b->len] = '\0';
+ free(app_str);
+
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-26 11:08:34
|
Revision: 353
http://redbutton.svn.sourceforge.net/redbutton/?rev=353&view=rev
Author: skilvington
Date: 2007-08-26 03:40:33 -0700 (Sun, 26 Aug 2007)
Log Message:
-----------
nearly missed this, lucky I was trying out different parsing methods
Modified Paths:
--------------
redbutton-author/trunk/grammar
Modified: redbutton-author/trunk/grammar
===================================================================
--- redbutton-author/trunk/grammar 2007-08-26 10:10:07 UTC (rev 352)
+++ redbutton-author/trunk/grammar 2007-08-26 10:40:33 UTC (rev 353)
@@ -245,7 +245,7 @@
TokenGroupClass ::= "{:TokenGroup" TokenGroupBody "}" .
TokenGroupBody ::= Presentable TokenManager [TokenGroupItems]
[NoTokenActionSlots] .
-TokenGroupItems ::= "{:TokenGroupItems" "(" TokenGroupItem+ ")" .
+TokenGroupItems ::= ":TokenGroupItems" "(" TokenGroupItem+ ")" .
TokenGroupItem ::= "(" AVisible [ActionSlots] ")" .
AVisible ::= ObjectReference .
ActionSlots ::= ":ActionSlots" "(" ActionSlot+ ")" .
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-24 16:07:42
|
Revision: 351
http://redbutton.svn.sourceforge.net/redbutton/?rev=351&view=rev
Author: skilvington
Date: 2007-08-24 09:07:40 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
check we have the right number of cmd line params
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-24 14:10:56 UTC (rev 350)
+++ redbutton-author/trunk/ccc.y 2007-08-24 16:07:40 UTC (rev 351)
@@ -189,7 +189,9 @@
}
}
- if(optind == argc)
+ if(optind != argc)
+ usage(prog_name);
+
state.items = NULL;
buf_init(&state.lexer);
state.tokens = NULL;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-24 14:10:57
|
Revision: 350
http://redbutton.svn.sourceforge.net/redbutton/?rev=350&view=rev
Author: skilvington
Date: 2007-08-24 07:10:56 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
parser.l depends on parser.l.footer
Modified Paths:
--------------
redbutton-author/trunk/Makefile
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-08-24 14:06:52 UTC (rev 349)
+++ redbutton-author/trunk/Makefile 2007-08-24 14:10:56 UTC (rev 350)
@@ -19,6 +19,7 @@
${CC} ${CFLAGS} -o mhegc ${OBJS} ${LIBS}
mhegc.o: mhegc.c parser.tab.h
+ ${CC} ${CFLAGS} -c mhegc.c
parser.tab.h: parser.tab.c
@@ -27,7 +28,7 @@
${YACC} -b ccc -d ccc.y
${CC} ${CFLAGS} -o ccc lex.ccc.c ccc.tab.c
-parser.l: parser.l.header grammar ccc
+parser.l: parser.l.header parser.l.footer grammar ccc
cat parser.l.header > parser.l
cat grammar | ./ccc -l >> parser.l
cat parser.l.footer >> parser.l
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-24 14:06:53
|
Revision: 349
http://redbutton.svn.sourceforge.net/redbutton/?rev=349&view=rev
Author: skilvington
Date: 2007-08-24 07:06:52 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
cope with old versions of gcc that can't do -c -o with multiple input files
Modified Paths:
--------------
redbutton-author/trunk/Makefile
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-08-24 13:58:03 UTC (rev 348)
+++ redbutton-author/trunk/Makefile 2007-08-24 14:06:52 UTC (rev 349)
@@ -9,7 +9,8 @@
DESTDIR=/usr/local
OBJS= mhegc.o \
- parser.o \
+ lex.parser.o \
+ parser.tab.o \
utils.o
TARDIR=`basename ${PWD}`
@@ -18,9 +19,8 @@
${CC} ${CFLAGS} -o mhegc ${OBJS} ${LIBS}
mhegc.o: mhegc.c parser.tab.h
- ${CC} ${CFLAGS} -c mhegc.c
-parser.tab.h: parser.o
+parser.tab.h: parser.tab.c
ccc: ccc.y ccc.l
${LEX} -i -t ccc.l > lex.ccc.c
@@ -37,10 +37,11 @@
cat grammar | ./ccc >> parser.y
cat parser.y.footer >> parser.y
-parser.o: parser.l parser.y
+lex.parser.c: parser.l
${LEX} -i -t parser.l > lex.parser.c
+
+parser.tab.c: parser.y
${YACC} -b parser -d parser.y
- ${CC} ${CFLAGS} -c -o parser.o lex.parser.c parser.tab.c
.c.o:
${CC} ${CFLAGS} -c $<
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-24 13:58:05
|
Revision: 348
http://redbutton.svn.sourceforge.net/redbutton/?rev=348&view=rev
Author: skilvington
Date: 2007-08-24 06:58:03 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
don't output multiple copies of OneOrMoreIdentifiers
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-24 13:36:03 UTC (rev 347)
+++ redbutton-author/trunk/ccc.y 2007-08-24 13:58:03 UTC (rev 348)
@@ -25,10 +25,10 @@
bool include; /* should we output this optional item or not */
};
-/* the literal strings we need to make into %token's */
-struct token
+/* a list of strings */
+struct str_list
{
- struct token *next;
+ struct str_list *next;
char *name;
};
@@ -43,12 +43,12 @@
/* global state */
struct
{
- struct item *items; /* NULL => start a new identifier */
- bool and_items; /* true => identifier must contain all items */
- struct buf lexer; /* lex output file */
- struct token *tokens; /* "%token" section of the yacc output file */
- struct buf grammar; /* grammar section of the yacc output file */
- struct buf oneormores; /* grammar section for Identifier+ rules */
+ struct item *items; /* NULL => start a new identifier */
+ bool and_items; /* true => identifier must contain all items */
+ struct buf lexer; /* lex output file */
+ struct str_list *tokens; /* "%token" section of the yacc output file */
+ struct buf grammar; /* grammar section of the yacc output file */
+ struct str_list *oneormores; /* grammar section for Identifier+ rules */
} state;
int yyparse(void);
@@ -62,10 +62,13 @@
void output_def(char *);
void output_item(struct item *, bool);
-void print_tokens(struct token *);
-char *add_token(struct token **, char *);
+void print_tokens(struct str_list *);
+char *add_token(struct str_list **, char *);
char *unquote(char *);
+void print_oneormores(struct str_list *);
+void add_oneormore(struct str_list **, char *);
+
void buf_init(struct buf *);
void buf_append(struct buf *, char *);
@@ -191,7 +194,7 @@
buf_init(&state.lexer);
state.tokens = NULL;
buf_init(&state.grammar);
- buf_init(&state.oneormores);
+ state.oneormores = NULL;
yyparse();
@@ -206,7 +209,7 @@
print_tokens(state.tokens);
printf("%%%%\n");
printf("%s", state.grammar.str);
- printf("%s", state.oneormores.str);
+ print_oneormores(state.oneormores);
printf("%%%%\n");
}
@@ -339,17 +342,8 @@
/* add "OneOrMoreIdentifier" to the grammar */
buf_append(&state.grammar, "OneOrMore");
buf_append(&state.grammar, item->name);
- /* now create the OneOrMoreIdentifier rule */
- buf_append(&state.oneormores, "OneOrMore");
- buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, ":\n\t");
- buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, "\n\t|\n\t");
- buf_append(&state.oneormores, "OneOrMore");
- buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, " ");
- buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, "\n\t;\n\n");
+ /* add the OneOrMoreIdentifier to our list */
+ add_oneormore(&state.oneormores, item->name);
break;
default:
@@ -367,7 +361,7 @@
}
void
-print_tokens(struct token *t)
+print_tokens(struct str_list *t)
{
while(t)
{
@@ -379,10 +373,10 @@
}
char *
-add_token(struct token **head, char *quoted)
+add_token(struct str_list **head, char *quoted)
{
- struct token *t = malloc(sizeof(struct token));
- struct token *list;
+ struct str_list *t = malloc(sizeof(struct str_list));
+ struct str_list *list;
if(t == NULL)
fatal("Out of memory");
@@ -480,6 +474,47 @@
return output;
}
+void
+print_oneormores(struct str_list *list)
+{
+ while(list)
+ {
+ /* output the OneOrMoreIdentifier rule */
+ printf("OneOrMore%s:\n", list->name);
+ printf("\t%s\n", list->name);
+ printf("\t|\n");
+ printf("\tOneOrMore%s %s\n", list->name, list->name);
+ printf("\t;\n\n");
+ list = list->next;
+ }
+
+ return;
+}
+
+void
+add_oneormore(struct str_list **head, char *name)
+{
+ struct str_list *list;
+
+ /* check we haven't got it already */
+ for(list=*head; list; list=list->next)
+ {
+ if(strcmp(list->name, name) == 0)
+ return;
+ }
+
+ /* take a copy of the string */
+ if((list = malloc(sizeof(struct str_list))) == NULL
+ || (list->name = strdup(name)) == NULL)
+ fatal("Out of memory");
+
+ /* add it to the head of the list */
+ list->next = *head;
+ *head = list;
+
+ return;
+}
+
#define INIT_BUF_SIZE 1024
void
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-24 13:36:11
|
Revision: 347
http://redbutton.svn.sourceforge.net/redbutton/?rev=347&view=rev
Author: skilvington
Date: 2007-08-24 06:36:03 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
fix a compiler warning
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
redbutton-author/trunk/parser.y.header
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-24 10:15:03 UTC (rev 346)
+++ redbutton-author/trunk/ccc.y 2007-08-24 13:36:03 UTC (rev 347)
@@ -52,6 +52,7 @@
} state;
int yyparse(void);
+int yylex(void);
void usage(char *);
void fatal(char *);
Modified: redbutton-author/trunk/parser.y.header
===================================================================
--- redbutton-author/trunk/parser.y.header 2007-08-24 10:15:03 UTC (rev 346)
+++ redbutton-author/trunk/parser.y.header 2007-08-24 13:36:03 UTC (rev 347)
@@ -6,6 +6,8 @@
#define YYERROR_VERBOSE
#define YYDEBUG 1
+int yylex(void);
+
int yylineno = 1;
void
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-24 10:15:11
|
Revision: 346
http://redbutton.svn.sourceforge.net/redbutton/?rev=346&view=rev
Author: skilvington
Date: 2007-08-24 03:15:03 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
the parser works, but only if SET items appear in the order they are defined in the grammar
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-author/trunk/ccc.y
redbutton-author/trunk/grammar
Added Paths:
-----------
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/parser.l.footer
redbutton-author/trunk/parser.l.header
redbutton-author/trunk/parser.y.footer
redbutton-author/trunk/parser.y.header
redbutton-author/trunk/utils.c
redbutton-author/trunk/utils.h
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-08-24 09:36:13 UTC (rev 345)
+++ redbutton-author/trunk/Makefile 2007-08-24 10:15:03 UTC (rev 346)
@@ -9,19 +9,39 @@
DESTDIR=/usr/local
OBJS= mhegc.o \
- token.o \
+ parser.o \
utils.o
TARDIR=`basename ${PWD}`
+mhegc: ${OBJS}
+ ${CC} ${CFLAGS} -o mhegc ${OBJS} ${LIBS}
+
+mhegc.o: mhegc.c parser.tab.h
+ ${CC} ${CFLAGS} -c mhegc.c
+
+parser.tab.h: parser.o
+
ccc: ccc.y ccc.l
${LEX} -i -t ccc.l > lex.ccc.c
${YACC} -b ccc -d ccc.y
${CC} ${CFLAGS} -o ccc lex.ccc.c ccc.tab.c
-mhegc: ${OBJS}
- ${CC} ${CFLAGS} -o mhegc ${OBJS} ${LIBS}
+parser.l: parser.l.header grammar ccc
+ cat parser.l.header > parser.l
+ cat grammar | ./ccc -l >> parser.l
+ cat parser.l.footer >> parser.l
+parser.y: parser.y.header parser.y.footer grammar ccc
+ cat parser.y.header > parser.y
+ cat grammar | ./ccc >> parser.y
+ cat parser.y.footer >> parser.y
+
+parser.o: parser.l parser.y
+ ${LEX} -i -t parser.l > lex.parser.c
+ ${YACC} -b parser -d parser.y
+ ${CC} ${CFLAGS} -c -o parser.o lex.parser.c parser.tab.c
+
.c.o:
${CC} ${CFLAGS} -c $<
@@ -29,7 +49,7 @@
install -m 755 mhegc ${DESTDIR}/bin
clean:
- rm -f mhegc ccc lex.ccc.c ccc.tab.[ch] *.o core
+ rm -f mhegc ccc lex.*.c *.tab.[ch] parser.l parser.y *.o core
tar:
make clean
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-24 09:36:13 UTC (rev 345)
+++ redbutton-author/trunk/ccc.y 2007-08-24 10:15:03 UTC (rev 346)
@@ -51,6 +51,8 @@
struct buf oneormores; /* grammar section for Identifier+ rules */
} state;
+int yyparse(void);
+
void usage(char *);
void fatal(char *);
Modified: redbutton-author/trunk/grammar
===================================================================
--- redbutton-author/trunk/grammar 2007-08-24 09:36:13 UTC (rev 345)
+++ redbutton-author/trunk/grammar 2007-08-24 10:15:03 UTC (rev 346)
@@ -1,6 +1,8 @@
// MHEG5 Textual Format
// includes UK MHEG Profile additions
+InterchangedObject ::= ApplicationClass | SceneClass .
+
// B.4.1 Root Class
Root ::= ObjectIdentifier .
Added: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c (rev 0)
+++ redbutton-author/trunk/mhegc.c 2007-08-24 10:15:03 UTC (rev 346)
@@ -0,0 +1,39 @@
+/*
+ * mhegc.c
+ */
+
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "parser.tab.h"
+
+int yyparse(void);
+extern int yydebug;
+
+int
+main(int argc, char *argv[])
+{
+ yydebug=1;
+ yyparse();
+
+ return EXIT_SUCCESS;
+}
+
Added: redbutton-author/trunk/parser.l.footer
===================================================================
--- redbutton-author/trunk/parser.l.footer (rev 0)
+++ redbutton-author/trunk/parser.l.footer 2007-08-24 10:15:03 UTC (rev 346)
@@ -0,0 +1,2 @@
+. return INVALID;
+%%
Added: redbutton-author/trunk/parser.l.header
===================================================================
--- redbutton-author/trunk/parser.l.header (rev 0)
+++ redbutton-author/trunk/parser.l.header 2007-08-24 10:15:03 UTC (rev 346)
@@ -0,0 +1,15 @@
+%{
+#include <string.h>
+#define YYSTYPE char *
+#include "parser.tab.h"
+extern int yylineno;
+%}
+%%
+([-0-9][0-9]*)|(0x[0-9a-f]+) yylval = strdup(yytext); return INTEGER;
+true|false yylval = strdup(yytext); return BOOLEAN;
+\"((\\\")|[^"])*\" yylval = strdup(yytext); return STRING;
+'[^']*' yylval = strdup(yytext); return QPRINTABLE;
+`[^`]*` yylval = strdup(yytext); return BASE64;
+null return Null;
+[\n\r\f] yylineno ++;
+[ \t]+ /* ignore whitespace */
Added: redbutton-author/trunk/parser.y.footer
===================================================================
--- redbutton-author/trunk/parser.y.footer (rev 0)
+++ redbutton-author/trunk/parser.y.footer 2007-08-24 10:15:03 UTC (rev 346)
@@ -0,0 +1 @@
+
Added: redbutton-author/trunk/parser.y.header
===================================================================
--- redbutton-author/trunk/parser.y.header (rev 0)
+++ redbutton-author/trunk/parser.y.header 2007-08-24 10:15:03 UTC (rev 346)
@@ -0,0 +1,31 @@
+%{
+#include <stdio.h>
+#include <string.h>
+
+#define YYSTYPE char *
+#define YYERROR_VERBOSE
+#define YYDEBUG 1
+
+int yylineno = 1;
+
+void
+yyerror(const char *str)
+{
+ fprintf(stderr, "Error: %s at line %d\n", str, yylineno);
+}
+
+int
+yywrap(void)
+{
+ return 1;
+}
+
+%}
+
+%token INTEGER
+%token BOOLEAN
+%token STRING
+%token QPRINTABLE
+%token BASE64
+%token Null
+%token INVALID
Added: redbutton-author/trunk/utils.c
===================================================================
--- redbutton-author/trunk/utils.c (rev 0)
+++ redbutton-author/trunk/utils.c 2007-08-24 10:15:03 UTC (rev 346)
@@ -0,0 +1,147 @@
+/*
+ * utils.c
+ */
+
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <ctype.h>
+
+#include "utils.h"
+
+/*
+ * I don't want to double the size of my code just to deal with malloc failures
+ * if you've run out of memory you're fscked anyway, me trying to recover is not gonna help...
+ */
+
+void *
+safe_malloc(size_t nbytes)
+{
+ void *buf;
+
+ if((buf = malloc(nbytes)) == NULL)
+ fatal("Out of memory");
+
+ return buf;
+}
+
+/*
+ * safe_realloc(NULL, n) == safe_malloc(n)
+ */
+
+void *
+safe_realloc(void *oldbuf, size_t nbytes)
+{
+ void *newbuf;
+
+ if(oldbuf == NULL)
+ return safe_malloc(nbytes);
+
+ if((newbuf = realloc(oldbuf, nbytes)) == NULL)
+ fatal("Out of memory");
+
+ return newbuf;
+}
+
+/*
+ * safe_free(NULL) is okay
+ */
+
+void
+safe_free(void *buf)
+{
+ if(buf != NULL)
+ free(buf);
+
+ return;
+}
+
+void
+error(char *message, ...)
+{
+ va_list ap;
+
+ va_start(ap, message);
+ vfprintf(stderr, message, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+
+ return;
+}
+
+void
+fatal(char *message, ...)
+{
+ va_list ap;
+
+ va_start(ap, message);
+ vfprintf(stderr, message, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+
+ exit(EXIT_FAILURE);
+}
+
+/* number of bytes per line */
+#define HEXDUMP_WIDTH 16
+
+void
+hexdump(unsigned char *data, size_t nbytes)
+{
+ size_t nout;
+ int i;
+
+ nout = 0;
+ while(nout < nbytes)
+ {
+ /* byte offset at start of line */
+ if((nout % HEXDUMP_WIDTH) == 0)
+ printf("0x%.8x ", nout);
+ /* the byte value in hex */
+ printf("%.2x ", data[nout]);
+ /* the ascii equivalent at the end of the line */
+ if((nout % HEXDUMP_WIDTH) == (HEXDUMP_WIDTH - 1))
+ {
+ printf(" ");
+ for(i=HEXDUMP_WIDTH-1; i>=0; i--)
+ printf("%c", isprint(data[nout - i]) ? data[nout - i] : '.');
+ printf("\n");
+ }
+ nout ++;
+ }
+
+ /* the ascii equivalent if we haven't just done it */
+ if((nout % HEXDUMP_WIDTH) != 0)
+ {
+ /* pad to the start of the ascii equivalent */
+ for(i=(nout % HEXDUMP_WIDTH); i<HEXDUMP_WIDTH; i++)
+ printf(" ");
+ printf(" ");
+ /* print the ascii equivalent */
+ nout --;
+ for(i=(nout % HEXDUMP_WIDTH); i>=0; i--)
+ printf("%c", isprint(data[nout - i]) ? data[nout - i] : '.');
+ printf("\n");
+ }
+
+ return;
+}
+
Added: redbutton-author/trunk/utils.h
===================================================================
--- redbutton-author/trunk/utils.h (rev 0)
+++ redbutton-author/trunk/utils.h 2007-08-24 10:15:03 UTC (rev 346)
@@ -0,0 +1,39 @@
+/*
+ * utils.h
+ */
+
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __UTILS_H__
+#define __UTILS_H__
+
+#include <stdlib.h>
+#include <stdarg.h>
+
+void *safe_malloc(size_t);
+void *safe_realloc(void *, size_t);
+void safe_free(void *);
+
+void hexdump(unsigned char *, size_t);
+
+void error(char *, ...);
+void fatal(char *, ...);
+
+#endif /* __UTILS_H__ */
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-24 09:36:16
|
Revision: 345
http://redbutton.svn.sourceforge.net/redbutton/?rev=345&view=rev
Author: skilvington
Date: 2007-08-24 02:36:13 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
the parser found the last of the OCR errors
Modified Paths:
--------------
redbutton-author/trunk/grammar
Modified: redbutton-author/trunk/grammar
===================================================================
--- redbutton-author/trunk/grammar 2007-08-24 08:56:51 UTC (rev 344)
+++ redbutton-author/trunk/grammar 2007-08-24 09:36:13 UTC (rev 345)
@@ -92,7 +92,7 @@
SceneCoordinateSystem [AspectRatio]
[MovingCursor] [NextScenes] "}" .
InputEventRegister ::= ":InputEventReg" INTEGER .
-SceneCoordinateSvstem ::= ":SceneCS" XScene YScene .
+SceneCoordinateSystem ::= ":SceneCS" XScene YScene .
XScene ::= INTEGER .
YScene ::= INTEGER .
AspectRatio ::= ":AspectRatio" Width Height .
@@ -604,7 +604,7 @@
GetFirstItem ::= ":GetFirstItem" "(" Target FirstItemVar
")" .
GetHighlightStatus ::= ":GetHighlightStatus" "(" Target
- HightlightStatusVar ")" .
+ HighlightStatusVar ")" .
GetInteractionStatus ::= ":GetInteractionStatus" "(" Target
InteractionStatusVar ")" .
GetItemStatus ::= ":GetItemStatus" "(" Target
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <ski...@us...> - 2007-08-23 18:50:47
|
Revision: 343
http://redbutton.svn.sourceforge.net/redbutton/?rev=343&view=rev
Author: skilvington
Date: 2007-08-23 11:50:46 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
get rid of a warning
Modified Paths:
--------------
redbutton-author/trunk/ccc.l
Modified: redbutton-author/trunk/ccc.l
===================================================================
--- redbutton-author/trunk/ccc.l 2007-08-23 18:49:46 UTC (rev 342)
+++ redbutton-author/trunk/ccc.l 2007-08-23 18:50:46 UTC (rev 343)
@@ -1,5 +1,6 @@
%{
#include <string.h>
+#define YYSTYPE char *
#include "ccc.tab.h"
extern int yylineno;
%}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-23 18:49:48
|
Revision: 342
http://redbutton.svn.sourceforge.net/redbutton/?rev=342&view=rev
Author: skilvington
Date: 2007-08-23 11:49:46 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
put the C code in the right place
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-23 16:11:36 UTC (rev 341)
+++ redbutton-author/trunk/ccc.y 2007-08-23 18:49:46 UTC (rev 342)
@@ -50,6 +50,18 @@
struct buf oneormores; /* grammar section for Identifier+ rules */
} state;
+void add_item(enum item_type, char *);
+
+void output_def(char *);
+void output_item(struct item *, bool);
+
+void print_tokens(struct token *);
+char *add_token(struct token **, char *);
+char *unquote(char *);
+
+void buf_init(struct buf *);
+void buf_append(struct buf *, char *);
+
/* input line we are currently parsing */
int yylineno = 1;
@@ -68,16 +80,83 @@
return 1;
}
-/* here we go ... */
-void output_item(struct item *, bool);
+%}
-void print_tokens(struct token *);
-char *add_token(struct token **, char *);
-char *unquote(char *);
+%token COMMENT
+%token LITERAL
+%token IDENTIFIER
+%token DEFINEDAS
+%token ALTERNATIVE
+%token LBRACKET
+%token RBRACKET
+%token ONEORMORE
+%token ENDCLAUSE
+%token INVALID
-void buf_init(struct buf *);
-void buf_append(struct buf *, char *);
+%%
+clauses:
+ /* empty */
+ |
+ clauses clause
+ ;
+clause:
+ COMMENT
+ |
+ IDENTIFIER DEFINEDAS definition ENDCLAUSE
+ {
+ output_def($1);
+ }
+ ;
+
+definition:
+ and_items
+ {
+ state.and_items = true;
+ }
+ |
+ or_items
+ {
+ state.and_items = false;
+ }
+ ;
+
+and_items:
+ item
+ |
+ and_items item
+ ;
+
+or_items:
+ item ALTERNATIVE item
+ |
+ or_items ALTERNATIVE item
+ ;
+
+item:
+ LITERAL
+ {
+ add_item(IT_LITERAL, $1);
+ }
+ |
+ IDENTIFIER
+ {
+ add_item(IT_IDENTIFIER, $1);
+ }
+ |
+ LBRACKET IDENTIFIER RBRACKET
+ {
+ add_item(IT_OPTIONAL, $2);
+ }
+ |
+ IDENTIFIER ONEORMORE
+ {
+ add_item(IT_ONEORMORE, $1);
+ }
+ ;
+%%
+
+/* here we go ... */
int
main(void)
{
@@ -394,78 +473,3 @@
return;
}
-%}
-
-%token COMMENT
-%token LITERAL
-%token IDENTIFIER
-%token DEFINEDAS
-%token ALTERNATIVE
-%token LBRACKET
-%token RBRACKET
-%token ONEORMORE
-%token ENDCLAUSE
-%token INVALID
-
-%%
-clauses:
- /* empty */
- |
- clauses clause
- ;
-
-clause:
- COMMENT
- |
- IDENTIFIER DEFINEDAS definition ENDCLAUSE
- {
- output_def($1);
- }
- ;
-
-definition:
- and_items
- {
- state.and_items = true;
- }
- |
- or_items
- {
- state.and_items = false;
- }
- ;
-
-and_items:
- item
- |
- and_items item
- ;
-
-or_items:
- item ALTERNATIVE item
- |
- or_items ALTERNATIVE item
- ;
-
-item:
- LITERAL
- {
- add_item(IT_LITERAL, $1);
- }
- |
- IDENTIFIER
- {
- add_item(IT_IDENTIFIER, $1);
- }
- |
- LBRACKET IDENTIFIER RBRACKET
- {
- add_item(IT_OPTIONAL, $2);
- }
- |
- IDENTIFIER ONEORMORE
- {
- add_item(IT_ONEORMORE, $1);
- }
- ;
-%%
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-23 16:11:41
|
Revision: 341
http://redbutton.svn.sourceforge.net/redbutton/?rev=341&view=rev
Author: skilvington
Date: 2007-08-23 09:11:36 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
output yacc grammar for optional items
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-23 13:10:24 UTC (rev 340)
+++ redbutton-author/trunk/ccc.y 2007-08-23 16:11:36 UTC (rev 341)
@@ -3,6 +3,7 @@
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <ctype.h>
#define YYSTYPE char *
@@ -20,6 +21,7 @@
struct item *next;
char *name;
enum item_type type;
+ bool include; /* should we output this optional item or not */
};
/* the literal strings we need to make into %token's */
@@ -67,6 +69,8 @@
}
/* here we go ... */
+void output_item(struct item *, bool);
+
void print_tokens(struct token *);
char *add_token(struct token **, char *);
char *unquote(char *);
@@ -131,6 +135,7 @@
new_item->next = NULL;
new_item->name = name; /* lex strdup's it for us */
new_item->type = type;
+ new_item->include = true;
return;
}
@@ -140,58 +145,14 @@
{
struct item *item;
struct item *next;
- char *tok_name;
buf_append(&state.grammar, name);
buf_append(&state.grammar, ":\n\t");
+ /* output each item that makes up this identifier */
for(item=state.items; item; item=item->next)
- {
- switch(item->type)
- {
- case IT_LITERAL:
- tok_name = add_token(&state.tokens, item->name);
- buf_append(&state.grammar, tok_name);
- break;
+ output_item(item, true);
- case IT_IDENTIFIER:
- buf_append(&state.grammar, item->name);
- break;
-
- case IT_OPTIONAL:
-buf_append(&state.grammar, "[FIXME:");
-buf_append(&state.grammar, item->name);
-buf_append(&state.grammar, "]");
- break;
-
- case IT_ONEORMORE:
- /* add "OneOrMoreIdentifier" to the grammar */
- buf_append(&state.grammar, "OneOrMore");
- buf_append(&state.grammar, item->name);
- /* now create the OneOrMoreIdentifier rule */
- buf_append(&state.oneormores, "OneOrMore");
- buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, ":\n\t");
- buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, "\n\t|\n\t");
- buf_append(&state.oneormores, "OneOrMore");
- buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, " ");
- buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, "\n\t;\n\n");
- break;
-
- default:
- fatal("Unexpected item type");
- break;
- }
- /* 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");
- }
-
buf_append(&state.grammar, ";\n\n");
/* free the items */
@@ -209,6 +170,84 @@
}
void
+output_item(struct item *item, bool recurse)
+{
+ char *tok_name;
+ struct item *rest;
+
+ switch(item->type)
+ {
+ case IT_LITERAL:
+ tok_name = add_token(&state.tokens, item->name);
+ buf_append(&state.grammar, tok_name);
+ break;
+
+ case IT_IDENTIFIER:
+ buf_append(&state.grammar, item->name);
+ break;
+
+ case IT_OPTIONAL:
+ if(recurse)
+ {
+ /*
+ * we are an optional item,
+ * so first output the remaining items
+ * this creates a rule which does not including us
+ */
+ item->include = false;
+ for(rest=item->next; rest; rest=rest->next)
+ output_item(rest, true);
+ /* or it with a rule which does contain us */
+ if(item->next == NULL)
+ buf_append(&state.grammar, "\n\t");
+ buf_append(&state.grammar, "|\n\t");
+ /*
+ * now output the items before us and output ourself,
+ * this constructs a rule including us
+ */
+ item->include = true;
+ for(rest=state.items; rest!=item; rest=rest->next)
+ output_item(rest, false);
+ buf_append(&state.grammar, item->name);
+ }
+ else if(item->include)
+ {
+ buf_append(&state.grammar, item->name);
+ }
+ break;
+
+ case IT_ONEORMORE:
+ /* add "OneOrMoreIdentifier" to the grammar */
+ buf_append(&state.grammar, "OneOrMore");
+ buf_append(&state.grammar, item->name);
+ /* now create the OneOrMoreIdentifier rule */
+ buf_append(&state.oneormores, "OneOrMore");
+ buf_append(&state.oneormores, item->name);
+ buf_append(&state.oneormores, ":\n\t");
+ buf_append(&state.oneormores, item->name);
+ buf_append(&state.oneormores, "\n\t|\n\t");
+ buf_append(&state.oneormores, "OneOrMore");
+ buf_append(&state.oneormores, item->name);
+ buf_append(&state.oneormores, " ");
+ buf_append(&state.oneormores, item->name);
+ buf_append(&state.oneormores, "\n\t;\n\n");
+ break;
+
+ default:
+ fatal("Unexpected item type");
+ break;
+ }
+
+ /* do we need all the items, or just one of them */
+ if(state.and_items)
+ buf_append(&state.grammar, item->next ? (item->include ? " " : "") : "\n\t");
+ else
+ buf_append(&state.grammar, item->next ? "\n\t|\n\t" : "\n\t");
+
+ return;
+}
+
+void
print_tokens(struct token *t)
{
while(t)
@@ -370,6 +409,7 @@
%%
clauses:
+ /* empty */
|
clauses clause
;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-23 13:10:29
|
Revision: 340
http://redbutton.svn.sourceforge.net/redbutton/?rev=340&view=rev
Author: skilvington
Date: 2007-08-23 06:10:24 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
patch from Mario Rossi to stop rb-download trying to tune unless it really needs to
Modified Paths:
--------------
redbutton-download/trunk/channels.c
Modified: redbutton-download/trunk/channels.c
===================================================================
--- redbutton-download/trunk/channels.c 2007-08-23 12:53:39 UTC (rev 339)
+++ redbutton-download/trunk/channels.c 2007-08-23 13:10:24 UTC (rev 340)
@@ -39,6 +39,7 @@
#define SLOF (11700*1000UL)
#define LOF1 (9750*1000UL)
#define LOF2 (10600*1000UL)
+#define ONE_kHz 1000UL
/* internal functions */
static bool get_tune_params(fe_type_t, uint16_t, struct dvb_frontend_parameters *, char *, unsigned int *);
@@ -575,8 +576,10 @@
/* are we already tuned to the right frequency */
vverbose("Current frequency %u; needed %u; first_time=%d", current_params.frequency, needed_params.frequency, first_time);
+
+ /* frequency resolution is up to 1 kHz */
if(first_time
- || current_params.frequency != needed_params.frequency)
+ || abs(current_params.frequency - needed_params.frequency) >= ONE_kHz)
{
first_time = false;
verbose("Retuning to frequency %u", needed_params.frequency);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-08-23 12:53:41
|
Revision: 339
http://redbutton.svn.sourceforge.net/redbutton/?rev=339&view=rev
Author: skilvington
Date: 2007-08-23 05:53:39 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
create OneOrMoreIdentifier rather than IdentifierOneOrMore
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-23 11:27:23 UTC (rev 338)
+++ redbutton-author/trunk/ccc.y 2007-08-23 12:53:39 UTC (rev 339)
@@ -165,16 +165,18 @@
break;
case IT_ONEORMORE:
- /* add "IdentifierOneOrMore" to the grammar */
+ /* add "OneOrMoreIdentifier" to the grammar */
+ buf_append(&state.grammar, "OneOrMore");
buf_append(&state.grammar, item->name);
- buf_append(&state.grammar, "OneOrMore");
- /* now create the IdentifierOneOrMore rule */
+ /* now create the OneOrMoreIdentifier rule */
+ buf_append(&state.oneormores, "OneOrMore");
buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, "OneOrMore:\n\t");
+ buf_append(&state.oneormores, ":\n\t");
buf_append(&state.oneormores, item->name);
buf_append(&state.oneormores, "\n\t|\n\t");
+ buf_append(&state.oneormores, "OneOrMore");
buf_append(&state.oneormores, item->name);
- buf_append(&state.oneormores, "OneOrMore ");
+ buf_append(&state.oneormores, " ");
buf_append(&state.oneormores, item->name);
buf_append(&state.oneormores, "\n\t;\n\n");
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <ski...@us...> - 2007-08-23 11:27:30
|
Revision: 338
http://redbutton.svn.sourceforge.net/redbutton/?rev=338&view=rev
Author: skilvington
Date: 2007-08-23 04:27:23 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
generate lex output too
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-08-23 11:18:29 UTC (rev 337)
+++ redbutton-author/trunk/ccc.y 2007-08-23 11:27:23 UTC (rev 338)
@@ -42,8 +42,9 @@
{
struct item *items; /* NULL => start a new identifier */
bool and_items; /* true => identifier must contain all items */
- struct token *tokens; /* "%token" section of the output file */
- struct buf grammar; /* grammar section of the output file */
+ struct buf lexer; /* lex output file */
+ struct token *tokens; /* "%token" section of the yacc output file */
+ struct buf grammar; /* grammar section of the yacc output file */
struct buf oneormores; /* grammar section for Identifier+ rules */
} state;
@@ -77,12 +78,17 @@
main(void)
{
state.items = NULL;
+ buf_init(&state.lexer);
state.tokens = NULL;
buf_init(&state.grammar);
buf_init(&state.oneormores);
yyparse();
+ printf("-- lex --\n");
+ printf("%s", state.lexer.str);
+
+ printf("-- yacc --\n");
print_tokens(state.tokens);
printf("%%%%\n");
printf("%s", state.grammar.str);
@@ -250,6 +256,12 @@
list->next = t;
}
+ /* add it to the lex output file */
+ buf_append(&state.lexer, quoted);
+ buf_append(&state.lexer, "\treturn ");
+ buf_append(&state.lexer, t->name);
+ buf_append(&state.lexer, ";\n");
+
return t->name;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|