lassenielsen / libdpl

Dynamic Parser Library
http://thelas.dk/index.php/DynParser
1 stars 0 forks source link

Can it accept EBNF ? #1

Open mingodad opened 3 years ago

mingodad commented 3 years ago

I'm collecting grammars in EBNF format accepted by https://www.bottlecaps.de/rr/ui and I'm looking for a dynamic parser to allow write/test grammars in EBNF and found your project.

I'm asking how hard would be to make it accept EBNF ?

Look bellow how the grammar from your https://github.com/lassenielsen/hapi after manually modified to EBNF would look like, you can copy and paste in https://www.bottlecaps.de/rr/ui in the Edit Grammar tab and switch to View Diagram tab to see a navigable railroad diagram.

//# Processes (Main / Root production)
Pi ::=   Pi2 '||' Pi
     |    Pi2

Pi2 ::=    PiActs '|' Pi2
      |   PiActs
      |  PiEActs

//# Statement sequence
PiActs ::=  PiTerm
         |  PiAct PiActs

PiEActs ::=  PiEAct
          |  PiAct PiEActs

//# Process Statements
PiAct ::=  Ch Sends ';'
        |  Ch Recvs ';'
        |   id '<<' Mtype ';'
        |   id '>>' nlvar ';'
        |  id '>>' lvar ';'
        |   id '=' 'new' id '(' int 'of' int ')' ';'
        |    Gtype Ids '(' Participants ')' ';'
        |     Gtype id '(' Participants ')' ';'
        |    Mtype id '=' Exp ';'
        |  id '=' Exp ';'
        |    'private+local' Mode pvar Dargs '(' Args ')' '(' Pi ')'
        |   'private+local' Mode  'service' pvar  '(' id  '(' int 'of' int  ')' id  ')' '(' Pi  ')'
        //  :-> :"local ::mode ::name ( ) ( global ::session = new ::channel ( ::pid of ::pids ); ::name (); | ( ::body ) ) local ::mode StartService(Int i) (if i<=0 then ::name (); else ( ::name (); | StartService(i-1); ) ) StartService(SYSTEM&\"tprocs\");"
        |   'guivalue' '(' Exps ')' ';'
        |  'HOST' '(' Exps ')' Mode ';'
        |  'HOSTHEADER' '(' Exps ')' ';'

//# Extended statements (for associativity)
PiEAct ::=   'public+global' id '=' 'new' id '(' int 'of' int ')' ';' Pi2
         |    'public+global' Gtype Ids '(' Participants ')' ';' Pi2
         |     'public+global' Gtype id '(' Participants ')' ';' Pi2
         |    'public+global' Mtype id '=' Exp ';' Pi2
         |  'public+global' id '=' Exp ';' Pi2
         |    'public+global' Mode pvar Dargs '(' Args ')' '(' Pi ')' Pi2
         |   'public+global' Mode  'service' pvar  '(' id  '(' int 'of' int  ')' id  ')' '(' Pi  ')' Pi2
         // :-> :"global ::mode ::name ( ) ( global ::session = new ::channel ( ::pid of ::pids ); ::name (); | ( ::body ) ) local ::mode StartService(Int i) (if i<=0 then ::name (); else ( ::name (); | StartService(i-1); ) ) StartService(SYSTEM&\"tprocs\"); | ::succ"

//# Non-sequential process constructions (branching termination etc.
PiTerm ::=    '(' Pi ')'
         |
         |  pvar Dexps '(' Exps ')' ';'
         |    if Exp then Pi else PiActs
         |    Ch '>>' '{' Branches '}'
         |   'sync' '(' Exps ')' '{' Branches '}'
         |  'guisync' '(' Exps ')' '{' Inputbranches '}'

//# Global Types
Gtype ::=  Gterm
        |   Gact Gtype
Gact ::=     int '->' int ':' Mtype NamedAssertion ';'
       |     'rec' gvar Targs ';'
       |  int ':' nlvar ';'
       |   int ':' lvar ';'
Gterm ::=     '$end' ';'
        |    gvar Tvals ';'
        |  int '->' int '{' Gbranches '}'
        |   '{' Gbranches '}'
Gbranches ::=   bid Assertion ':' Gtype
            |  bid Assertion ':' Gtype Gbranches

//# Local Types
Ltype ::=  Lterm
        |  Lact Ltype
Lact ::=     int '<<' Mtype NamedAssertion ';'
       |     int '>>' Mtype NamedAssertion ';'
       |  'forall' id 'where' Exp ';'
       |  '<<' nlvar ';'
       |  '>>' nlvar ';'
       |   '<<' lvar ';'
       |   '>>' lvar ';'
       |     'rec' lvar Targs ';'
Lterm ::=  int '<<' '{' Lbranches '}'
        |  int '>>' '{' Lbranches '}'
        |  lvar Tvals ';'
        |   '%end' ';'
        |  '{' Lbranches '}'
Lbranches ::=   bid Assertion ':' Ltype
            |  bid Assertion ':' Ltype Lbranches

//# Message (value) Types
Mtype ::=  Stype
        |  Gtype '(' Participants ')'
        |  nlvar
        |  Ltype '(' int 'of' Participants ')'
        |  Gtype '(' int 'of' Participants ')'
Stype ::=     'Int'
        |   'Float'
        |  'String'
        |    'Bool'
        |   '(' Stypes ')'
Stypes ::=  Stypes2
         |
Stypes2 ::=  Stype ',' Stypes2
          |  Stype

//# Expressions (value)
Exp  ::=       'if' Exp 'then' Exp 'else' Exp
       |      Exp2
Exp2 ::=       Exp3 '=' Exp2
       |      Exp3
Exp3 ::=      Exp4 '<=' Exp3
       |      Exp4 '>=' Exp3
       |       Exp4 '<' Exp3
       |      Exp4
Exp4 ::=     Exp5 '+' Exp4
       |      Exp5
Exp5 ::=    Exp6 '-' Exp5
       |      Exp6
Exp6 ::=     Exp7 '*' Exp6
       |      Exp7
Exp7 ::=      Exp8 '/' Exp7
       |      Exp8
Exp8 ::=      Exp9 'and' Exp8
       |      Exp9
Exp9 ::=       Exp10 'or' Exp9
       |      Exp10
Exp10 ::=     Exp10 '&' int
        |     Exp11
Exp11 ::=     'not' Exp11
        |     Exp12
Exp12 ::=      id
        |     int
        |   float
        |     string
        |    'true'
        |   'false'
        |   '(' Exps ')'
        |     'SYSTEM' '&' string
Exps ::=   Exps2
       |
Exps2 ::=   Exp
        |  Exp ',' Exps2

//# Leftovers / details
Ch ::=  id '[' int ']'
Participant ::= int Mode
Ids ::=  id ',' Ids2
Ids2 ::=  id
       |  id ',' Ids2
Participants ::=   Participant
               |  Participant ',' Participants
Assertion ::=  'where' Exp
            |
NamedAssertion ::=  'as' id Assertion
                 |
Branch ::=  bid Assertion ':' Pi
Branches ::=   Branch
           |  Branch Branches
Inputbranch ::=  bid Assertion ( Targs2 ) ':' Pi
Inputbranches ::=   Inputbranch
                |  Inputbranch Inputbranches
Args ::=  Args2
       |
Args2 ::=   Mtype id
        |  Mtype id ',' Args2
Dargs ::=  '<' Args2 '>'
        |
Dexps ::=  '<' Exps '>'
        |
Mode ::=
       |  'pure'
       |  'impure'
Send ::=  '<<' Exp
       |  '<<' bid
Sends ::=  Send
        |  Send Sends
Recv ::=  '>>' id
       |  '>>' id '(' int 'of' int ')'
Recvs ::=  Recv
        |  Recv Recvs
Tvals ::=  '<' Exps '>'
        |
Targ ::=  Mtype id '=' Exp
Targs ::=  '<' Targs2 '>'
        |
Targs2 ::=  Targ
         |  Targ ',' Targs2
mingodad commented 3 years ago

Other related projects I found: https://github.com/mpailab/CFG-parser https://github.com/kthielen/ww https://github.com/waywardgeek/not_rune https://github.com/waywardgeek/parse42 https://github.com/izuzanak/yapgen https://tree-sitter.github.io/ https://github.com/FransFaase/IParse https://github.com/gotthardp/bnfparser2