[Redbutton-devel] SF.net SVN: redbutton: [346] redbutton-author/trunk
Brought to you by:
skilvington
|
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.
|