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

Open
mingodad opened this issue Mar 6, 2024 · 0 comments
Open

Grammar railroad diagram #102

mingodad opened this issue Mar 6, 2024 · 0 comments

Comments

@mingodad
Copy link

mingodad commented Mar 6, 2024

Manually converting the grammars shown at https://shenlanguage.org/OSM/Syntax.html 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 for then to help document/debug/develop then (see bellow).

/*
Grammar originally from https://shenlanguage.org/OSM/Syntax.html

Manually converted to be viewd  by
	(IPV6) https://www.bottlecaps.de/rr/ui
	(IPV4) https://rr.red-dove.com/ui

Copy and paste the this on one of the urls shown above on the
	'Edit Grammar' tab then click the 'View Diagram' tab.
*/

Shen_def ::=
	"(define" lowercase '{' types '}' rules ')'
	| "('define" lowercase rules ')'
	| "(defmacro" lowercase rules ')'

lowercase ::=
	//any <symbol> not beginning in uppercase
	([a-z] | alpha_punct)alpha*

rules ::=
	rule
	| rule rules

rule ::=
	patterns "->" item
	| patterns "<-" item
	| patterns "->" item "where" item
	| patterns "<-" item "where" item

patterns ::=
	//Ɛ
	| pattern patterns

pattern ::=
	base '(' "except -> and <-" ')'
	| '[' pattern patterns '|' pattern ']'
	| '[' patterns ']'
	| "(cons" pattern pattern ')'
	| "(@p" pattern pattern patterns ')'
	| "(@s" pattern pattern patterns ')'
	| "(@v" pattern pattern patterns ')'

item ::=
	base
	| '[' items '|' item ']'
	| '[' items ']'
	| application
	| abstraction

items ::=
	item
	| item items

base ::=
	symbol '(' "except |" ')'
	| string
	| boolean
	| number
	| '(' ')'
	| '[' ']'

application ::=
	'(' items ')'

abstraction ::=
	"(/." variables item ')'

variables ::=
	variable
	| variable variables

variable ::=
	//any <symbol> beginning in uppercase
	[A-Z]alpha*

types ::=
	//Ɛ
	| '(' types ')'
	| types "-->" types
	| symbol

symbol ::=
	alpha symbolchars
	| alpha symbolchars ":=" alpha symbolchars
	| digit symbolchars
	| alpha
	| digit

alpha_punct ::=
	[-.=*/+_?\$!@~><&%'#`;:{}]

alpha ::=
	[A-Za-z]
	| alpha_punct

digit ::=
	[0-9]

number ::=
	signs float
	| signs integer
	| signs e_number

signs ::=
	//Ɛ
	| '+' signs
	| '-' signs

float ::=
	digits '.' digits
	| '.' digits

integer ::=
	digits

digits ::=
	digit
	| digit digits

e_number ::=
	integer "e-" integer
	| integer 'e' integer
	| float "e-" integer
	| float 'e' integer
/*
Grammar originally from https://shenlanguage.org/OSM/Syntax.html

Manually converted to be viewd  by
	(IPV6) https://www.bottlecaps.de/rr/ui
	(IPV4) https://rr.red-dove.com/ui

Copy and paste the this on one of the urls shown above on the
	'Edit Grammar' tab then click the 'View Diagram' tab.
*/

datatype_definition ::=
	"(datatype" lowercase datatype_rules ')'

datatype_rules ::=
	datatype_rule
	| datatype_rule datatype_rules

datatype_rule ::=
	side_conditions schemes underline scheme ';'
	| side_conditions simple_schemes double_underline formula ';'

side_conditions ::=
	//Ɛ
	| side_condition
	| side_condition side_conditions

side_condition ::=
	"if" item
	| "let" variable item

underline ::=
	'_' +
	//| "one or more concatenations of the underscore _"

double_underline ::=
	'='+
	//| one or more concatenations of =

simple_schemes ::=
	formula ';'
	| formula ';' simple_schemes

formula ::=
	item ':' item
	| item

schemes ::=
	//Ɛ
	| scheme ';' schemes

scheme ::=
	assumptions ">>" formula
	| formula

assumptions ::=
	formula
	| formula ',' assumptions
/*
Grammar originally from https://shenlanguage.org/OSM/Syntax.html

Manually converted to be viewd  by
	(IPV6) https://www.bottlecaps.de/rr/ui
	(IPV4) https://rr.red-dove.com/ui

Copy and paste the this on one of the urls shown above on the
	'Edit Grammar' tab then click the 'View Diagram' tab.
*/

prolog_definition ::=
	"(defprolog" lowercase clauses ')'

clauses ::=
	clause
	| clause clauses

clause ::=
	head "<--" tail

head ::=
	prolog_patterns

prolog_patterns ::=
	//Ɛ
	| prolog_pattern prolog_patterns

prolog_pattern ::=
	base
	| '[' prolog_pattern prolog_patterns '|' prolog_pattern ']'
	| '[' prolog_patterns ']'
	| "(cons" prolog_pattern prolog_pattern ')'

tail ::=
	//Ɛ
	| '!' tail
	| application tail

lowercase ::=
	//any <symbol> not beginning in uppercase
	([a-z] | alpha_punct)alpha*

alpha_punct ::=
	[-.=*/+_?\$!@~><&%'#`;:{}]

alpha ::=
	[A-Za-z]
	| alpha_punct
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