X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=blobdiff_plain;f=csrc%2Findent_test.mdc;h=960f63eb8122a2b8791952498e5c7b42832d2029;hp=699b3ca1b08c5502889526a547675579cbd05b51;hb=86e54542650f7f72a04c70618e07091f905398c8;hpb=70f81bfd8197056d800dad88ba4339fc6fad9801 diff --git a/csrc/indent_test.mdc b/csrc/indent_test.mdc index 699b3ca..960f63e 100644 --- a/csrc/indent_test.mdc +++ b/csrc/indent_test.mdc @@ -4,20 +4,27 @@ simple assignments with expressions, and then prints out the same 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 ./md2c indent_test.mdc - itest: itest.c + itest: itest.c | $(filter %.o,$(itestLDLIBS)) + $(CC) $(itestCFLAGS) $^ $(itestLDLIBS) -o $@ - demos:: itest itest.code + 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 + @sed -e 'i\ + ' itest.code > itest2.code + @./itest itest2.code| diff -u - .tmp.out || echo itest2 FAILED + demos :: doitest + tests :: checkitest # indent: header @@ -123,18 +130,17 @@ with complete bracketing and indenting. exit(0); } - # indent: grammar ~~~~~~ Program -> Statementlist ${ print_statement($1, 0); }$ -OptNL -> NEWLINE - | - $*statement + Newlines -> NEWLINE + | Newlines NEWLINE Statementlist -> Statements ${ $0 = $<1; }$ + | Newlines Statements ${ $0 = $<2; }$ Statements -> Statements Statement ${ { @@ -150,12 +156,14 @@ $*statement | ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$ Open -> { - | NEWLINE { + | Newlines { Close -> } - | NEWLINE } + | Newlines } Block -> Open Statementlist Close ${ $0 = $<2; }$ | Open SimpleStatements } ${ $0 = $<2; }$ - | : Statementlist ${ $0 = $2; $2 = NULL; }$ + | : SimpleStatements ${ $0 = $<2; }$ + | : StatementBlock ${ $0 = $<2; }$ + StatementBlock -> Statementlist $$OUT ${ $0 = $<1; }$ SimpleStatements -> SimpleStatements ; SimpleStatement ${ { @@ -177,40 +185,29 @@ $*statement $0->expr->op = $2.txt; $0->expr->right = $<3; }$ - Statement -> SimpleStatements NEWLINE ${ - $0 = $<1; - }$ - | IfStatement ${ $0 = $<1; }$ + SSline -> SimpleStatements NEWLINE ${ $0 = $<1; }$ + Statement -> SSline ${ $0 = $<1; }$ + | IfStatement $$NEWLINE ${ $0 = $<1; }$ | Statement NEWLINE ${ $0 = $<1; }$ - IfStatement -> if Expression Block OptNL ${ - $0 = calloc(1, sizeof(struct statement)); - $0->expr = $<2; - $0->thenpart = $<3; - }$ - | if Expression : SimpleStatements ${ - $0 = calloc(1, sizeof(struct statement)); - $0->expr = $<2; - $0->thenpart = $<4; - }$ - | if Expression Block OptNL else Block ${ - $0 = calloc(1, sizeof(struct statement)); - $0->expr = $<2; - $0->thenpart = $<3; - $0->elsepart = $<6; - }$ - | if Expression Block OptNL else : SimpleStatements ${ - $0 = calloc(1, sizeof(struct statement)); - $0->expr = $<2; - $0->thenpart = $<3; - $0->elsepart = $<7; - }$ - | if Expression Block OptNL else IfStatement ${ + $RIGHT else + + IfHead -> if Expression Block ${ $0 = calloc(1, sizeof(struct statement)); $0->expr = $<2; $0->thenpart = $<3; - $0->elsepart = $<6; }$ + | IfHead NEWLINE ${ $0 = $<1; }$ + + IfStatement -> IfHead $$else ${ $0 = $<1; }$ + | IfHead else Block ${ + $0 = $<1; + $0->elsepart = $<3; + }$ + | IfHead else IfStatement ${ + $0 = $<1; + $0->elsepart = $<3; + }$ $*expression Expression -> Expression + Term ${ @@ -225,7 +222,7 @@ $*expression $0->left = $<1; $0->right = $<3; }$ - | Term ${ $0 = $1; $1 = NULL; }$ + | Term ${ $0 = $<1; }$ Term -> Term * Factor ${ $0 = calloc(1, sizeof(struct expression)); $0->op = $2.txt; @@ -238,7 +235,7 @@ $*expression $0->left = $<1; $0->right = $<3; }$ - | Factor ${ $0 = $1; $1 = NULL; }$ + | Factor ${ $0 = $<1; }$ Factor -> IDENTIFIER ${ $0 = calloc(1, sizeof(struct expression)); $0->op = $1.txt; @@ -272,6 +269,7 @@ $*expression all = y; if true {yes=x;} else : no=x if true: yes = no; no = yes; + if false: yes=ok; else: no=ok if false { print = OK @@ -284,3 +282,40 @@ $*expression c= d x = y +# File: itest.out + (hello=yes); + (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); + (there2=x); + (there3=x); + (all=y); + if true: + (yes=x); + else: + (no=x); + if true: + (yes=no); + (no=yes); + if false: + (yes=ok); + else: + (no=ok); + if false: + (print=OK); + else: + (print=not_OK); + if a: + if b: + (c=d); + (x=y);