Skip to content

Instantly share code, notes, and snippets.

@Bruno-366
Last active July 18, 2023 14:43
Show Gist options
  • Save Bruno-366/4ba65477bd31cccb5f28148d1a76e4a5 to your computer and use it in GitHub Desktop.
Save Bruno-366/4ba65477bd31cccb5f28148d1a76e4a5 to your computer and use it in GitHub Desktop.
Exploring how to define a Grammar in APL using BNF-like syntax

BNF in APL

Exploring how to define a Grammar in APL using BNF-like syntax

⍝ Example Grammar:
HELLO ← 'hello world'
BYE ← 'bye world'
CONVERSATION ← HELLO , ' and then ' , BYE
⍝ CAPITALIZED words are the non-terminals
⍝ 'Strings' are the terminals
⍝ Concatenation is done with ,
⍝ Output:
HELLO
hello world
BYE
bye world
CONVERSATION
hello world and then bye world
@Bruno-366
Copy link
Author

Bruno-366 commented Aug 15, 2021

          HELLO    'hello world' 'hey world'
      HELLO
┌───────────┐
│hello world│
├───────────┤
│hey world  │
└───────────┘
          BYE   'bye world' 'cya world'
      BYE
┌─────────┐
│bye world│
├─────────┤
│cya world│
└─────────┘
          ]display , (HELLO ., BYE)
───────────────────────┐
───────────────────┐ │
│ │hello worldbye world│ │
│ └────────────────────┘ │
│ ┌───────────────────┐ │
│ │hello worldcya world│ │
│ └────────────────────┘ │
│ ┌─────────────────┐   │
│ │hey worldbye world│   │
│ └──────────────────┘   │
│ ┌─────────────────┐   │
│ │hey worldcya world│   │
│ └──────────────────┘   │
───────────────────────┘
          ( 'hey world ') ., ( 'cya world')
┌───────────────────┐
hey world cya world
└───────────────────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment