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 #121

Open
mingodad opened this issue Feb 29, 2024 · 0 comments
Open

Grammar railroad diagram #121

mingodad opened this issue Feb 29, 2024 · 0 comments

Comments

@mingodad
Copy link

Using a script to convert (with some manual fixes) joo.cup to an EBNF understood by (IPV6) https://www.bottlecaps.de/rr/ui or (IPV4) https://rr.red-dove.com/ui to generate a nice navigable railroad diagram that can be used to document/develop/debug this project grammar.

Follow the instructions shown bellow at the top:

//
// EBNF to be viewd at
//	(IPV6) https://www.bottlecaps.de/rr/ui
//	(IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one url shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//

as3_joo ::=
   compilationUnit

arguments ::=
  | nonEmptyArguments

arrayLiteral ::=
  LBRACK arrayLiteralFields RBRACK

arrayLiteralFields ::=
  |  expr
  | optExpr COMMA arrayLiteralFields

block ::=
  LBRACE statements RBRACE

catches ::=
  catchClause
  |  catches catchClause

catchClause ::=
  CATCH LPAREN parameter RPAREN block

classBody ::=
  LBRACE classBodyDirectives RBRACE

classBodyDirectives ::=
  | classBodyDirectives	classBodyDirective

classBodyDirective ::=
    statement
  | directive

classDeclaration ::=
    annotationsAndModifiers CLASS ide extends implements classBody
  | annotationsAndModifiers INTERFACE ide interfaceExtends classBody

commaExpr ::=
    expr
  | expr COMMA commaExpr

compilationUnit ::=
    packageDeclaration LBRACE optDirectives compilationUnitDeclaration RBRACE optClassDeclarations
  | mxmlCompilationUnit

compilationUnitDeclaration ::=
    classDeclaration SEMICOLON
  | classDeclaration
  | variableDeclaration
  | functionDeclaration
  | namespaceDeclaration

optClassDeclarations ::=
  | optDirectives classDeclaration optClassDeclarations

constOrVar ::=
    CONST
  | VAR

directive ::=
    IMPORT qualifiedIde SEMICOLON
  | IMPORT qualifiedIde DOT MUL SEMICOLON
  | USE ide qualifiedIde SEMICOLON

annotationsAndModifiers ::=
    modifiers
  | annotations modifiers

annotations ::=
    annotation
  | annotations annotation

annotation ::=
    LBRACK ide RBRACK
  | LBRACK ide LPAREN annotationParameters RPAREN RBRACK

nonEmptyAnnotationParameters ::=
    annotationParameter
  | annotationParameter COMMA nonEmptyAnnotationParameters

annotationParameter ::=
    ide EQ literalExpr
  | ide EQ qualifiedIde
  | literalExpr
  | ide

annotationParameters ::=
  | nonEmptyAnnotationParameters

optDirectives ::=
  | directive optDirectives

literalExpr ::=
    INT_LITERAL
  | FLOAT_LITERAL
  | BOOL_LITERAL
  | STRING_LITERAL
  | REGEXP_START REGEXP_LITERAL
  | NULL_LITERAL

expr ::=
    literalExpr
  | objectLiteral
  | arrayLiteral
  | lvalue
  | functionExpr
  | THIS
  | parenthesizedExpr
  | NEW LT type GT arrayLiteral
  | NEW expr
  | PLUSPLUS expr
     //%prec PREFIX_PLUSPLUS
  | MINUSMINUS expr
     //%prec PREFIX_MINUSMINUS
  | PLUS expr
     //%prec PREFIX_PLUS
  | MINUS expr
     //%prec PREFIX_MINUS
  | NOT expr
  | BITNOT expr
  | TYPEOF expr
  | DELETE expr
  | expr LPAREN arguments RPAREN
  | expr AS expr
  | expr IS expr
  | expr NO_LINE_TERMINATOR_HERE_POSTFIX_OP PLUSPLUS
  | expr NO_LINE_TERMINATOR_HERE_POSTFIX_OP MINUSMINUS
  | expr MUL expr
  | expr DIV expr
  | expr MOD expr
  | expr PLUS expr
  | expr MINUS expr
  | expr LSHIFT expr
  | expr RSHIFT expr
  | expr URSHIFT expr
  | expr LT expr
  | expr GT expr
  | expr LTEQ expr
  | expr GTEQ expr
  | expr INSTANCEOF expr
  | expr EQEQ expr
  | expr NOTEQ expr
  | expr EQEQEQ expr
  | expr NOTEQEQ expr
  | expr AND expr
  | expr XOR expr
  | expr OR expr
  | expr ANDAND expr
  | expr OROR expr
  | expr IN expr
  | lvalue EQ expr
  | lvalue MULTEQ expr
  | lvalue DIVEQ expr
  | lvalue MODEQ expr
  | lvalue PLUSEQ expr
  | lvalue MINUSEQ expr
  | lvalue LSHIFTEQ expr
  | lvalue RSHIFTEQ expr
  | lvalue URSHIFTEQ expr
  | lvalue ANDEQ expr
  | lvalue XOREQ expr
  | lvalue OREQ expr
  | lvalue ANDANDEQ expr
  | lvalue OROREQ expr
  | expr QUESTION expr COLON expr

extends ::=
  |
    EXTENDS qualifiedIde

interfaceExtends ::=
  | EXTENDS ideList

namespaceDeclaration ::=
    annotationsAndModifiers EQ STRING_LITERAL SEMICOLON

functionExpr ::=
    FUNCTION_EXPR optIde LPAREN parameters RPAREN optTypeRelation block

functionDeclaration ::=
    annotationsAndModifiers FUNCTION ide LPAREN parameters RPAREN optTypeRelation block
  | annotationsAndModifiers FUNCTION ide LPAREN parameters RPAREN optTypeRelation SEMICOLON
  | annotationsAndModifiers FUNCTION IDE ide LPAREN parameters RPAREN optTypeRelation block
  | annotationsAndModifiers FUNCTION IDE ide LPAREN parameters RPAREN optTypeRelation SEMICOLON

ide ::=
    IDE

implements ::=
  | IMPLEMENTS ideList

lvalue ::=
    qualifiedIde
  | IDE NAMESPACESEP IDE
  | THIS DOT namespacedIde
  | SUPER DOT namespacedIde
  | expr DOT namespacedIde
  | expr LBRACK commaExpr RBRACK

modifier ::=
    PUBLIC
  | PROTECTED
  | PRIVATE
  | INTERNAL
  /* syntactic keyword modifier or a namespace: */
  | IDE

modifiers ::=
  | modifier modifiers

namespacedIde ::=
    ide
  | modifier NAMESPACESEP IDE

nonEmptyArguments ::=
    expr
  | expr COMMA nonEmptyArguments

nonEmptyParameters ::=
    parameter
  | REST ide optTypeRelation
  | parameter COMMA nonEmptyParameters

nonEmptyObjectFields ::=
    objectField
  | objectField COMMA nonEmptyObjectFields

objectField ::=
    ide COLON expr
  | STRING_LITERAL COLON expr
  | INT_LITERAL COLON expr

objectFields ::=
  | nonEmptyObjectFields

objectLiteral ::=
    LBRACE_EXPR objectFields RBRACE

optCatches ::=
  | catches

optCommaExpr ::=
  | commaExpr

optExpr ::=
  | expr

optIde ::=
  | ide

optInitializer ::=
  | EQ expr

optTypeRelation ::=
  | typeRelation

packageDeclaration ::=
    PACKAGE
  | PACKAGE qualifiedIde

parameter ::=
    ide optTypeRelation optInitializer

parameters ::=
  | nonEmptyParameters

parenthesizedExpr ::=
    LPAREN expr RPAREN

qualifiedIde ::=
    ide
  | IDE DOTLT type GT
  | qualifiedIde DOT namespacedIde

statement ::=
    SEMICOLON
  | commaExpr SEMICOLON
  | ide COLON statement
  | variableDeclaration
  | BREAK SEMICOLON
  | BREAK NO_LINE_TERMINATOR_HERE ide SEMICOLON
  | CONTINUE SEMICOLON
  | CONTINUE NO_LINE_TERMINATOR_HERE ide SEMICOLON
  | RETURN  SEMICOLON
  | RETURN  NO_LINE_TERMINATOR_HERE expr SEMICOLON
  | THROW NO_LINE_TERMINATOR_HERE commaExpr SEMICOLON
  | SUPER LPAREN arguments RPAREN SEMICOLON
  | IF parenthesizedExpr statement ELSE statement
  | IF parenthesizedExpr statement
  | SWITCH parenthesizedExpr LBRACE statementsInSwitch RBRACE
  | WHILE parenthesizedExpr statement
  | DO statement WHILE parenthesizedExpr SEMICOLON
  | FOR LPAREN SEMICOLON optCommaExpr SEMICOLON optCommaExpr RPAREN statement
  | FOR LPAREN commaExpr SEMICOLON optCommaExpr SEMICOLON optCommaExpr RPAREN statement
  | FOR LPAREN forVariableDeclaration SEMICOLON optCommaExpr SEMICOLON optCommaExpr RPAREN statement
  | FOR LPAREN lvalue IN expr RPAREN statement
  | FOR LPAREN VAR ide optTypeRelation IN expr RPAREN statement
  | FOR IDE LPAREN lvalue IN expr RPAREN statement
  | FOR IDE LPAREN VAR ide optTypeRelation IN expr RPAREN statement
  | TRY block catches
  | TRY block optCatches FINALLY block
  | block
  | functionDeclaration

statements ::=
  | statements statement

statementInSwitch ::=
    statement
  | CASE expr COLON
  | DEFAULT COLON

statementsInSwitch ::=
  | statementsInSwitch statementInSwitch

type ::=
    ideType
  | MUL
  | VOID

ideType ::=
    qualifiedIde

ideList ::=
    qualifiedIde
  | qualifiedIde COMMA ideList

typeRelation ::=
    COLON type
  | COLON TYPE_START type

forVariableDeclaration ::=
  VAR ide optTypeRelation optInitializer optNextVariableDeclaration

variableDeclaration ::=
  annotationsAndModifiers constOrVar ide optTypeRelation optInitializer optNextVariableDeclaration SEMICOLON

optNextVariableDeclaration ::=
  | COMMA ide optTypeRelation optInitializer optNextVariableDeclaration

mxmlCompilationUnit ::=
    optXmlHeader mxmlElement

/* <?xml version="..."?> */
optXmlHeader ::=
  | LT_QUESTION ide xmlAttributes QUESTION_GT

mxmlElement ::=
    closedMxmlTag
  | openingMxmlTag mxmlElements closingMxmlTag

mxmlElements ::=
  | mxmlElements mxmlElement
  | mxmlElements STRING_LITERAL

xmlAttribute ::=
    namespacedXmlIde EQ STRING_LITERAL

xmlAttributes ::=
  | xmlAttributes xmlAttribute

namespacedXmlIde ::=
    IDE
  | IDE COLON IDE

openingMxmlTag ::=
    LT namespacedXmlIde xmlAttributes GT

closedMxmlTag ::=
    LT namespacedXmlIde xmlAttributes SLASH_GT

closingMxmlTag ::=
    LT_SLASH namespacedXmlIde GT

//Tokens
//\("[^"]+"\)\s+{ return symbol(\([^)]+\)); }

AS ::= "as"
BREAK ::= "break"
CASE ::= "case"
CATCH ::= "catch"
CLASS ::= "class"
CONST ::= "const"
CONTINUE ::= "continue"
DEFAULT ::= "default"
DELETE ::= "delete"
DO ::= "do"
ELSE ::= "else"
EXTENDS ::= "extends"
FINALLY ::= "finally"
FOR ::= "for"
FUNCTION ::= "function"
IF ::= "if"
IMPLEMENTS ::= "implements"
IMPORT ::= "import"
IN ::= "in"
INSTANCEOF ::= "instanceof"
INTERFACE ::= "interface"
INTERNAL ::= "internal"
IS ::= "is"
NEW ::= "new"
NULL_LITERAL ::= "null"
PACKAGE ::= "package"
PRIVATE ::= "private"
PROTECTED ::= "protected"
PUBLIC ::= "public"
RETURN ::= "return"
SUPER ::= "super"
SWITCH ::= "switch"
THIS ::= "this"
THROW ::= "throw"
TRY ::= "try"
TYPEOF ::= "typeof"
USE ::= "use"
VAR ::= "var"
VOID ::= "void"
WHILE ::= "while"
WITH ::= "with"

BOOL_LITERAL ::= "true"
BOOL_LITERAL ::= "false"


LPAREN ::= "("
RPAREN ::= ")"
LBRACE ::= "{"
RBRACE ::= "}"
LBRACK ::= "["
RBRACK ::= "]"
SEMICOLON ::= ";"
COMMA ::= ","
DOT ::= "."
EQ ::= "="
GT ::= ">"
LT ::= "<"
NOT ::= "!"
QUESTION ::= "?"
COLON ::= ":"
EQEQ ::= "=="
LTEQ ::= "<="
GTEQ ::= ">="
NOTEQ ::= "!="
ANDAND ::= "&&"
OROR ::= "||"
PLUSPLUS ::= "++"
MINUSMINUS ::= "--"
PLUS ::= "+"
MINUS ::= "-"
MUL ::= "*"
AND ::= "&"
OR ::= "|"
XOR ::= "^"
MOD ::= "%"
BITNOT ::= "~"
LSHIFT ::= "<<"
RSHIFT ::= ">>"
URSHIFT ::= ">>>"
PLUSEQ ::= "+="
MINUSEQ ::= "-="
MULTEQ ::= "*="
ANDEQ ::= "&="
ANDANDEQ ::= "&&="
OREQ ::= "|="
OROREQ ::= "||="
XOREQ ::= "^="
MODEQ ::= "%="
LSHIFTEQ ::= "<<="
RSHIFTEQ ::= ">>="
URSHIFTEQ ::= ">>>="
EQEQEQ ::= "==="
NOTEQEQ ::= "!=="
REST ::= "..."
NAMESPACESEP ::= "::"
DIV ::= "/"
DIVEQ ::= "/="
DOTLT ::= ".<"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant