Skip to content
This repository has been archived by the owner on Jul 26, 2018. It is now read-only.

0.4.5 update #15

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
greg
greg.exe
samples/*.c
/.gdbinit
/.lldbinit
59 changes: 41 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
CFLAGS = -g -Wall $(OFLAGS) $(XFLAGS)
OFLAGS = -O3 -DNDEBUG
OFLAGS = -O3 -DNDEBUG -DYY_MAIN
CFLAGS = -g -Wall -Wno-unused-function $(OFLAGS) $(XFLAGS)
#OFLAGS = -pg

OBJS = tree.o compile.o
SRCS = tree.c compile.c
SAMPLES = $(wildcard samples/*.leg)

all : greg

greg : greg.o $(OBJS)
$(CC) $(CFLAGS) -o $@-new greg.o $(OBJS)
mv $@-new $@
greg : greg.c $(SRCS)
$(CC) $(CFLAGS) -o $@-new greg.c $(SRCS)
cp $@-new $@

ROOT =
PREFIX ?= /usr
Expand All @@ -23,22 +24,23 @@ $(BINDIR)/% : %
uninstall : .FORCE
rm -f $(BINDIR)/greg

greg.o : greg.c

# bootstrap greg from greg.g
greg.c : greg.g compile.c tree.c
test -f greg && ./greg -o greg-new.c greg.g
$(CC) $(CFLAGS) -o greg-new greg-new.c $(OBJS)
$(MAKE) greg-new
./greg-new -o greg-new.c greg.g
$(CC) $(CFLAGS) -o greg-new greg-new.c $(OBJS)
mv greg-new.c greg.c
mv greg-new greg
$(CC) $(CFLAGS) -o greg-new greg-new.c $(SRCS)
cp greg-new.c greg.c
cp greg-new greg

# bootstrap: call make greg-new when you updated compile.c and greg-new.c
greg-new : greg-new.c $(SRCS)
$(CC) $(CFLAGS) -o greg-new greg-new.c $(SRCS)

grammar : .FORCE
./greg -o greg.c greg.g

clean : .FORCE
rm -rf *~ *.o *.greg.[cd] greg samples/*.o samples/calc samples/*.dSYM testing1.c testing2.c *.dSYM selftest/
rm -rf *~ *.o *.greg.[cd] greg ${SAMPLES:.leg=.o} ${SAMPLES:.leg=} ${SAMPLES:.leg=.c} samples/*.dSYM testing1.c testing2.c *.dSYM selftest/

spotless : clean .FORCE
rm -f greg
Expand All @@ -49,15 +51,36 @@ samples/calc.c: samples/calc.leg greg
samples/calc: samples/calc.c
$(CC) $(CFLAGS) -o $@ $<

test: samples/calc run
echo '21 * 2 + 0' | ./samples/calc | grep 42
samples: ${SAMPLES:.leg=} greg

%.c: %.leg
./greg $< > $@
.leg.c:
./greg $< > $@

test: samples run
echo 'abcbcdabcbcdabcbcdabcbcd' | samples/accept | tee samples/accept.out
diff samples/accept.out samples/accept.ref
echo 'abcbcdabcbcdabcbcdabcbcd' | samples/rule | tee samples/rule.out
diff samples/rule.out samples/rule.ref
echo '21 * 2 + 0' | samples/calc | grep 42
echo 'a = 6; b = 7; a * b' | samples/calc | grep 42
echo ' 2 *3 *(3+ 4) ' | samples/dc | grep 42
echo 'a = 6; b = 7; a * b' | samples/dcv | grep 42
echo 'print 2 * 21 + 0' | samples/basic | grep 42
echo 'ab.ac.ad.ae.afg.afh.afg.afh.afi.afj.' | samples/test | tee samples/test.out
diff samples/test.out samples/test.ref
cat samples/wc.leg | samples/wc > samples/wc.out
diff samples/wc.out samples/wc.ref
echo '6*9' | samples/erract | tee samples/erract.out
diff samples/erract.out samples/erract.ref

run: greg
mkdir -p selftest
./greg -o testing1.c greg.g
$(CC) $(CFLAGS) -o selftest/testing1 testing1.c $(OBJS)
$(CC) $(CFLAGS) -o selftest/testing1 testing1.c $(SRCS)
$(TOOL) ./selftest/testing1 -o testing2.c greg.g
$(CC) $(CFLAGS) -o selftest/testing2 testing2.c $(OBJS)
$(CC) $(CFLAGS) -o selftest/testing2 testing2.c $(SRCS)
$(TOOL) ./selftest/testing2 -o selftest/calc.c ./samples/calc.leg
$(CC) $(CFLAGS) -o selftest/calc selftest/calc.c
$(TOOL) echo '21 * 2 + 0' | ./selftest/calc | grep 42
Expand Down
12 changes: 6 additions & 6 deletions README
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
greg is a re-entrant peg/leg, with some bug fixes.
greg is a re-entrant leg, with some bug fixes and enhancements.
<http://piumarta.com/software/peg/>
This version is equivalent to leg from peg-0.1.13.

the most comprehensive example of greg usage is in
nagaqueen, an ooc grammar, used in rock, an ooc
compiler written in ooc.
<http://github.com/nddrylliog/nagaqueen>
<http://github.com/nddrylliog/rock>
greg derived from potion <http://github.com/perl11/potion>,
is used as perl5 and perl6 parser in <http://github.com/perl11/p2>.
And in nagaqueen, an ooc grammar <http://github.com/nddrylliog/nagaqueen>,
used in rock, an ooc compiler written in ooc <http://github.com/nddrylliog/rock>.

peg/leg is copyright (c) 2007 by Ian Piumarta
released under an MIT license. as is greg.
Loading