Skip to content

Commit

Permalink
Make a simpler, non-ambiguous grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
fizruk committed Dec 21, 2023
1 parent fd6c7cc commit 14270bf
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 277 deletions.
32 changes: 7 additions & 25 deletions eo-phi-normalizer/grammar/EO/Phi/Syntax.cf
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,24 @@
token Bytes ({"--"} | ["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 AlphaIndex ({"α0"} | {"α"} (digit - ["0"]) (digit)* ) ;

Program. Program ::= "{" [Binding] "}" ;

Formation. Object ::= "{" [Binding] "}" ;
Application. Object ::= AbstractObject "{" [Binding] "}" [Bindings];
Dispatch. Object ::= Dispatch ;
Termination. Object ::= "⊥";

AbstractFormation. AbstractObject ::= "{" [Binding] "}" ;
AbstractDispatch. AbstractObject ::= Dispatch ;
AbstractTermination. AbstractObject ::= "⊥" ;

DispatchedFormation. DispatchedObject ::= "{" [Binding] "}" ;
DispatchedTermination. DispatchedObject ::= "⊥" ;
Application. Object ::= Object "{" [Binding] "}" ;
Dispatch. Object ::= Object "." Attribute ;
Termination. Object ::= "⊥" ;

AlphaBinding. Binding ::= Attribute "↦" Object ;
EmptyBinding. Binding ::= Attribute "↦" "∅" ;
DeltaBinding. Binding ::= "Δ" "⤍" Bytes;
LambdaBinding. Binding ::= "λ" "⤍" ;
DeltaBinding. Binding ::= "Δ" "⤍" Bytes ;
LambdaBinding. Binding ::= "λ" "⤍" Function ;
separator Binding "," ;

Bindings. Bindings ::= "{" [Binding] "}" ;
separator Bindings "" ;

ObjectDispatch. Dispatch ::= DispatchedObject [Bindings] "." [Attribute] [Disp] ;
HomeDispatch. Dispatch ::= "Φ" "." [Attribute] [Disp] ;
ThisDispatch. Dispatch ::= "ξ" "." [Attribute] [Disp] ;

Phi. Attribute ::= "φ" ; -- decoratee object
Rho. Attribute ::= "ρ" ; -- parent object
Sigma. Attribute ::= "σ" ; -- ???
Sigma. Attribute ::= "σ" ; -- home object
VTX. Attribute ::= "ν" ; -- ???
Label. Attribute ::= LabelId ;
Alpha. Attribute ::= AlphaIndex ;
separator nonempty Attribute "." ;

Disp. Disp ::= "{" [Binding] "}" Bindings "." [Attribute] ;
separator Disp "" ;
49 changes: 49 additions & 0 deletions eo-phi-normalizer/grammar/EO/Phi/Syntax.old.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- ==========================================================
-- BNFC grammar for φ-programs (translated from EO)
-- ==========================================================
--
-- This grammar is a (manual) translation of Phi.g4 grammar from objectionary/eo:
-- https://github.com/objectionary/eo/blob/fa24c7cc47e1ac473fb930f3a08ccc4d88d9d1e3/eo-parser/src/main/antlr4/org/eolang/parser/Phi.g4

token Bytes ({"--"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] ({"-"} ["0123456789ABCDEF"] ["0123456789ABCDEF"])* {"--"}) ;
token Function upper (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
token LabelId lower (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ;
token AlphaIndex ({"α0"} | {"α"} (digit - ["0"]) (digit)* ) ;

Program. Program ::= "{" [Binding] "}" ;

Formation. Object ::= "{" [Binding] "}" ;
Application. Object ::= AbstractObject "{" [Binding] "}" [Bindings] ;
Dispatch. Object ::= Dispatch ;
Termination. Object ::= "⊥";

AbstractFormation. AbstractObject ::= "{" [Binding] "}" ;
AbstractDispatch. AbstractObject ::= Dispatch ;
AbstractTermination. AbstractObject ::= "⊥" ;

DispatchedFormation. DispatchedObject ::= "{" [Binding] "}" ;
DispatchedTermination. DispatchedObject ::= "⊥" ;

AlphaBinding. Binding ::= Attribute "↦" Object ;
EmptyBinding. Binding ::= Attribute "↦" "∅" ;
DeltaBinding. Binding ::= "Δ" "⤍" Bytes ;
LambdaBinding. Binding ::= "λ" "⤍" Function ;
separator Binding "," ;

Bindings. Bindings ::= "{" [Binding] "}" ;
separator Bindings "" ;

ObjectDispatch. Dispatch ::= DispatchedObject [Bindings] "." [Attribute] [Disp] ;
HomeDispatch. Dispatch ::= "Φ" "." [Attribute] [Disp] ;
ThisDispatch. Dispatch ::= "ξ" "." [Attribute] [Disp] ;

Phi. Attribute ::= "φ" ; -- decoratee object
Rho. Attribute ::= "ρ" ; -- parent object
Sigma. Attribute ::= "σ" ; -- ???
VTX. Attribute ::= "ν" ; -- ???
Label. Attribute ::= LabelId ;
Alpha. Attribute ::= AlphaIndex ;
separator nonempty Attribute "." ;

Disp. Disp ::= "{" [Binding] "}" Bindings "." [Attribute] ;
separator Disp "" ;
64 changes: 6 additions & 58 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 7 additions & 23 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 14270bf

Please sign in to comment.