Skip to content

Performance tips for grammars with case insensitive keywords? #17

Description

@jsm174

We are using node-ebnf to transpile vbscript into javascript in an attempt to run Visual Pinball in a web browser.

Currently we go through a two pass approach. The first pass format's the original script file to remove comments, standardize keyword case, and remove extra whitespace. The second pass converts the node-ebnf ast tree into a js ast tree.

To standardize the keyword case, we end up taking a rule like:

Keywords ::= 'And' | 'ByVal' | 'ByRef' | 'Case' | 'Call' | 'Class' | 'Const' | 'Default' | 'Dim' | 'Do' | 'Each' | 'ElseIf' | 'Else' | 'Empty' | 'End' | 'Erase' | 'Error' | 'Eqv' | 'Exit' | 'Explicit' | 'False' | 'For' | 'Function' | 'Get' | 'GoTo' | 'If' | 'In' | 'Is' | 'Let' | 'Loop' | 'Mod' | 'New' | 'Next' | 'Nothing' | 'Not' | 'Null' | 'On' | 'Option' | 'Or' | 'Preserve' | 'Private' | 'Property' | 'Public' | 'ReDim' | 'Resume' | 'Select' | 'Set' | 'Step' | 'Sub' | 'Then' | 'To' | 'True' | 'Until' | 'While' | 'WEnd' | 'With' | 'Xor' Keyword ::= Keywords ![A-Za-z0-9_]

and converting it to:

Keywords ::= ('A'|'a')('N'|'n')('D'|'d')|('B'|'b')('Y'|'y')('V'|'v')('A'|'a')('L'|'l')|('B'|'b')('Y'|'y')('R'|'r')('E'|'e')('F'|'f')|('C'|'c')('A'|'a')('S'|'s')('E'|'e')|('C'|'c')('A'|'a')('L'|'l')('L'|'l')|('C'|'c')('L'|'l')('A'|'a')('S'|'s')('S'|'s')|('C'|'c')('O'|'o')('N'|'n')('S'|'s')('T'|'t')|('D'|'d')('E'|'e')('F'|'f')('A'|'a')('U'|'u')('L'|'l')('T'|'t')|('D'|'d')('I'|'i')('M'|'m')|('D'|'d')('O'|'o')|('E'|'e')('A'|'a')('C'|'c')('H'|'h')|('E'|'e')('L'|'l')('S'|'s')('E'|'e')('I'|'i')('F'|'f')|('E'|'e')('L'|'l')('S'|'s')('E'|'e')|('E'|'e')('M'|'m')('P'|'p')('T'|'t')('Y'|'y')|('E'|'e')('N'|'n')('D'|'d')|('E'|'e')('R'|'r')('A'|'a')('S'|'s')('E'|'e')|('E'|'e')('R'|'r')('R'|'r')('O'|'o')('R'|'r')|('E'|'e')('Q'|'q')('V'|'v')|('E'|'e')('X'|'x')('I'|'i')('T'|'t')|('E'|'e')('X'|'x')('P'|'p')('L'|'l')('I'|'i')('C'|'c')('I'|'i')('T'|'t')|('F'|'f')('A'|'a')('L'|'l')('S'|'s')('E'|'e')|('F'|'f')('O'|'o')('R'|'r')|('F'|'f')('U'|'u')('N'|'n')('C'|'c')('T'|'t')('I'|'i')('O'|'o')('N'|'n')|('G'|'g')('E'|'e')('T'|'t')|('G'|'g')('O'|'o')('T'|'t')('O'|'o')|('I'|'i')('F'|'f')|('I'|'i')('N'|'n')|('I'|'i')('S'|'s')|('L'|'l')('E'|'e')('T'|'t')|('L'|'l')('O'|'o')('O'|'o')('P'|'p')|('M'|'m')('O'|'o')('D'|'d')|('N'|'n')('E'|'e')('W'|'w')|('N'|'n')('E'|'e')('X'|'x')('T'|'t')|('N'|'n')('O'|'o')('T'|'t')('H'|'h')('I'|'i')('N'|'n')('G'|'g')|('N'|'n')('O'|'o')('T'|'t')|('N'|'n')('U'|'u')('L'|'l')('L'|'l')|('O'|'o')('N'|'n')|('O'|'o')('P'|'p')('T'|'t')('I'|'i')('O'|'o')('N'|'n')|('O'|'o')('R'|'r')|('P'|'p')('R'|'r')('E'|'e')('S'|'s')('E'|'e')('R'|'r')('V'|'v')('E'|'e')|('P'|'p')('R'|'r')('I'|'i')('V'|'v')('A'|'a')('T'|'t')('E'|'e')|('P'|'p')('R'|'r')('O'|'o')('P'|'p')('E'|'e')('R'|'r')('T'|'t')('Y'|'y')|('P'|'p')('U'|'u')('B'|'b')('L'|'l')('I'|'i')('C'|'c')|('R'|'r')('E'|'e')('D'|'d')('I'|'i')('M'|'m')|('R'|'r')('E'|'e')('S'|'s')('U'|'u')('M'|'m')('E'|'e')|('S'|'s')('E'|'e')('L'|'l')('E'|'e')('C'|'c')('T'|'t')|('S'|'s')('E'|'e')('T'|'t')|('S'|'s')('T'|'t')('E'|'e')('P'|'p')|('S'|'s')('U'|'u')('B'|'b')|('T'|'t')('H'|'h')('E'|'e')('N'|'n')|('T'|'t')('O'|'o')|('T'|'t')('R'|'r')('U'|'u')('E'|'e')|('U'|'u')('N'|'n')('T'|'t')('I'|'i')('L'|'l')|('W'|'w')('H'|'h')('I'|'i')('L'|'l')('E'|'e')|('W'|'w')('E'|'e')('N'|'n')('D'|'d')|('W'|'w')('I'|'i')('T'|'t')('H'|'h')|('X'|'x')('O'|'o')('R'|'r')

If we could assume the case of the script was correct, not splitting the keywords like this gives us a 40% gain in performance.

Is there any tips or suggestions you could offer on case insensitive grammars?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions