mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 18:03:31 +01:00
First time parsing doesn't error out with a syntax error. No usable AST is produced, strings are not returned from lexer, and AST lists aren't lists, really. TEXT:="Hello world!"; had to be excluded from the example, because I don't get how this could be parsed with the given syntax. There's a special sequence "all visible characters", but any lexer regex I could think of will also match the types defining "alphabetic character" and return the respective tokens (e.g. T_A) or vice-versa, depending on the order in the lexer input file. I suppose, the only sensible way to handle this, is to define "all visible characters" by defining the tokens for the missing characters, and then use them along T_A ... T_Z or their derived types. Signed-off-by: Jan Lindemann <jan@janware.com>
16 lines
859 B
EBNF
16 lines
859 B
EBNF
(* a simple program syntax in EBNF − Wikipedia *)
|
||
program = 'PROGRAM', white space, identifier, white space,
|
||
'BEGIN', white space,
|
||
{ assignment, ";", white space },
|
||
'END.', [ white space ];
|
||
identifier = alphabetic character, { alphabetic character | digit } ;
|
||
number = [ "-" ], digit, { digit } ;
|
||
string = '"' , { all characters }, '"' ;
|
||
assignment = identifier , ":=" , ( number | identifier | string ) ;
|
||
alphabetic character = "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" ;
|
||
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
|
||
white space = ? white space characters ? ;
|
||
all characters = ? all visible characters ? ;
|