HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //snap/google-cloud-cli/394/platform/gsutil/third_party/pyparsing/examples/ebnf_number_words.py
#
# ebnftest_number_parser.py
#
#     BNF from number_parser.py:
#
#     optional_and ::= ["and" | "-"]
#     optional_dash ::= ["-"]
#     units ::= "one" | "two" | "three" | ... | "nine"
#     tens ::= "twenty" | "thirty" | ... | "ninety"
#     one_to_99 ::= units | ten | teens | (tens [optional_dash units])
#     ten ::= "ten"
#     teens ::= "eleven" | "twelve" | ... | "nineteen"
#     hundreds ::= (units | teens_only | tens optional_dash units) "hundred"
#     thousands ::= one_to_99 "thousand"
#
#     # number from 1-999,999
#     number ::= [thousands [optional_and]] [hundreds[optional_and]] one_to_99
#                | [thousands [optional_and]] hundreds
#                | thousands
#

import ebnf

grammar = """
    (*
    EBNF for number_words.py
    *)
    number = [thousands, [and]], [hundreds, [and]], [one_to_99];
    thousands = one_to_99, "thousand";
    hundreds_mult = units | teens | multiples_of_ten, ["-"], units; 
    hundreds = hundreds_mult, "hundred";
    teens = 
        "eleven"
        | "twelve"
        | "thirteen"
        | "fourteen"
        | "fifteen"
        | "sixteen"
        | "seventeen"
        | "eighteen"
        | "nineteen"
    ;
    one_to_99 = units | teens | ten | multiples_of_ten, [["-"], units];
    ten = "ten";
    multiples_of_ten = "twenty" | "thirty" | "forty" | "fifty" | "sixty" | "seventy" | "eighty" | "ninety";
    units = "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "eight" | "nine";
    and = "and" | "-";
    """

parsers = ebnf.parse(grammar)
number_parser = parsers["number"]

try:
    number_parser.create_diagram("ebnf_number_parser_diagram.html")
except Exception as e:
    print("Failed to create diagram for EBNF-generated number parser"
          f" - {type(e).__name__}: {e}")

number_parser.run_tests(
    """
    one
    seven
    twelve
    twenty six
    forty-two
    two hundred
    twelve hundred
    one hundred and eleven
    seven thousand and six
    twenty five hundred and one
    ninety nine thousand nine hundred and ninety nine

    # invalid
    twenty hundred
    """,
    full_dump=False
)