How to use SDF {avoid} in MPL fraudster

I am trying to create island grammar using Rascal MPL , but I ran into a problem:

When implementing Island Grammar in SDF, a very common approach is to define "all water production" using the {avoid} attribute. This prevents the parser from using these products, if others are applicable. This allows you to specify default behavior that can be overridden by other manufacturing processes without creating bumps. A very simple example:

context free syntax
    Chunk*         -> Input
    Water          -> Chunk
lexical syntax
    ~[\t\n\ ]+   -> Water {avoid}  // avoid the Water production

I tried to reproduce this behavior using Rascal MPL. My goal is to create an island grammar that collects all conditional preprocessor directives inside a piece of C / C ++ code and skips the rest of the input using Water production.

layout LAYOUT = [\t\n\ ];
lexical WATER = ![\t\n\ ]+;

start syntax Program = Line*;       // program consists of lines

syntax Line = ConditionalDirective  // preprocessor directives
            > WATER;                // catch-all option

syntax ConditionalDirective = "#ifdef" 
                            | "#ifndef"
                            | "#if"
                            | "#elif";

{avoid}, ConditionalDirective , " > ", . .

#ifdef asd

, , , :

ambiguous parse tree

Rascal Documentation, "" - , . , , , SDF .

SDF {avoid} MPL? - , ?

+4
1

: sdf2 . , . https://github.com/cwi-swat/rascal/blob/master/src/org/rascalmpl/library/lang/sdf2/filters/PreferAvoid.rsc , sdf2, , . @avoid @prefer, sdf2, .

: , , , sdf2, . , , . . , - .

, , . , .

- \! -. . . , , .

+2

All Articles