iXML Community Group Test Suite

23 Oct 2023 (22 Nov 2023)

Top-level catalog for tests in the iXML Community Group Test Suite.

Tests have been contributed from several sources, but the core of the test collection are the tests contributed by Steven Pemberton in December 2021.

Misc tests 3

28 Jun 2022

Grammars 41-60.

Tests compiled manually in 2018 and 2019, re-packaged and extended (supplying test cases where needed) in 2022.

Note that some tests have alternate results for processors operating in non-standard modes, in particular modes in which they tolerate multiple definitions and undefined nonterminals or in which they do not tolerate non-productive nonterminals or unreachable nonterminals.

For a description of the form in which alternate results are recorded, see tests/misc-grammar/test-catalog.xml.

sample.grammar.41ter

Created 08 Feb 2022 by cmsmcq

Sample grammar derived from one in Niklaus Wirth, Grundlagen und Techniken des Compilerbaus (Bonn: Addison-Wesley, 1996), pp. 36-37.

Derived from sample.grammar.41bis by rewriting the expression syntax so that nonterminals are visible in the XML only when needed to group multiple children and invisible if they have only one child.

Invisible XML Grammar

{ Sample grammar from Niklaus Wirth, Grundlagen und Techniken des
Compilerbaus (Bonn: Addison-Wesley, 1996), pp. 36-37.

Oberon-0.

Rules for ws added for convenience; Wirth assumes the lexer
eats whitespace. }

{ Revisions:
  2022-06-15 : CMSMcQ : Use the Lumley construction to trim expressions.
  2022-06-15 : CMSMcQ : revise S handling again (leading ws pattern).
                        Make selector and procedures reject epsilon
                        for clarity in the output
  2022-06-14 : CMSMcQ : revise S handling (tight tags, where possible).
                        Hide most literals, use pre-terminal symbols.
  2018-08-10 : CMSMcQ : correct syntax errors found by DCG parser
  2018-08-09 : CMSMcQ : made first transcription; needs testing, since
      the translation from Wirth's EBNF is error-prone.
}

{ We move the rule for module to the front, since it is the
start symbol. }

            module = S?, -"MODULE", S, @ident, -";", S?,
                     declarations,
                     (-"BEGIN", S?, StatementSequence)?,
                     -"END", S, @ident_close, -".", S?.
    
             ident = letter, (letter; digit)*, S?.
       ident_close = ident.
           integer = digit, (digit)*, S?.
          selector = (member; subscript)+.
	    member = -".", S?, ident.
	 subscript = -"[", S?, EXPRESSION, -"]", S?.
         {selector = (".", S?, ident; "[", S?, expression, "]", S?)*.}
           -number = integer.
           -FACTOR = ident
	           ; number
		   ; -"(", S?, EXPRESSION, -")", S?
		   ; factor
		   .
            factor = ident, selector
	           ; "~", S?, FACTOR
		   .
             -TERM = FACTOR; term.
              term = FACTOR, (TIMES; DIV; MOD; AND), FACTOR++(TIMES; DIV; MOD; AND).
             {term = factor++(TIMES; DIV; MOD; AND).}
	      
 -SIMPLEEXPRESSION =  (PLUS; MINUS)?, TERM; SimpleExpression.
  SimpleExpression =  (PLUS; MINUS)?, TERM, (PLUS; MINUS; OR), TERM++(PLUS; MINUS; OR).
 {SimpleExpression =  (PLUS; MINUS)?, term++(PLUS; MINUS; OR).}

    { N.B. Simplexpression allows 1, -1, 1 + 1,
      -1 + 1, but not 1 + -1.
      I expect that's intentional.
      I've made it also forbid white space between sign and term.
    }    
 
       -EXPRESSION = SIMPLEEXPRESSION; expression.
        expression = SIMPLEEXPRESSION, -COMPARATOR, SIMPLEEXPRESSION.
       {expression = SimpleExpression, (-COMPARATOR, SimpleExpression)?.}
       -COMPARATOR = EQL; NEQ; LSS; LEQ; GTR; GEQ.
        assignment = ident, selector?, -":=", S?, EXPRESSION.
  ActualParameters = -"(", S?, EXPRESSION**(-",", S?), -")", S?.
     ProcedureCall = ident, selector?, ActualParameters?.
       IfStatement = -"IF", S?, condition, 
                     -"THEN", S?, then-stmts,
                     (-"ELSIF", S?, condition, 
		     -"THEN", S?, then-stmts)*,
                     (-"ELSE", S?, else-stmts)?,
		     -"END", S?.
         condition = -EXPRESSION.
        then-stmts = -StatementSequence.
        else-stmts = -StatementSequence.
    WhileStatement = -"WHILE", S?, condition, 
                     -"DO", S?, do-statements,
		     -"END", S?.
     do-statements = -StatementSequence.

         statement = {}
	 	   ; assignment
		   ; ProcedureCall
		   ; IfStatement
		   ; WhileStatement
		   .
 StatementSequence = statement++(-";", S?).
 
 { Wirth's formulation is closer to the following, but that complicates whitespace
   handling. 

         statement = (assignment; ProcedureCall; IfStatement; WhileStatement)?.
 StatementSequence = statement++SEMI.
 }

         IdentList = ident++(-",", S?).
         ArrayType = -"ARRAY", S?, EXPRESSION, -"OF", S?, type.
         FieldList = (IdentList, -":", S?, type)?.
        RecordType = -"RECORD", S?, FieldList++(-";", S?), -"END", S?.
              type = ident
	           ; ArrayType
		   ; RecordType
		   .
         FPSection = (-"VAR", S)?, IdentList, -":", S?, type.
  FormalParameters = -"(", S?, FPSection**(-";", S?), -")", S?.
  ProcedureHeading = -"PROCEDURE", S, ident, FormalParameters?.
     ProcedureBody = declarations, 
                     (-"BEGIN", S?, StatementSequence)?,
		     -"END", S, @ident.
ProcedureDeclaration
                   = ProcedureHeading, -";", S?, ProcedureBody.
      declarations = constants?, types?, variables?, procedures?.
         constants = -"CONST", S, (ident, -"=", S?, EXPRESSION, -";", S?)*.
             types = -"TYPE", S, (IdentList, -"=", S?, type, -";", S?)*.
         variables = -"VAR", S, (IdentList, -":", S?, type, -";", S?)*.
        procedures = (ProcedureDeclaration, -";", S?)+.

{ S and comment added here to make the grammar usable without
  a scanner. N.B. Comments nest. }
                -S = (ws; comment)+.
               -ws = -[" "; #09; #0A; #0D].

           comment = -"(*", comment-body, -"*)".
      comment-body = comment-chars, ((comment++comment-chars), comment-chars?)?.
    -comment-chars = (cc1; cc2; cc3)+, star*, lpar* | star+, lpar* | lpar+.
              -cc1 = not-star-or-lpar.
              -cc2 = lpar+, not-star-or-lpar.
	      -cc3 = star+, lpar+, not-star-or-lpar
                   | star+, not-star-or-lrpar.
 -not-star-or-lpar = ~["*("].
-not-star-or-lrpar = ~["(*)"].
             -lpar = "(".
	     -star = "*".

            -digit = ['0'-'9'].
           -letter = ['a'-'z'; 'A'-'Z'].

             TIMES = -"*", S?.
	       DIV = -"DIV", S?.
	       MOD = -"MOD", S?.
	       AND = -"AND", S?.
	      PLUS = -"+", S?.
	     MINUS = -"-", S?.
	        OR = -"OR", S?.
               EQL = -"=", S?.
	       NEQ = -"#", S?.
	       LSS = -"<", S?.
	       LEQ = -"<=", S?.
	       GTR = -">", S?.
	       GEQ = -">=", S?.

{ Separators }

Test case: g41ter.c00

Repository URI: …/tests/misc/misc-041-060-catalog.xml

Created 15 Jun 2022 by cmsmcq

Sample Oberon-0 module from the same source as the grammar, pp. 37-38.

Input string (889 characters)

MODULE Samples;
(* Wirth 1995, pp. 37-38 *)

PROCEDURE Multiply;
  VAR x, y, z: INTEGER;
BEGIN Read(x); Read(y); z := 0;
  WHILE x > 0 DO
    IF x MOD 2 = 1 THEN z := z + y END ;
    y := 2*y; x := x DIV 2
  END ;
  Write(x); Write(y); Write(z); WriteLn
END Multiply;

PROCEDURE Divide;
  VAR x, y, r, q, w: INTEGER;
BEGIN Read(x); Read(y); r := x; q := 0; w := y;
  WHILE w <= r DO w := 2*w END ;
  WHILE w > y DO
    q := 2*q; w := w DIV 2;
    IF w <= r THEN r := r - w; q := q + 1 END
  END ;
  Write(x); Write(y); Write(q); Write(r); WriteLn
END Divide;

PROCEDURE BinSearch;
  VAR i, j, k, n: INTEGER;
    a: ARRAY 32 OF INTEGER;
BEGIN Read(n); k := 0;
  WHILE k < n DO Read(a[k]); k := k + 1 END ;
  i := 0; j := n;
  WHILE i < j DO
    k := (i+j) DIV 2;
    IF x < a[k] THEN j := k ELSE i := k + 1 END
  END ;
  Write(i); Write(j); Write(a[j]); WriteLn
END BinSearch;

END Samples.

Expected result

<module ident="Samples" ident_close="Samples">
   <comment>
      <comment-body> Wirth 1995, pp. 37-38 </comment-body>
   </comment>
   <declarations>
      <procedures>
         <ProcedureDeclaration>
            <ProcedureHeading>
               <ident>Multiply</ident>
            </ProcedureHeading>
            <ProcedureBody ident="Multiply">
               <declarations>
                  <variables>
                     <IdentList>
                        <ident>x</ident>
                        <ident>y</ident>
                        <ident>z</ident>
                     </IdentList>
                     <type>
                        <ident>INTEGER</ident>
                     </type>
                  </variables>
               </declarations>
               <StatementSequence>
                  <statement>
                     <ProcedureCall>
                        <ident>Read</ident>
                        <ActualParameters>
                           <ident>x</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Read</ident>
                        <ActualParameters>
                           <ident>y</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <assignment>
                        <ident>z</ident>
                        <integer>0</integer>
                     </assignment>
                  </statement>
                  <statement>
                     <WhileStatement>
                        <condition>
                           <expression>
                              <ident>x</ident>
                              <GTR/>
                              <integer>0</integer>
                           </expression>
                        </condition>
                        <do-statements>
                           <statement>
                              <IfStatement>
                                 <condition>
                                    <expression>
                                       <term>
                                          <ident>x</ident>
                                          <MOD/>
                                          <integer>2</integer>
                                       </term>
                                       <EQL/>
                                       <integer>1</integer>
                                    </expression>
                                 </condition>
                                 <then-stmts>
                                    <statement>
                                       <assignment>
                                          <ident>z</ident>
                                          <SimpleExpression>
                                             <ident>z</ident>
                                             <PLUS/>
                                             <ident>y</ident>
                                          </SimpleExpression>
                                       </assignment>
                                    </statement>
                                 </then-stmts>
                              </IfStatement>
                           </statement>
                           <statement>
                              <assignment>
                                 <ident>y</ident>
                                 <term>
                                    <integer>2</integer>
                                    <TIMES/>
                                    <ident>y</ident>
                                 </term>
                              </assignment>
                           </statement>
                           <statement>
                              <assignment>
                                 <ident>x</ident>
                                 <term>
                                    <ident>x</ident>
                                    <DIV/>
                                    <integer>2</integer>
                                 </term>
                              </assignment>
                           </statement>
                        </do-statements>
                     </WhileStatement>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>x</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>y</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>z</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>WriteLn</ident>
                     </ProcedureCall>
                  </statement>
               </StatementSequence>
            </ProcedureBody>
         </ProcedureDeclaration>
         <ProcedureDeclaration>
            <ProcedureHeading>
               <ident>Divide</ident>
            </ProcedureHeading>
            <ProcedureBody ident="Divide">
               <declarations>
                  <variables>
                     <IdentList>
                        <ident>x</ident>
                        <ident>y</ident>
                        <ident>r</ident>
                        <ident>q</ident>
                        <ident>w</ident>
                     </IdentList>
                     <type>
                        <ident>INTEGER</ident>
                     </type>
                  </variables>
               </declarations>
               <StatementSequence>
                  <statement>
                     <ProcedureCall>
                        <ident>Read</ident>
                        <ActualParameters>
                           <ident>x</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Read</ident>
                        <ActualParameters>
                           <ident>y</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <assignment>
                        <ident>r</ident>
                        <ident>x</ident>
                     </assignment>
                  </statement>
                  <statement>
                     <assignment>
                        <ident>q</ident>
                        <integer>0</integer>
                     </assignment>
                  </statement>
                  <statement>
                     <assignment>
                        <ident>w</ident>
                        <ident>y</ident>
                     </assignment>
                  </statement>
                  <statement>
                     <WhileStatement>
                        <condition>
                           <expression>
                              <ident>w</ident>
                              <LEQ/>
                              <ident>r</ident>
                           </expression>
                        </condition>
                        <do-statements>
                           <statement>
                              <assignment>
                                 <ident>w</ident>
                                 <term>
                                    <integer>2</integer>
                                    <TIMES/>
                                    <ident>w</ident>
                                 </term>
                              </assignment>
                           </statement>
                        </do-statements>
                     </WhileStatement>
                  </statement>
                  <statement>
                     <WhileStatement>
                        <condition>
                           <expression>
                              <ident>w</ident>
                              <GTR/>
                              <ident>y</ident>
                           </expression>
                        </condition>
                        <do-statements>
                           <statement>
                              <assignment>
                                 <ident>q</ident>
                                 <term>
                                    <integer>2</integer>
                                    <TIMES/>
                                    <ident>q</ident>
                                 </term>
                              </assignment>
                           </statement>
                           <statement>
                              <assignment>
                                 <ident>w</ident>
                                 <term>
                                    <ident>w</ident>
                                    <DIV/>
                                    <integer>2</integer>
                                 </term>
                              </assignment>
                           </statement>
                           <statement>
                              <IfStatement>
                                 <condition>
                                    <expression>
                                       <ident>w</ident>
                                       <LEQ/>
                                       <ident>r</ident>
                                    </expression>
                                 </condition>
                                 <then-stmts>
                                    <statement>
                                       <assignment>
                                          <ident>r</ident>
                                          <SimpleExpression>
                                             <ident>r</ident>
                                             <MINUS/>
                                             <ident>w</ident>
                                          </SimpleExpression>
                                       </assignment>
                                    </statement>
                                    <statement>
                                       <assignment>
                                          <ident>q</ident>
                                          <SimpleExpression>
                                             <ident>q</ident>
                                             <PLUS/>
                                             <integer>1</integer>
                                          </SimpleExpression>
                                       </assignment>
                                    </statement>
                                 </then-stmts>
                              </IfStatement>
                           </statement>
                        </do-statements>
                     </WhileStatement>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>x</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>y</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>q</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>r</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>WriteLn</ident>
                     </ProcedureCall>
                  </statement>
               </StatementSequence>
            </ProcedureBody>
         </ProcedureDeclaration>
         <ProcedureDeclaration>
            <ProcedureHeading>
               <ident>BinSearch</ident>
            </ProcedureHeading>
            <ProcedureBody ident="BinSearch">
               <declarations>
                  <variables>
                     <IdentList>
                        <ident>i</ident>
                        <ident>j</ident>
                        <ident>k</ident>
                        <ident>n</ident>
                     </IdentList>
                     <type>
                        <ident>INTEGER</ident>
                     </type>
                     <IdentList>
                        <ident>a</ident>
                     </IdentList>
                     <type>
                        <ArrayType>
                           <integer>32</integer>
                           <type>
                              <ident>INTEGER</ident>
                           </type>
                        </ArrayType>
                     </type>
                  </variables>
               </declarations>
               <StatementSequence>
                  <statement>
                     <ProcedureCall>
                        <ident>Read</ident>
                        <ActualParameters>
                           <ident>n</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <assignment>
                        <ident>k</ident>
                        <integer>0</integer>
                     </assignment>
                  </statement>
                  <statement>
                     <WhileStatement>
                        <condition>
                           <expression>
                              <ident>k</ident>
                              <LSS/>
                              <ident>n</ident>
                           </expression>
                        </condition>
                        <do-statements>
                           <statement>
                              <ProcedureCall>
                                 <ident>Read</ident>
                                 <ActualParameters>
                                    <factor>
                                       <ident>a</ident>
                                       <selector>
                                          <subscript>
                                             <ident>k</ident>
                                          </subscript>
                                       </selector>
                                    </factor>
                                 </ActualParameters>
                              </ProcedureCall>
                           </statement>
                           <statement>
                              <assignment>
                                 <ident>k</ident>
                                 <SimpleExpression>
                                    <ident>k</ident>
                                    <PLUS/>
                                    <integer>1</integer>
                                 </SimpleExpression>
                              </assignment>
                           </statement>
                        </do-statements>
                     </WhileStatement>
                  </statement>
                  <statement>
                     <assignment>
                        <ident>i</ident>
                        <integer>0</integer>
                     </assignment>
                  </statement>
                  <statement>
                     <assignment>
                        <ident>j</ident>
                        <ident>n</ident>
                     </assignment>
                  </statement>
                  <statement>
                     <WhileStatement>
                        <condition>
                           <expression>
                              <ident>i</ident>
                              <LSS/>
                              <ident>j</ident>
                           </expression>
                        </condition>
                        <do-statements>
                           <statement>
                              <assignment>
                                 <ident>k</ident>
                                 <term>
                                    <SimpleExpression>
                                       <ident>i</ident>
                                       <PLUS/>
                                       <ident>j</ident>
                                    </SimpleExpression>
                                    <DIV/>
                                    <integer>2</integer>
                                 </term>
                              </assignment>
                           </statement>
                           <statement>
                              <IfStatement>
                                 <condition>
                                    <expression>
                                       <ident>x</ident>
                                       <LSS/>
                                       <factor>
                                          <ident>a</ident>
                                          <selector>
                                             <subscript>
                                                <ident>k</ident>
                                             </subscript>
                                          </selector>
                                       </factor>
                                    </expression>
                                 </condition>
                                 <then-stmts>
                                    <statement>
                                       <assignment>
                                          <ident>j</ident>
                                          <ident>k</ident>
                                       </assignment>
                                    </statement>
                                 </then-stmts>
                                 <else-stmts>
                                    <statement>
                                       <assignment>
                                          <ident>i</ident>
                                          <SimpleExpression>
                                             <ident>k</ident>
                                             <PLUS/>
                                             <integer>1</integer>
                                          </SimpleExpression>
                                       </assignment>
                                    </statement>
                                 </else-stmts>
                              </IfStatement>
                           </statement>
                        </do-statements>
                     </WhileStatement>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>i</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <ident>j</ident>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>Write</ident>
                        <ActualParameters>
                           <factor>
                              <ident>a</ident>
                              <selector>
                                 <subscript>
                                    <ident>j</ident>
                                 </subscript>
                              </selector>
                           </factor>
                        </ActualParameters>
                     </ProcedureCall>
                  </statement>
                  <statement>
                     <ProcedureCall>
                        <ident>WriteLn</ident>
                     </ProcedureCall>
                  </statement>
               </StatementSequence>
            </ProcedureBody>
         </ProcedureDeclaration>
      </procedures>
   </declarations>
</module>