with complete bracketing and indenting.
# File: indent_test.mk
- myCFLAGS := -Wall -g -fplan9-extensions
- CFLAGS := $(filter-out $(myCFLAGS),$(CFLAGS)) $(myCFLAGS)
- myLDLIBS:= libparser.o libscanner.o libmdcode.o -licuuc
- LDLIBS := $(filter-out $(myLDLIBS),$(LDLIBS)) $(myLDLIBS)
+ itestCFLAGS := -Wall -g -fplan9-extensions
+ itestLDLIBS:= libparser.o libscanner.o libmdcode.o -licuuc
all :: itest
- itest.c itest.h : indent_test.mdc parsergen libparser.o libscanner.o libmdcode.o
+ itest.c itest.h : indent_test.mdc parsergen
./parsergen -o itest --LALR --tag indent indent_test.mdc
- indent_test.mk: indent_test.mdc md2c
+ indent_test.mk itest.code: indent_test.mdc md2c
./md2c indent_test.mdc
- itest: itest.c
+ itest: itest.c | $(filter %.o,$(itestLDLIBS))
+ $(CC) $(itestCFLAGS) $^ $(itestLDLIBS) -o $@
doitest: itest itest.code
./itest itest.code
checkitest: itest itest.code
@grep -v '^#' itest.out > .tmp.out
- @./itest itest.code | diff -u - .tmp.out || echo itest FAILED
+ @./itest itest.code | diff -u .tmp.out - || echo itest FAILED
@sed -e 'i\
' itest.code > itest2.code
- @./itest itest2.code| diff -u - .tmp.out || echo itest2 FAILED
+ @./itest itest2.code| diff -u .tmp.out - || echo itest2 FAILED
demos :: doitest
tests :: checkitest
# indent: header
- ./parsergen -o itest --LALR indent_test.cgm
- cc -o itest itest.c lib*.o -licuuc -lgmp
- ./itest itest.code
-
struct expression {
struct text op;
struct expression *left, *right;
char *file = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
struct section *s = code_extract(file, file+len, NULL);
struct token_config config = {
- .ignored = (1 << TK_line_comment)
- | (1 << TK_block_comment),
.number_chars = ".,_+-",
.word_start = "",
.word_cont = "",
~~~~~~
+$TERM if { } : * + - / ; =
+
Program -> Statementlist ${ print_statement($1, 0); }$
$*statement
Newlines -> NEWLINE
| Newlines NEWLINE
- Statementlist -> Statements ${ $0 = $<1; }$
- | Newlines Statements ${ $0 = $<2; }$
+ Statementlist -> Statements ${ $0 = $<S; }$
+ | Newlines Statements ${ $0 = $<S1; }$
Statements -> Statements Statement ${
{
| Newlines {
Close -> }
| Newlines }
- Block -> Open Statementlist Close ${ $0 = $<2; }$
- | Open SimpleStatements } ${ $0 = $<2; }$
- | : SimpleStatements ${ $0 = $<2; }$
- | : StatementBlock ${ $0 = $<2; }$
- StatementBlock -> Statementlist $$OUT ${ $0 = $<1; }$
+ Block -> Open Statementlist Close ${ $0 = $<S; }$
+ | Open SimpleStatements } ${ $0 = $<S; }$
+ | : SimpleStatements ${ $0 = $<SS; }$
+ | : StatementBlock ${ $0 = $<SB; }$
+ StatementBlock -> Statementlist ${ $0 = $<Sl; }$
SimpleStatements -> SimpleStatements ; SimpleStatement ${
{
struct statement **s;
- $0 = $<1;
+ $0 = $<SSs;
s = &$0;
while (*s)
s = &(*s)->next;
- *s = $<3;
+ *s = $<SS;
}
}$
| SimpleStatement ${ $0 = $<1; }$
}$
SSline -> SimpleStatements NEWLINE ${ $0 = $<1; }$
Statement -> SSline ${ $0 = $<1; }$
- | IfStatement $$NEWLINE ${ $0 = $<1; }$
+ | IfStatement ${ $0 = $<1; }$
| Statement NEWLINE ${ $0 = $<1; }$
$RIGHT else
else if cond2:
there1 =x
there1a=x
+ if cond + cond2 :
+ hello = x;
+ hello2 = x;
+
+ sum = val +
+ val;
+
+ if condX:
+ foo = x *
+ x +
+ y
+ / two;
+ else if cond2:
+ there1 =x
+ there1a=x
there2=x
there3=x;
all = y;
if a:
if b:
c= d
+ else:
+ f=g
x = y
# File: itest.out
(mister=no);
(there=x);
(all=y);
+ if (cond+cond2):
+ (hello=x);
+ (hello2=x);
+ (sum=(val+val));
+ if condX:
+ (foo=((x*x)+(y/two)));
+ else:
+ if cond2:
+ (there1=x);
+ (there1a=x);
if (cond+cond2):
(hello=x);
(hello2=x);
if a:
if b:
(c=d);
+ else:
+ (f=g);
(x=y);