convert R code to BNF form ( Backus–Naur form )

78 views Asked by At

I am a complete newbie at this and may be my question is stupid, I apologize in advance. I want to convert any piece of code to BNF form.

https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form

For example, here is some code (code can be completely different)

m = NULL
for(i in 1:10){
  m[i] = i 
}

I want to get something like this

<expr> ::=  <var><equ><null> ;
            for(<iter> in <vec>) { 
               <var><br><equ><iter>}
                               
<var>  ::= m
<equ>  ::= =
<br>   ::= [i]
<vec>  ::= 1:10
<iter> ::= i
<null> ::= NULL

There may be errors in my BNF form, take this as an illustration of what I would like to receive, and not as an exact example

I would like to get an example of how this is generally done

===== upd =====

I'm using grammatical evolution gramEvol package to find useful expressions (R code)

vignette

features of this package

  1. takes the BNF form as input
  2. generates different expressions
  3. checks expressions against the fitness function

I would like to be able to generate the BNF for this package from my relatively small chunks of real R code.

0

There are 0 answers