Extended BNF 4.0 Main Module


Extended BNF 4.0 Copyright

Extended Backus-Naur Form 4.0
Formerly, XBNF through version 3.5
(c) Copyright 2002, 2006, 2008, 2009, 2014
Curtis G. Flippin
Flippin Engineering
All Rights Reserved

Not to be confused with Extreme BNF (XBNF) developed
by Dr. R. J. Botting, CSUSB

EBNF Development History

Developed for Win7-32 using Win32Forth version 6.12.00
Build 2 and ported to Win32Forth version 6.14.04 Build 1.

Originally developed from a concept published in ACM:
"A BNF Parser in FORTH", Bradford J. Rodriguez
ACM SIGFORTH Newsletter Volume 2, Issue 2
(December, 1990)  ISSN: 1047-4544

Additional References:

1. Extended Backus-Naur Form Standard
   ISO/IEC 14977:1996(E)
   http://standards.iso.org/ittf/PubliclyAvailableStandards/index.html
2. "Deterministic Parsing of Ambiguous Grammars"
   A. V. Aho and S. C. Johnson, Bell Laboratories
   and J. D. Ullman, Princeton University
   Communications of the ACM Volume 18 Number 8
   August 1975
3. "Compilers and Compiler Generators"
   P. D. Terry, Rhodes University, 1996
   http://scifac.ru.ac.za/compilers/

Version History:

1.0  Alpha Baseline to partial BNF Standard
2.0  Beta To 90% BNF Standard
3.0  Alpha Baseline to partial Extended BNF Standard
3.1  Beta to 95% EBNF Standard
3.14   99% EBNF Standard
3.5  Performance Update
4.0  Win32 Beta Baseline to EBNF Standard
     This is a total re-write.
     The current version has a very good five-year
     performance record.

EBNF 4.0 Modules:

EBNF4 Main Module
   ENGINE
       USEFILE
           VAR11
   SYNTAX

EBNF4 Module Forth Code:

\ ebnf4.f is the main load module

anew -ebnf4.f

\ Place EBNF definitions in their own vocabulary

ONLY FORTH ALSO DEFINITIONS

VOCABULARY EBNF

ALSO EBNF DEFINITIONS
DECIMAL

needs engine
needs syntax

\ Reset EBNF Parms

\ Reset Data Stack
\ This function is here as a user convenience. The Forth
\ data stack should normally be reset prior to performing
\ an EBNF parse.
\ -- W32F 6.14 Update: Use RESET-STACKS --
\ : reset-s     ( ??? -)
\ sp0 @ sp!
\ ;

\ Reset EBNF Parms
\ These parameters are reset each time a new source file is
\ open for parsing. These are the key EBNF parameters:
\ Success - This is a flag value that is set to reflect the
\   outcome of every parsed token analysis and affects the
\   results of every EBNF production. Upon completion of a
\   parse, Success? will return "true" if it was successful
\   or "false" if it was not.
\ Uin - Variable Uin is the offset into the source file line
\   buffer and works just like ">in" does. "usource" returns
\   the char-addr of the line character pointed to by Uin. And
\   "@token" returns the token character.
\ Uline - Value Uline is the current file text line number being
\   parsed. It is initialized to zero here but "open-ebnf" will
\   call function "+uline" after the source file is open which
\   will read the first line and set Uline = 1. "+uline" always
\   advances Uline, and the source file line, by exactly 1 making
\   it handy if you need to skip a line. "Uin" and "Uline" are the
\   primary parse pointers used to control the advancement or
\   back-tracking of the source file analysis.
\ SaveUin, SaveUline, -Tflag - Are used to track state transitions
\   for serial syntactic-exceptions. Users should not alter these
\   values.

: reset-ebnf-parms
true to Success
Uin off
0 to Uline
0 to SaveUin
Uline to SaveUline
true to -Tflag
;

\ A main parser/compiler function will call this function to
\ initiate the scan and open the file specified in the string
\ and length arguments. Order of operation:
\ (1) Load EBNF 4.0;
\ (2) Load your EBNF defined grammar;
\ (3) Load your parse program;
\ (4) Run your parse program.
\ : my-parse-program s" my-source-file" open-ebnf my-EBNF-defined-grammar
\   Success? if great else not-so-great then ;

: open-ebnf     ( c-addr u -) ( full path file spec)
reset-ebnf-parms
open
reset-stacks
+uline
;

BACK