]> ocean-lang.org Git - ocean/blobdiff - csrc/indent_test.mdc
parsergen: add more power to symbol references in generated code
[ocean] / csrc / indent_test.mdc
index 88e93914aa6f88a7b49638e230c3d99e372019eb..fddb64b7520a15931b430075406c2853f056fef3 100644 (file)
@@ -4,17 +4,16 @@ 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 $@
 
        doitest: itest itest.code
                ./itest itest.code
@@ -115,8 +114,6 @@ with complete bracketing and indenting.
                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 = "",
@@ -135,11 +132,15 @@ with complete bracketing and indenting.
 
 ~~~~~~
 
+$TERM if { } : * + - / ; =
+
 Program -> Statementlist ${ print_statement($1, 0); }$
 
 $*statement
-       Statementlist ->  Statements ${ $0 = $<1; }$
-               | NEWLINE Statementlist ${ $0 = $<2; }$
+       Newlines -> NEWLINE
+               | Newlines NEWLINE
+       Statementlist ->  Statements ${ $0 = $<S; }$
+               | Newlines Statements ${ $0 = $<S1; }$
 
        Statements -> Statements Statement ${
                                {
@@ -155,23 +156,23 @@ $*statement
                        | ERROR ${ printf("statement ERROR\n"); $0 = NULL; }$
 
        Open -> {
-               | NEWLINE Open
+               | Newlines {
        Close -> }
-               | NEWLINE Close
-       Block -> Open Statementlist Close ${ $0 = $<2; }$
-               | Open SimpleStatements } ${ $0 = $<2; }$
-               | : SimpleStatements $$NEWLINE ${ $0 = $<2; }$
-               | : StatementBlock ${ $0 = $<2; }$
-       StatementBlock -> Statementlist $$OUT ${ $0 = $<1; }$
+               | Newlines }
+       Block -> Open Statementlist Close ${ $0 = $<S; }$
+               | Open SimpleStatements } ${ $0 = $<S; }$
+               | : SimpleStatements ${ $0 = $<SS; }$
+               | : StatementBlock ${ $0 = $<SB; }$
+       StatementBlock -> Statementlist $$OUT ${ $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; }$
@@ -185,9 +186,9 @@ $*statement
                        $0->expr->right = $<3;
                        }$
        SSline -> SimpleStatements NEWLINE ${ $0 = $<1; }$
-               | SSline NEWLINE ${ $0 = $<1; }$
        Statement -> SSline ${ $0 = $<1; }$
-               | IfStatement ${ $0 = $<1; }$
+               | IfStatement $$NEWLINE ${ $0 = $<1; }$
+               | Statement NEWLINE ${ $0 = $<1; }$
 
        $RIGHT else
 
@@ -197,20 +198,16 @@ $*statement
                                $0->thenpart = $<3;
                                }$
                | IfHead NEWLINE ${ $0 = $<1; }$
-       IfTail -> else Block ${ $0 = $<2; }$
-               | IfTail NEWLINE ${ $0 = $<1; }$
 
        IfStatement -> IfHead $$else ${ $0 = $<1; }$
-               | IfHead IfTail ${
+               | IfHead else Block ${
                        $0 = $<1;
-                       $0->elsepart = $<2;
+                       $0->elsepart = $<3;
                        }$
                | IfHead else IfStatement ${
                        $0 = $<1;
                        $0->elsepart = $<3;
                        }$
-               | IfStatement NEWLINE ${ $0 = $<1; }$
-
 
 $*expression
        Expression -> Expression + Term ${
@@ -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
@@ -309,6 +307,10 @@ $*expression
        if true:
            (yes=no);
            (no=yes);
+       if false:
+           (yes=ok);
+       else:
+           (no=ok);
        if false:
            (print=OK);
        else: