-- The MIT License (MIT)
-- Copyright (c) 2016-2024 Objectionary.com
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included
-- in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
-- ==========================================================
-- BNFC grammar for φ-programs (translated from EO)
-- ==========================================================
--
-- This is a non-ambiguous grammar for φ-programs.
comment "//" ;
comment "/*" "*/" ;
token Bytes ({"--"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] {"-"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] ({"-"} ["0123456789ABCDEF"] ["0123456789ABCDEF"])+) ;
token Function upper (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
token LabelId lower (char - [" \r\n\t,.|':;!?][}{)(⟧⟦"])* ;
token AlphaIndex ({"α0"} | {"α"} (digit - ["0"]) (digit)* ) ;
token LabelMetaId {"!τ"} (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
token TailMetaId {"!t"} (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
token BindingsMetaId {"!B"} (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
token ObjectMetaId {"!b"} (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
token BytesMetaId {"!y"} (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
token MetaFunctionName {"@"} (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
Program. Program ::= "{" "⟦" [Binding] "⟧" "}" ;
MetaIdLabel. MetaId ::= LabelMetaId ;
MetaIdTail. MetaId ::= TailMetaId ;
MetaIdBindings. MetaId ::= BindingsMetaId ;
MetaIdObject. MetaId ::= ObjectMetaId ;
MetaIdBytes. MetaId ::= BytesMetaId ;
Formation. Object ::= "⟦" [Binding] "⟧" ;
Application. Object ::= Object "(" [Binding] ")" ;
ObjectDispatch. Object ::= Object "." Attribute ;
GlobalObject. Object ::= "Φ";
ThisObject. Object ::= "ξ";
Termination. Object ::= "⊥" ;
ConstString. Object ::= String ;
ConstInt. Object ::= Integer ;
ConstFloat. Object ::= Double ;
MetaSubstThis. Object ::= Object "[" "ξ" "↦" Object "]" ;
MetaContextualize. Object ::= "⌈" Object "," Object "⌉" ;
MetaObject. Object ::= ObjectMetaId ;
MetaTailContext. Object ::= Object "*" TailMetaId ;
MetaFunction. Object ::= MetaFunctionName "(" Object ")" ;
AlphaBinding. Binding ::= Attribute "↦" Object ;
EmptyBinding. Binding ::= Attribute "↦" "∅" ;
DeltaBinding. Binding ::= "Δ" "⤍" Bytes ;
DeltaEmptyBinding. Binding ::= "Δ" "⤍" "∅" ;
LambdaBinding. Binding ::= "λ" "⤍" Function ;
MetaBindings. Binding ::= BindingsMetaId ;
MetaDeltaBinding. Binding ::= "Δ" "⤍" BytesMetaId ;
separator Binding "," ;
Phi. Attribute ::= "φ" ; -- decoratee object
Rho. Attribute ::= "ρ" ; -- parent object
Label. Attribute ::= LabelId ;
Alpha. Attribute ::= AlphaIndex ;
MetaAttr. Attribute ::= LabelMetaId ;
-- Additional symbols used as attributes in the rules
ObjectAttr. RuleAttribute ::= Attribute ;
DeltaAttr. RuleAttribute ::= "Δ" ;
LambdaAttr. RuleAttribute ::= "λ" ;
PeeledObject. PeeledObject ::= ObjectHead [ObjectAction] ;
HeadFormation. ObjectHead ::= "⟦" [Binding] "⟧" ;
HeadGlobal. ObjectHead ::= "Φ" ;
HeadThis. ObjectHead ::= "ξ" ;
HeadTermination. ObjectHead ::= "⊥" ;
ActionApplication. ObjectAction ::= "(" [Binding] ")" ;
ActionDispatch. ObjectAction ::= "." Attribute ;
separator ObjectAction "" ;