[Redbutton-devel] SF.net SVN: redbutton: [328] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-08-22 13:19:39
|
Revision: 328
http://redbutton.svn.sourceforge.net/redbutton/?rev=328&view=rev
Author: skilvington
Date: 2007-08-22 06:19:38 -0700 (Wed, 22 Aug 2007)
Log Message:
-----------
import the yacc grammar compiler
Added Paths:
-----------
redbutton-author/trunk/Makefile
redbutton-author/trunk/ccc.l
redbutton-author/trunk/ccc.y
Added: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile (rev 0)
+++ redbutton-author/trunk/Makefile 2007-08-22 13:19:38 UTC (rev 328)
@@ -0,0 +1,35 @@
+CC=gcc
+CFLAGS=-Wall -O2
+
+LEX=lex
+YACC=yacc
+
+DESTDIR=/usr/local
+
+OBJS= mhegc.o \
+ token.o \
+ utils.o
+
+TARDIR=`basename ${PWD}`
+
+ccc: ccc.y ccc.l
+ ${LEX} -i ccc.l
+ ${YACC} -d ccc.y
+ ${CC} ${CFLAGS} -o ccc lex.yy.c y.tab.c
+
+mhegc: ${OBJS}
+ ${CC} ${CFLAGS} -o mhegc ${OBJS} ${LIBS}
+
+.c.o:
+ ${CC} ${CFLAGS} -c $<
+
+install: mhegc
+ install -m 755 mhegc ${DESTDIR}/bin
+
+clean:
+ rm -f mhegc *.o core
+
+tar:
+ make clean
+ (cd ..; tar zcvf ${TARDIR}.tar.gz --exclude .svn ${TARDIR})
+
Added: redbutton-author/trunk/ccc.l
===================================================================
--- redbutton-author/trunk/ccc.l (rev 0)
+++ redbutton-author/trunk/ccc.l 2007-08-22 13:19:38 UTC (rev 328)
@@ -0,0 +1,18 @@
+%{
+#include <string.h>
+#include "y.tab.h"
+%}
+%%
+\/\/[^\n\r\f]* return COMMENT;
+\"[^"]*\" yylval = strdup(yytext); return LITERAL;
+[a-z][a-z0-9]* yylval = strdup(yytext); return IDENTIFIER;
+"::=" return DEFINEDAS;
+"|" return ALTERNATIVE;
+"[" return LBRACKET;
+"]" return RBRACKET;
+"+" return ONEORMORE;
+"." return ENDCLAUSE;
+[\n\r\f] /* ignore end of line */
+[ \t]+ /* ignore whitespace */
+. return INVALID;
+%%
Added: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y (rev 0)
+++ redbutton-author/trunk/ccc.y 2007-08-22 13:19:38 UTC (rev 328)
@@ -0,0 +1,94 @@
+%{
+#include <stdio.h>
+#include <string.h>
+
+#define YYSTYPE char *
+
+void
+yyerror(const char *str)
+{
+ fprintf(stderr, "yyerror: %s\n", str);
+}
+
+int
+yywrap(void)
+{
+ return 1;
+}
+
+int
+main(void)
+{
+ yyparse();
+
+ return 0;
+}
+
+%}
+
+%token COMMENT
+%token LITERAL
+%token IDENTIFIER
+%token DEFINEDAS
+%token ALTERNATIVE
+%token LBRACKET
+%token RBRACKET
+%token ONEORMORE
+%token ENDCLAUSE
+%token INVALID
+
+%%
+clauses:
+ |
+ clauses clause
+ ;
+
+clause:
+ COMMENT
+ |
+ IDENTIFIER DEFINEDAS definition ENDCLAUSE
+ {
+ printf("DEFINE:'%s'\n", $1);
+ }
+ ;
+
+definition:
+ and_items
+ |
+ or_items
+ ;
+
+and_items:
+ item
+ |
+ and_items item
+ ;
+
+or_items:
+ item ALTERNATIVE item
+ |
+ or_items ALTERNATIVE item
+ ;
+
+item:
+ LITERAL
+ {
+ printf("LITERAL:'%s'\n", $1);
+ }
+ |
+ IDENTIFIER
+ {
+ printf("IDENTIFIER:'%s'\n", $1);
+ }
+ |
+ LBRACKET IDENTIFIER RBRACKET
+ {
+ printf("[IDENTIFIER]:'%s'\n", $2);
+ }
+ |
+ IDENTIFIER ONEORMORE
+ {
+ printf("IDENTIFIER+:'%s'\n", $1);
+ }
+ ;
+%%
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|