summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-08-17 19:26:42 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-08-17 19:26:42 -0700
commitb5bcecee77e513b656973476dd7b76be9038b097 (patch)
tree5f847ec77abb9ae15dec3a727ddb29697811c4ea /regex.c
parent2399bf36c10ec9f7011008a76f96847be7255c9d (diff)
downloadtxr-b5bcecee77e513b656973476dd7b76be9038b097.tar.gz
txr-b5bcecee77e513b656973476dd7b76be9038b097.tar.bz2
txr-b5bcecee77e513b656973476dd7b76be9038b097.zip
parser: more efficient treatment of string literals.
In this patch we switch the string literal parser from right recursion to left recursion, so that it doesn't require a Yacc stack depth proportional to the number of characters in the literal. Secondly, we build the string directly in a syntax-directed way, rather than building a list of characters and then walking the list to build a string. This was discovered as a byacc regression, though the fix is not for the sake of byacc but basic efficiency. The Sep 29, 2015 commit 111650e235ab2e529fa1529b1c9a23688a11cd1f "Implementation of static slots for structures." extended the string literal in the struct.tl test case in such a way that if the parser is generated by byacc rather than GNU Bison, the test case fails with a "yacc stack overflow". I haven't done any regression testing with byacc in over two years so I didn't notice this. Quasiliterals could use this treatment also. Word list literals benefit from this change, but they still use a Yacc stack depth proportional to the number of words, since the accumulation of words is right recursive. * parser.y (lit_char_helper): Static function removed. (restlitchar): New grammar nonterminal symbol. (strlit, quasi_item, wordslit): No need to call lit_char_helper. (litchars): A litchars is now either a single LITCHAR, or else a LITCHARS followed by a sequence of more. This sequence is a separate production rule called restlitchar, which is purely left recursive. (If litchars is made directly left recursive without this helper rule, intractable reduce/reduce and shift/reduce conflicts arise.)
Diffstat (limited to 'regex.c')
0 files changed, 0 insertions, 0 deletions