dino-lang / dino

The programming language DINO
GNU General Public License v2.0
71 stars 5 forks source link

Grammar railroad diagram #19

Open mingodad opened 3 years ago

mingodad commented 3 years ago

It seems that there is some mistake around XOR_ASSIGN because it's defined twice as ^= and ~= in DINO/d_yacc.y.

Using this tool https://www.bottlecaps.de/convert/ (removing everything after the last %%) and manually adding the tokens from DINO/d_kw.shilka and DINO/d_yacc.y we can see a railroad diagram for the grammar in DINO/d_yacc.y copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui in the tab Edit Grammar then switching to the tab View Diagram.

/* converted on Thu Jul 22, 2021, 12:41 (UTC+02) by bison-to-w3c v0.53 which is Copyright (c) 2011-2021 by Gunther Rademacher <grd@gmx.net> */

clear_flag
         ::=
set_flag ::=
set_flag2
         ::=
expr     ::= NUMBER
           | CHARACTER
           | NIL
           | STRING
           | type
           | expr ( ( '?' expr ':' | LOGICAL_OR | LOGICAL_AND | IN | '|' | '^' | '&' | EQ | NE | IDENTITY | UNIDENTITY | '<' | '>' | LE | GE | LSHIFT | RSHIFT | ASHIFT | '@' | '+' | '-' | '*' | '/' | '%' ) expr | actual_parameters )
           | ( '!' | '+' | '-' | '~' | '#' | FOLD_PLUS | FOLD_MULT | FOLD_AND | FOLD_XOR | FOLD_OR | FOLD_CONCAT | FINAL | NEW ) expr
           | designator
           | '(' ( expr ')' | error bracket_stop )
           | '[' ( set_flag elist_parts_list_empty ']' | error sqbracket_stop )
           | TAB ( '[' ( clear_flag elist_parts_list_empty ']' | error stmt_stop ) | '(' expr ')' )
           | ( ( TYPE | CHAR | INT | LONG | FLOAT ) '(' | VEC '(' ( expr ',' )? ) expr ')'
           | THIS
           | TRY '(' ( set_flag2 executive_stmt except_class_list_opt ')' | error bracket_stop )
           | WILDCARD
           | DOTS
type     ::= CHAR
           | INT
           | LONG
           | FLOAT
           | HIDE
           | HIDEBLOCK
           | VEC
           | TAB
           | fun_fiber_class
           | OBJ
           | THREAD
           | TYPE
except_class_list_opt
         ::= ( ',' except_class_list )?
aheader  ::= fun_fiber_class ( '(' formal_parameters ')' )?
eof_stop ::= END_OF_FILE
           | END_OF_INCLUDE_FILE
bracket_stop
         ::= eof_stop
           | ')'
           | '}'
           | ';'
sqbracket_stop
         ::= eof_stop
           | ']'
           | '}'
           | ';'
stmt_stop
         ::= eof_stop
           | '}'
           | ';'
pos      ::=
hint     ::= ( '!' ( IDENT | error ) )?
designator
         ::= expr ( '[' ( ( expr | expr_empty ':' expr_empty opt_step ) ']' | error sqbracket_stop ) | '.' IDENT )
           | IDENT
           | aheader hint block
elist_part
         ::= pos expr ( ':' expr )?
elist_parts_list_empty
         ::= ( elist_part ( ',' elist_part )* )?
actual_parameters
         ::= '(' ( expr_list_empty ')' | error bracket_stop )
expr_list_empty
         ::= ( pos expr ( ',' expr )* )?
access   ::= ( PRIV | PUB )?
val_var_list
         ::= ( val_var | error ) ( ',' val_var )*
val_var  ::= IDENT
           | pattern '=' expr
stmt     ::= executive_stmt
           | declaration
           | error stmt_stop
assign   ::= '='
           | MULT_ASSIGN
           | DIV_ASSIGN
           | MOD_ASSIGN
           | PLUS_ASSIGN
           | MINUS_ASSIGN
           | CONCAT_ASSIGN
           | LSHIFT_ASSIGN
           | RSHIFT_ASSIGN
           | ASHIFT_ASSIGN
           | AND_ASSIGN
           | XOR_ASSIGN
           | OR_ASSIGN
incr_decr
         ::= INCR
           | DECR
executive_stmt
         ::= ( THROW? expr | incr_decr designator | BREAK | CONTINUE | RETURN expr_empty | designator ( assign expr | incr_decr ) )? end_exec_stmt
           | IF '(' ( expr ')' | error bracket_stop ) stmt else_part
           | ( FOR '(' ( clear_flag ( stmt for_guard_expr ';' set_flag stmt | designator IN expr ) ')' | error bracket_stop ) | WAIT '(' ( expr ')' | error bracket_stop ) ) stmt
           | match_head '(' expr ')' '{' error? a_case* '}'
           | block_stmt
           | try_block_stmt
           | CODE
match_head
         ::= PMATCH
           | RMATCH
a_case   ::= CASE regexp_pattern opt_cond ':' stmt_list
opt_cond ::= ( IF expr )?
pattern  ::= expr
regexp_pattern
         ::= expr
for_guard_expr
         ::= expr?
block_stmt
         ::= block
try_block_stmt
         ::= TRY block catch*
catch    ::= CATCH '(' except_class_list ')' block
           | error
except_class_list
         ::= expr ( ',' expr )*
declaration
         ::= ( access ( ( VAL set_flag | VAR clear_flag ) val_var_list | EXTERN extern_item ( ',' extern_item )* ) | FRIEND ( IDENT | error ) ( ',' IDENT )* | fun_fiber_class_start IDENT | EXPOSE expose_qual_ident ( ',' expose_qual_ident )* | USE qual_ident ( ( FORMER set_flag | LATER clear_flag ) use_item ( ',' use_item )* )* | REQUIRE NUMBER ) end_simple_stmt
           | ( header hint | ( PRIV | PUB )? OBJ IDENT ) block
           | INCLUDE '+'? STRING end_simple_stmt inclusion
all_fields
         ::= '.' '*'
           | FOLD_MULT
expose_qual_ident
         ::= qual_ident ( alias_opt | all_fields )
qual_ident
         ::= IDENT ( '.' IDENT )*
use_item ::= IDENT alias_opt
alias_opt
         ::= ( '(' IDENT ')' )?
extern_item
         ::= IDENT ( '(' ')' )?
inclusion
         ::= ( INCLUSION stmt_list END_OF_INCLUDE_FILE )?
end_simple_stmt
         ::= ';'
           | ')'
end_exec_stmt
         ::= end_simple_stmt
           | ','
header   ::= fun_fiber_class_start IDENT ( '(' formal_parameters ')' )?
fun_fiber_class_start
         ::= ( ( PRIV | PUB ) FINAL? | FINAL ( PRIV | PUB )? )? fun_fiber_class
fun_fiber_class
         ::= FUN
           | FIBER
           | CLASS
else_part
         ::= ( ELSE stmt )?
expr_empty
         ::= expr?
opt_step ::= ( ':' expr )?
par_list ::= ( par | error ) ( ',' par )*
par_kind ::= ( VAL | VAR )?
par      ::= access par_kind IDENT ( '=' expr )?
par_list_empty
         ::= par_list?
formal_parameters
         ::= par_list_empty
           | ( par_list ',' )? DOTS
block    ::= '{' stmt_list '}'
stmt_list
         ::= ( clear_flag stmt | error )*
program  ::= stmt_list END_OF_FILE

// Tokens

WILDCARD ::= "_"
BREAK ::= "break"
CASE ::= "case"
CATCH ::= "catch"
CHAR ::= "char"
CLASS ::= "class"
CONTINUE ::= "continue"
EXPOSE ::= "expose"
EXTERN ::= "extern"
ELSE ::= "else"
FIBER ::= "fiber"
FINAL ::= "final"
FLOAT ::= "float"
FOR ::= "for"
FORMER ::= "former"
FRIEND ::= "friend"
FUN ::= "fun"
HIDE ::= "hide"
HIDEBLOCK ::= "hideblock"
IF ::= "if"
IN ::= "in"
INCLUDE ::= "include"
INT ::= "int"
LATER ::= "later"
LONG ::= "long"
NEW ::= "new"
NIL ::= "nil"
OBJ ::= "obj"
PMATCH ::= "pmatch"
PRIV ::= "priv"
PUB ::= "pub"
REQUIRE ::= "require"
RETURN ::= "return"
RMATCH ::= "rmatch"
TAB ::= "tab"
THREAD ::= "thread"
THIS ::= "this"
THROW ::= "throw"
TRY ::= "try"
TYPE ::= "type"
USE ::= "use"
VAL ::= "val"
VAR ::= "var"
VEC ::= "vec"
WAIT ::= "wait"

XOR_ASSIGN ::= "~="
INCR ::= "++"
PLUS_ASSIGN ::= "+="
DECR ::= "--"
MINUS_ASSIGN ::= "-="
CONCAT_ASSIGN ::= "@="
LE ::= "<="
LSHIFT_ASSIGN ::= "<<="
LSHIFT ::= "<<"
GE ::= ">="
ASHIFT_ASSIGN ::= ">>="
RSHIFT_ASSIGN ::= ">>>="
RSHIFT ::= ">>>"
ASHIFT ::= ">>"
DIV_ASSIGN ::= "/="
MULT_ASSIGN ::= "*="
LOGICAL_AND ::= "&&"
AND_ASSIGN ::= "&="
LOGICAL_OR ::= "||"
OR_ASSIGN ::= "|="
MOD_ASSIGN ::= "%="
XOR_ASSIGN ::= "^="
NE ::= "!="
EQ ::= "=="
DOTS ::= "..."
FOLD_PLUS ::= ".+"
FOLD_MULT ::= ".*"
FOLD_AND ::= ".&"
FOLD_XOR ::= ".^"
FOLD_OR ::= ".|"
FOLD_CONCAT ::= ".@"
mingodad commented 1 year ago

I've also added dino grammar to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex compatible online editor/tester (select Dino-lang parser from Examples then click Parse to see a parser tree for the content in Input source editor).

Any feedback is welcome !

vnmakarov commented 12 months ago

Sorry for the delay with the answer. I am too busy this time of year.

I've just played with it. It is a really nice service! Thank you.

I have only one wish. The default input source is too specific and complicated. I would prefer to use something simpler, e.g. sieve.d (or fact.d or fib.d) from https://github.com/dino-lang/dino/tree/master/DINO/Examples.