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
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
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.
EBNF4 Main Module
ENGINE
USEFILE
VAR11
SYNTAX
\ 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 ;