[GoLUG] Backus-Naur form -- revisited

Steve Litt slitt at troubleshooters.com
Wed Nov 15 18:36:15 EST 2023


David Billsbrough said on Wed, 15 Nov 2023 19:30:38 +0000

>Hello compiler fans and compiler nerds maybe likely to be,
>
>While this might skipping ahead a couple of phases for me, here is a
>link to extended Backus-Naur form for Pascal:
>
>  https://www.cs.kent.edu/~durand/CS43101Fall2004/resources/Pascal-EBNF.html

Thanks David. This is an OUTSTANDING reference!

You're obviously way ahead of me on this journey.  I feel like it's
1998 all over again.

This is obviously on the distant fringes of my IQ and abilities. Where
are Henry Richardson and Nickolai Zeldovich when we need them?

I put up an old "maze runner" Pascal program I wrote in 1988 on the
right and your referenced article on the left, and after a half hour of
study I concluded, "yes, the BNF on the left does describe the code
structure on the right".

I have a couple observations after reading your referenced BNF. These
observations are probably obvious to you but they were game changing
for me.

* Prioritize lots and lots of simple token type names over tricky token
  type definitions.

* The process for constructing this particular BNF appears to be the
  way a three year old maps things out, as shown below:

Kid: What's a program?

Parent: It's a program-heading followed by a block followed by a
period.

Kid: What's a program-heading?

Parent: It's the word "program" followed by an identifier followed by
an open quote followed by an identifier-list followed by a close quote
followed by a semicolon.

Kid: What's an identifier?

Parent: It's a letter followed by zero or more letters and/or digits.

Kid: What's a letter?

Parent: A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,
        a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y, or z.

In the preceding, the kid has gone down one single branch of a tree all
the way to the leaf node, the terminal node, the piece of info known to
the silicon in the computer. By my count there are 130 such branches.
It's a BIG job, but if done in tiny definition increments and following
the Kid/Parent process, I think it's doable by a mere mortal.

Your link was EBNF (Enhanced BNF), whereas mine was just BNF. I'm
liking your example a lot more because EBNF appears to use curly braces
for "zero or more" instead of using recursion, and therefore to me is
much more understandable. I asked ChatGTP if switching to EBNF was OK,
and it said it was OK, so I'm switching to EBNF from now on. See the
following article:

https://www.freecodecamp.org/news/what-are-bnf-and-ebnf/

Thanks,

SteveT

Steve Litt 

Autumn 2023 featured book: Rapid Learning for the 21st Century
http://www.troubleshooters.com/rl21



More information about the GoLUG mailing list