Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar railroad diagram #1503

Open
mingodad opened this issue Sep 22, 2023 · 0 comments
Open

Grammar railroad diagram #1503

mingodad opened this issue Sep 22, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@mingodad
Copy link

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
@mingodad mingodad added the bug Something isn't working label Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant