[xsmith-dev] Adding "else if" branches to if-statements

Sayilir, O.F. (Omer, Student M-CS) o.f.sayilir at student.utwente.nl
Fri Dec 22 03:51:41 MST 2023


Hello everyone,

I am currently working on a fuzzer for the language Oberon-0 using Xsmith to create synthetic language samples that are to be used as input for a grammatical inference algorithm.
I am using the “simple/javascript.rkt” file as my main source of inspiration.
I noticed that this javascript fuzzer does not have an “else if” in its definition for if-statements. As an experiment, I tried adding it myself by copying the grammar definition for if-else statements from the canned components and modifying it to generate zero-or-more “else if” branches in the if-statements. The modified definition is displayed below:

--------------------
(add-to-grammar
    javascript-comp
    [ElseIf #f ([test : Expression]
                [then : Block])
        #:prop block-user? #t
        #:prop strict-child-order? #t
        #:prop type-info [(fresh-maybe-return-type)
                        (λ (n t) (hash 'test bool-type
                                        'then t))]]

    [IfElseStatement Statement
        ([test : Expression]
        [then : Block]
        [elseif : ElseIf *]
        [else : Block])
        #:prop block-user? #t
        #:prop strict-child-order? #t
        #:prop type-info [(fresh-maybe-return-type)
                        (λ (n t) (hash 'test bool-type
                                        'then t
                                        'elseif t
                                        'else t))]])
--------------------

I am wondering if this is correct way to define this since, without the Kleene star, this definition seems to be generating code where every if-statement has an “else if” branch as it should. Once the Kleene star is added however, the fuzzer no longer seems to work as expected and outputs error messages similar to the one below.

--------------------
!!! Xsmith Error !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Error encountered while printing program!

Options:
Fuzzer: simple-javascript
Version: simple-javascript 1.0, xsmith 2.0.6 (de6ace1), in Racket 8.2 (vm-type chez-scheme)
Options: --max-depth 2
Seed: 106358447
Debug Log:
Concretizing binding b_3.  Type: #<type-variable (#<mutable (#<array-type (#<type-variable #f>)>)>)>, concretized to: #<mutable (#<array-type (#<bool>)>)>
Lifting binding "lift_4", of type #<mutable (#<array-type (#<bool>)>)>, with SN 14, caused by node with SN 13
Lifting binding "lift_6", of type #<int>, with SN 19, caused by node with SN 18
Lifting binding "lift_7", of type #<bool>, with SN 25, caused by node with SN 22
Lifting binding "lift_8", of type #<string>, with SN 29, caused by node with SN 27
Lifting binding "lift_9", of type #<string>, with SN 32, caused by node with SN 30
Lifting binding "lift_10", of type #<string>, with SN 34, caused by node with SN 33
Lifting binding "lift_11", of type #<string>, with SN 36, caused by node with SN 35
Lifting binding "lift_12", of type #<mutable (#<structural-record-type final?:#t, fields: #hash()>)>, with SN 41, caused by node with SN 39


Exception:
RACR exception: "AG evaluator exception;" "Unexpected" 'xsmith_render-node "cycle."

Program output captured:
--------------------

My apologies if this is an obvious question, I am still new to the world of Racket and RACR an Xsmith and I could not find an example of something similar in the examples folder in the git repository.

Kind regards,
Ömer Sayilir

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </listarchives/xsmith-dev/attachments/20231222/b1d3173b/attachment.html>


More information about the xsmith-dev mailing list