Skip to content

Grammar railroad diagram #1503

@mingodad

Description

@mingodad

I just added the nasl grammar to https://mingodad.github.io/parsertl-playground/playground/ (an online Yacc/Lex editor/tester, select NASL parser from Examples then click Parse to see a parser tree for the content in Input source editor).
It also generate an EBNF accepted by https://www.bottlecaps.de/rr/ui to generate a nice navigable railroad diagram, follow the instructions shown bellow.

Any feedback is welcome !

//
// EBNF to be viewd at https://www.bottlecaps.de/rr/ui
//
// Copy and paste this at https://www.bottlecaps.de/rr/ui in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//

tiptop::=
	  instr_decl_list

instr_decl_list::=
	  instr_decl
	| instr_decl_list instr_decl

instr_decl::=
	  instr
	| func_decl

func_decl::=
	  FUNCTION identifier '(' arg_decl ')' block

arg_decl::=
	  /*%empty*/
	| arg_decl_1

arg_decl_1::=
	  identifier
	| arg_decl_1 ',' identifier

block::=
	  '{' instr_list '}'
	| '{' '}'

instr_list::=
	  instr
	| instr_list instr

instr::=
	  simple_instr ';'
	| block
	| if_block
	| loop

simple_instr::=
	  aff
	| post_pre_incr
	| rep
	| func_call
	| ret
	| inc
	| loc
	| glob
	| BREAK
	| CONTINUE
	| /*%empty*/

ret::=
	  RETURN expr
	| RETURN

if_block::=
	  IF '(' expr ')' instr
	| IF '(' expr ')' instr ELSE instr

loop::=
	  for_loop
	| while_loop
	| repeat_loop
	| foreach_loop

for_loop::=
	  FOR '(' aff_func ';' expr ';' aff_func ')' instr

while_loop::=
	  WHILE '(' expr ')' instr

repeat_loop::=
	  REPEAT instr UNTIL expr ';'

foreach_loop::=
	  FOREACH identifier '(' expr ')' instr

aff_func::=
	  aff
	| post_pre_incr
	| func_call
	| /*%empty*/

rep::=
	  func_call REP expr

string::=
	  STRING1
	| STRING2

inc::=
	  INCLUDE '(' string ')'

func_call::=
	  identifier '(' arg_list ')'

arg_list::=
	  arg_list_1
	| /*%empty*/

arg_list_1::=
	  arg
	| arg_list_1 ',' arg

arg::=
	  expr
	| identifier ':' expr

aff::=
	  lvalue '=' expr
	| lvalue PLUS_EQ expr
	| lvalue MINUS_EQ expr
	| lvalue MULT_EQ expr
	| lvalue DIV_EQ expr
	| lvalue MODULO_EQ expr
	| lvalue R_SHIFT_EQ expr
	| lvalue R_USHIFT_EQ expr
	| lvalue L_SHIFT_EQ expr

lvalue::=
	  identifier
	| array_elem

identifier::=
	  IDENT
	| REP

array_elem::=
	  identifier '[' array_index ']'

array_index::=
	  expr

post_pre_incr::=
	  PLUS_PLUS lvalue
	| MINUS_MINUS lvalue
	| lvalue PLUS_PLUS
	| lvalue MINUS_MINUS

expr::=
	  '(' expr ')'
	| expr AND expr
	| '!' expr
	| expr OR expr
	| expr '+' expr
	| expr '-' expr
	| '-' expr
	| '~' expr
	| expr '*' expr
	| expr EXPO expr
	| expr '/' expr
	| expr '%' expr
	| expr '&' expr
	| expr '^' expr
	| expr '|' expr
	| expr R_SHIFT expr
	| expr R_USHIFT expr
	| expr L_SHIFT expr
	| post_pre_incr
	| expr MATCH expr
	| expr NOMATCH expr
	| expr RE_MATCH string
	| expr RE_NOMATCH string
	| expr '<' expr
	| expr '>' expr
	| expr EQ expr
	| expr NEQ expr
	| expr SUPEQ expr
	| expr INFEQ expr
	| var
	| aff
	| ipaddr
	| atom
	| const_array

const_array::=
	  '[' list_array_data ']'

list_array_data::=
	  array_data
	| list_array_data ',' array_data

array_data::=
	  simple_array_data
	| string ARROW simple_array_data

atom::=
	  INTEGER
	| STRING2
	| STRING1

simple_array_data::=
	  atom

var::=
	  var_name
	| array_elem
	| func_call

var_name::=
	  identifier

ipaddr::=
	  INTEGER '.' INTEGER '.' INTEGER '.' INTEGER

loc::=
	  LOCAL arg_decl

glob::=
	  GLOBAL arg_decl

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions