pcmacdon / jsish

Jsi is a small, C-embeddable javascript interpreter with tightly woven Web and DB support.
https://jsish.org/
MIT License
42 stars 9 forks source link

Grammar railroad diagram #96

Open mingodad opened 2 years ago

mingodad commented 2 years ago

Using this online tool https://www.bottlecaps.de/convert/ to convert the jsish grammar to a format understood by https://www.bottlecaps.de/rr/ui and manually adding the lex tokens we can have a navigable railroad diagram (https://en.wikipedia.org/wiki/Syntax_diagram).

Copy the EBNF shown bellow on https://www.bottlecaps.de/rr/ui in the tab Edit Grammar then switch to the tab View Diagram.

/* converted on Thu Aug 25, 2022, 11:38 (UTC+02) by bison-to-w3c v0.59 which is Copyright (c) 2011-2022 by Gunther Rademacher <grd@gmx.net> */

file     ::= statements? expr?
statements
         ::= statement+
statement
         ::= iterstatement
           | ( IDENTIFIER ':' )? commonstatement
localvar ::= LOCAL
           | LOCALLET
           | LOCALCONST
objexport
         ::= object
           | IDENTIFIER
           | '*'
           | '+'
commonstatement
         ::= ( THROW? expr | ( BREAK | CONTINUE ) identifier_opt | localvar vardecs | RETURN expr? )? ';'
           | if_statement
           | delete_statement
           | try_statement
           | with_statement
           | '{' statements '}'
           | func_statement
           | EXPORT DEFAULT objexport
func_statement
         ::= func_prefix '(' args_opt ')' ( ':' rettype )? func_statement_block
func_prefix
         ::= FUNC IDENTIFIER
iterstatement
         ::= for_statement
           | while_statement
           | do_statement
           | switch_statement
identifier_opt
         ::= IDENTIFIER?
label_opt
         ::= ( IDENTIFIER ':' )?
statement_or_empty
         ::= statement
           | '{' '}'
with_statement
         ::= WITH '(' expr ')' statement_or_empty
switch_statement
         ::= label_opt SWITCH '(' expr ')' '{' case* '}'
case     ::= ( CASE expr | DEFAULT ) ':' statements?
try_statement
         ::= TRY func_statement_block ( CATCH '(' IDENTIFIER ')' ( func_statement_block FINALLY )? | FINALLY ) func_statement_block
vardecs  ::= vardec ( ',' vardec )*
vardec   ::= IDENTIFIER ( '=' expr )?
delete_statement
         ::= DELETE lvalue ';'
if_statement
         ::= IF '(' expr ')' statement_or_empty ( ELSE statement_or_empty )?
inof     ::= IN
           | OF
for_statement
         ::= label_opt FOR '(' ( for_init for_cond ';' expr_opt | ( localvar IDENTIFIER | lvalue ) inof expr ) ')' statement_or_empty
for_init ::= ( expr | localvar vardecs )? ';'
for_cond ::= expr?
expr_opt ::= expr?
while_statement
         ::= label_opt WHILE '(' expr ')' statement_or_empty
do_statement
         ::= label_opt DO statement_or_empty WHILE '(' expr ')'
func_expr
         ::= FUNC IDENTIFIER? '(' args_opt ')' ( ':' rettype )? func_statement_block
args_opt ::= ( args ( ',' '.' '.' '.' )? | '.' '.' '.' )?
typeid   ::= TYPESTRING
           | TYPENUMBER
           | TYPEBOOLEAN
           | TYPEREGEXP
           | TYPEOBJECT
           | TYPEUSEROBJ
           | TYPEITEROBJ
           | TYPEANY
           | TYPEARRAY
           | TYPENULL
           | FUNC
           | UNDEF
           | VOID
rettype  ::= argtype
argtype  ::= typeid ( '|' typeid )*
strlit   ::= STRING
argdefault
         ::= UNDEF
           | VOID
           | '-'? FNUMBER
           | _TRUE
           | _FALSE
           | TYPENULL
           | strlit
args     ::= IDENTIFIER ( ':' argtype )? ( '=' argdefault )? ( ',' IDENTIFIER ( ':' argtype )? ( '=' argdefault )? )*
arrowargs
         ::= IDENTIFIER
           | '(' ( IDENTIFIER ( ',' IDENTIFIER )+ )? ')'
func_statement_block
         ::= '{' statements? '}'
expr     ::= value
           | func_expr
           | lvalue
           | expr ',' expr
           | expr '[' expr ']'
           | expr '.' IDENTIFIER
           | '-' expr
           | '+' expr
           | '~' expr
           | '!' expr
           | VOID expr
           | expr '*' expr
           | expr '/' expr
           | expr '%' expr
           | expr '+' expr
           | expr '-' expr
           | expr IN expr
           | lvalue INC
           | lvalue DEC
           | INC lvalue
           | TYPEOF expr
           | DEC lvalue
           | '(' expr ')'
           | arrowargs ARROW expr
           | arrowargs ARROW func_statement_block
           | expr AND expr
           | expr OR expr
           | expr '<' expr
           | expr '>' expr
           | expr LEQ expr
           | expr GEQ expr
           | expr EQU expr
           | expr NEQ expr
           | expr EEQU expr
           | expr NNEQ expr
           | expr '&' expr
           | expr '|' expr
           | expr '^' expr
           | expr LSHF expr
           | expr RSHF expr
           | expr URSHF expr
           | lvalue '=' expr
           | lvalue ADDAS expr
           | lvalue MNSAS expr
           | lvalue MULAS expr
           | lvalue MODAS expr
           | lvalue LSHFAS expr
           | lvalue RSHFAS expr
           | lvalue URSHFAS expr
           | lvalue BANDAS expr
           | lvalue BORAS expr
           | lvalue BXORAS expr
           | lvalue DIVAS expr
           | lvalue INSTANCEOF expr
           | ( expr '.' IDENTIFIER '(' exprlist_opt ')' | expr '[' expr ']' '(' exprlist_opt ')' | '(' expr ')' '(' exprlist_opt ')' | lvalue '(' exprlist_opt ')' ) ( '(' exprlist_opt ')' )*
           | NEW value
           | NEW lvalue
           | NEW '(' expr ')'
           | NEW func_expr
           | NEW value '(' exprlist_opt ')'
           | NEW lvalue '(' exprlist_opt ')'
           | NEW '(' expr ')' '(' exprlist_opt ')'
           | NEW func_expr '(' exprlist_opt ')'
           | func_expr '(' exprlist_opt ')'
           | expr '?' expr ':' expr
           | __DEBUG
lvalue   ::= ( IDENTIFIER | ARGUMENTS | _THIS ) ( '[' expr ']' | '.' ( IDENTIFIER | itemres ) )*
exprlist_opt
         ::= exprlist?
exprlist ::= expr
           | exprlist ',' ( expr | ',' )
           | ',' exprlist
value    ::= strlit
           | TYPENULL
           | UNDEF
           | _TRUE
           | _FALSE
           | FNUMBER
           | REGEXP
           | object
           | array
object   ::= '{' item? ( ',' itemident? )* '}'
itemfunc ::= IDENTIFIER '(' args_opt ')' func_statement_block
itemident
         ::= itemfunc
           | IDENTIFIER
           | item
itemres  ::= OBJSET
           | OBJGET
           | CONTINUE
           | RETURN
           | BREAK
           | THROW
           | DEFAULT
           | CASE
           | EXPORT
           | TYPEANY
           | TYPEARRAY
           | TYPESTRING
           | TYPENUMBER
           | TYPEBOOLEAN
           | TYPEREGEXP
           | TYPEITEROBJ
           | TYPEUSEROBJ
           | ARGUMENTS
           | _THIS
           | DELETE
           | NEW
           | LOCAL
           | LOCALLET
           | LOCALCONST
           | VOID
           | __DEBUG
           | TYPEOBJECT
           | WITH
           | FUNC
           | TYPEOF
           | INSTANCEOF
item     ::= ( IDENTIFIER | strlit | itemres | FNUMBER | _TRUE | _FALSE | UNDEF | TYPENULL ) ':' expr
           | ( OBJSET IDENTIFIER '(' IDENTIFIER | OBJGET IDENTIFIER '(' ) ')' func_statement_block
array    ::= '[' ( exprlist ','? )? ']'

//Tokens
//{ \("[^"]+"\), \(\S+\) },

IF ::= "if"
ELSE ::= "else"
FOR ::= "for"
IN ::= "in"
WHILE ::= "while"
DO ::= "do"
CONTINUE ::= "continue"
SWITCH ::= "switch"
CASE ::= "case"
DEFAULT ::= "default"
BREAK ::= "break"
FUNC ::= "function"
RETURN ::= "return"
LOCAL ::= "var"
LOCALLET ::= "let"
LOCALCONST ::= "const"
OF ::= "of"
NEW ::= "new"
DELETE ::= "delete"
TRY ::= "try"
CATCH ::= "catch"
THROW ::= "throw"
FINALLY ::= "finally"
WITH ::= "with"
UNDEF ::= "undefined"
_TRUE ::= "true"
_FALSE ::= "false"
_THIS ::= "this"
ARGUMENTS ::= "arguments"
VOID ::= "void"
TYPEOF ::= "typeof"
INSTANCEOF ::= "instanceof"
TYPESTRING ::= "string"
TYPENUMBER ::= "number"
TYPEREGEXP ::= "regexp"
TYPEANY ::= "any"
TYPEUSEROBJ ::= "userobj"
TYPEITEROBJ ::= "iterobj"
TYPEOBJECT ::= "object"
TYPEBOOLEAN ::= "boolean"
TYPEARRAY ::= "array"
TYPENULL ::= "null"
EXPORT ::= "export"
OBJSET ::= "set"
OBJGET ::= "get"
ELLIPSIS ::= "..."
__DEBUG ::= "debugger"
//0 ::= "Array"
//0 ::= "Boolean"
//0 ::= "Channel"
//0 ::= "Event"
//0 ::= "File"
//0 ::= "Function"
//0 ::= "Info"
//0 ::= "Interp"
//0 ::= "JSON"
//0 ::= "Math"
//0 ::= "MySql"
//0 ::= "Number"
//0 ::= "Object"
//0 ::= "RegExp"
//0 ::= "Signal"
//0 ::= "Socket"
//0 ::= "Sqlite"
//0 ::= "String"
//0 ::= "System"
//0 ::= "Util"
//0 ::= "Vfs"
//0 ::= "WebSocket"
//0 ::= "Zvfs"
//0 ::= "JSON"
//0 ::= "console"
URSHFAS ::= ">>>="
LSHFAS ::= "<<="
RSHFAS ::= ">>="
EEQU ::= "==="
NNEQ ::= "!=="
URSHF ::= ">>>"
EQU ::= "=="
NEQ ::= "!="
LEQ ::= "<="
GEQ ::= ">="
INC ::= "++"
DEC ::= "--"
AND ::= "&&"
OR ::= "||"
ADDAS ::= "+="
MNSAS ::= "-="
MULAS ::= "*="
DIVAS ::= "/="
MODAS ::= "%="
BANDAS ::= "&="
BORAS ::= "|="
BXORAS ::= "^="
LSHF ::= "<<"
RSHF ::= ">>"
ARROW ::= "=>"
pcmacdon commented 2 years ago

It does look very cool. But I'm not sure how the result can be incorporated into github easily.

mingodad commented 2 years ago

What do you mean ? You can download/save the resulting railroad diagram .

pcmacdon commented 2 years ago

Sorry, I wasn't clear. I meant I could download the diagram.xhtml, but github does not support this extension for drag/drop it it into issues textarea. Which I took to mean xhtml is not supported by their embedded doc system.