Open mingodad opened 3 years ago
And here is the EBNF for astl/parser.ypp
:
/*
From https://raw.githubusercontent.com/afborchert/astl/master/astl/parser.ypp
*/
/* converted on Sun Jul 18, 2021, 18:02 (UTC+02) by bison-to-w3c v0.53 which is Copyright (c) 2011-2021 by Gunther Rademacher <grd@gmx.net> */
start ::= unit
unit ::= opt_clauses opt_rules
opt_clauses
::= clause*
clause ::= import_clause
| library_clause
| operator_set_clause
import_clause
::= IMPORT IDENT SEMICOLON
library_clause
::= LIBRARY STRING_LITERAL SEMICOLON
operator_set_clause
::= OPSET IDENT EQ operator_expression SEMICOLON
opt_rules
::= rule*
rule ::= print_rules
| named_print_rules
| operator_rules
| transformation_rules
| named_transformation_rules
| named_inplace_transformation_rules
| attribution_rules
| named_attribution_rules
| function_definition
| state_machine
| abstract_state_machine
function_definition
::= SUB IDENT parameter_list? block
parameter_list
::= LPAREN ( IDENT ( COMMA IDENT )* )? RPAREN
print_rules
::= PRINT RULES LBRACE sequence_of_print_rules RBRACE
named_print_rules
::= PRINT RULES IDENT LBRACE sequence_of_print_rules RBRACE
sequence_of_print_rules
::= print_rule+
print_rule
::= conditional_tree_expression ARROW print_expression
named_tree_expression
::= tree_expression ( AS IDENT )?
tree_expression
::= LPAREN operator_expression subnodes? RPAREN
| variable_length_tree_expression
variable_length_tree_expression
::= LPAREN operator_expression ( STAR | subnodes? subnode_list subnodes? ) RPAREN
operator_expression
::= string_literal
| IDENT
| LBRACKET operators RBRACKET
conditional_tree_expression
::= contextual_tree_expression ( WHERE expression )?
contextual_tree_expression
::= named_tree_expression ( NOT? IN context_expression )?
context_expression
::= context_match ( AND NOT? IN context_match )*
context_match
::= named_tree_expression
subnodes ::= subnode+
subnode ::= named_tree_expression
| regular_expression
| string_literal
| IDENT
subnode_list
::= IDENT DOTS
regular_expression
::= REGEXP_LITERAL ( AS IDENT )?
assignment
::= ( designator ( EQ | AMP_EQ | PLUS_EQ | MINUS_EQ ) )* conditional
conditional
::= term ( QMARK term COLON term )?
term ::= factor
| term ( ( OR | AND | AMPERSAND | X | EQEQ | NE | LT | LE | GE | GT | PLUS | MINUS | DIV | MOD | STAR | POWER ) term | MATCHES ( REGEXP_LITERAL | term ) )
factor ::= ( MINUS | NOT )? primary
primary ::= designator
| EXISTS ( designator | LPAREN designator RPAREN )
| prefix_increment
| prefix_decrement
| postfix_increment
| postfix_decrement
| LPAREN assignment RPAREN
| list_aggregate
| dictionary_aggregate
| tree_constructor
| function_call
| function_constructor
| CARDINAL_LITERAL
| STRING_LITERAL
| NULL_T
prefix_increment
::= PLUSPLUS designator
prefix_decrement
::= MINUSMINUS designator
postfix_increment
::= designator PLUSPLUS
postfix_decrement
::= designator MINUSMINUS
list_aggregate
::= LBRACKET expression_list? RBRACKET
dictionary_aggregate
::= LBRACE ( key_value_pairs COMMA? )? RBRACE
tree_constructor
::= LEYE STRING_LITERAL subnodes_constructor? REYE
key_value_pairs
::= key_value_pair ( COMMA key_value_pair )*
key_value_pair
::= ( IDENT | STRING_LITERAL ) ARROW expression
function_call
::= primary LPAREN expression_list? RPAREN
function_constructor
::= SUB parameter_list? block
expression_list
::= expression ( COMMA expression )*
print_expression
::= print_expression_item*
print_expression_item
::= TEXT_LITERAL
| VARIABLE
| LBRACE expression RBRACE
| print_expression_listvar
print_expression_listvar
::= DOTS
operator_rules
::= OPERATORS LBRACE ( operator_list SEMICOLON )+ RBRACE
operator_list
::= ( LEFT | RIGHT | NONASSOC ) operators
operators
::= operator_term+
operator_term
::= string_literal
| IDENT
transformation_rules
::= TRANSFORMATION RULES LBRACE transformations RBRACE
named_transformation_rules
::= TRANSFORMATION RULES IDENT LBRACE transformations RBRACE
named_inplace_transformation_rules
::= INPLACE TRANSFORMATION RULES IDENT LBRACE transformations RBRACE
transformations
::= transformation+
transformation
::= ( IDENT COLON )? conditional_tree_expression ARROW ( PRE | POST )? transformation_instructions
transformation_instructions
::= pre_transformation_block? subnode_constructor post_transformation_block?
pre_transformation_block
::= block
post_transformation_block
::= block
subnode_constructor
::= IDENT DOTS?
| named_tree_expression_constructor
| named_expression
named_expression
::= LBRACE expression RBRACE DOTS? ( AS IDENT )?
named_tree_expression_constructor
::= tree_expression_constructor ( AS IDENT )?
tree_expression_constructor
::= LPAREN STRING_LITERAL subnodes_constructor? RPAREN
subnodes_constructor
::= subnode_constructor+
attribution_rules
::= ATTRIBUTION RULES LBRACE attributions RBRACE
named_attribution_rules
::= ATTRIBUTION RULES IDENT LBRACE attributions RBRACE
attributions
::= attribution+
attribution
::= conditional_tree_expression ARROW ( PRE | POST )? block
block ::= LBRACE statement* RBRACE
statement
::= ( ( expression | delete_statement | var_statement | return_statement ) SEMICOLON | if_statement | while_statement | foreach_statement ) SEMICOLON*
delete_statement
::= DELETE designator
if_statement
::= IF LPAREN expression RPAREN block elsif_chain? ( ELSE block )?
elsif_chain
::= elsif_statement+
elsif_statement
::= ELSIF LPAREN expression RPAREN block
while_statement
::= WHILE LPAREN expression RPAREN block
foreach_statement
::= FOREACH ( IDENT | LPAREN IDENT COMMA IDENT RPAREN ) IN LPAREN expression RPAREN block
var_statement
::= VAR IDENT ( EQ expression )?
return_statement
::= RETURN expression?
designator
::= IDENT ( DOT IDENT | LBRACE expression RBRACE | LBRACKET expression RBRACKET )*
expression
::= assignment
abstract_state_machine
::= ABSTRACT STATE MACHINE IDENT ( COLON IDENT )? LBRACE sm_vars sm_functions sm_rules RBRACE
state_machine
::= STATE MACHINE IDENT ( COLON IDENT )? LPAREN states RPAREN LBRACE sm_vars sm_functions sm_rules RBRACE
states ::= IDENT ( COMMA IDENT )*
sm_vars ::= ( sm_var_declaration SEMICOLON )*
sm_var_declaration
::= ( SHARED | PRIVATE ) VAR IDENT ( EQ expression )?
sm_functions
::= function_definition*
sm_rules ::= sm_rule+
sm_rule ::= sm_condition ( ARROW ( sm_block | CREATE block ) | sm_alternative+ )
| ON CLOSE sm_handler
sm_handler
::= ( WHEN sm_state_condition )? ARROW block
sm_condition
::= conditional_tree_expression ( AT cfg_node_expression )?
| AT cfg_node_expression
cfg_node_expression
::= ( cfg_node_types | STAR ) ( WHERE expression )?
cfg_node_types
::= IDENT ( OR IDENT )*
sm_block ::= block
| sm_action block?
sm_alternative
::= ( WHEN sm_state_condition | IF cfg_edge_condition ( AND WHEN sm_state_condition )? ) ARROW sm_block
cfg_edge_condition
::= IDENT ( OR IDENT )*
sm_state_condition
::= IDENT ( OR IDENT )*
sm_action
::= CACHE LPAREN expression RPAREN
| CLOSE
| CUT
| RETRACT
| IDENT
string_literal
::= STRING_LITERAL
// Tokens from https://github.com/afborchert/astl/blob/master/astl/operators.txt
//# keywords
ABSTRACT ::= "abstract"
AND ::= "and"
AS ::= "as"
AT ::= "at"
ATTRIBUTION ::= "attribution"
CACHE ::= "cache"
CREATE ::= "create"
CLOSE ::= "close"
CUT ::= "cut"
DELETE ::= "delete"
DIV ::= "div"
ELSE ::= "else"
ELSIF ::= "elsif"
EXISTS ::= "exists"
FOREACH ::= "foreach"
IF ::= "if"
IMPORT ::= "import"
IN ::= "in"
INPLACE ::= "inplace"
LEFT ::= "left"
LIBRARY ::= "library"
MACHINE ::= "machine"
MOD ::= "mod"
NONASSOC ::= "nonassoc"
NULL_T ::= "null"
ON ::= "on"
OPERATORS ::= "operators"
OPSET ::= "opset"
OR ::= "or"
POST ::= "post"
PRE ::= "pre"
PRINT ::= "print"
PRIVATE ::= "private"
RETRACT ::= "retract"
RIGHT ::= "right"
RETURN ::= "return"
RULES ::= "rules"
SHARED ::= "shared"
STATE ::= "state"
SUB ::= "sub"
TRANSFORMATION ::= "transformation"
VAR ::= "var"
WHERE ::= "where"
WHEN ::= "when"
WHILE ::= "while"
X ::= "x"
//# operators and delimiters
MATCHES ::= "=~"
AMPERSAND ::= "&"
LT ::= "<"
GT ::= ">"
LE ::= "<="
GE ::= ">="
EQEQ ::= "=="
NE ::= "!="
EQEQ ::= "=="
PLUS ::= "+"
MINUS ::= "-"
STAR ::= "*"
POWER ::= "^"
LBRACKET ::= "["
RBRACKET ::= "]"
LPAREN ::= "("
RPAREN ::= ")"
LBRACE ::= "{"
RBRACE ::= "}"
DOT ::= "."
ARROW ::= "->"
EQ ::= "="
AMP_EQ ::= "&="
PLUS_EQ ::= "+="
MINUS_EQ ::= "-="
COMMA ::= ","
DOTS ::= "..."
prefix_increment ::= "prefix++"
prefix_decrement ::= "prefix--"
postfix_increment ::= "postfix++"
postfix_decrement ::= "postfix--"
Using this tool https://www.bottlecaps.de/convert/ and manually adding the tokens from
astl-c/operators.txt
we can see a railroad diagram for the grammar inastl-c/parser.ypp
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.