Grammar optimization from NetBSD: Two adjacent string constants are merged.
This commit is contained in:
parent
795a06b58c
commit
c95b96020f
5
FIXES
5
FIXES
@ -25,12 +25,17 @@ THIS SOFTWARE.
|
||||
This file lists all bug fixes, changes, etc., made since the AWK book
|
||||
was sent to the printers in August, 1987.
|
||||
|
||||
July 28, 2019:
|
||||
Import grammar optimization from NetBSD: Two string constants
|
||||
concatenated together get turned into a single string.
|
||||
|
||||
July 26, 2019:
|
||||
Support POSIX-specified C-style escape sequences "\a" (alarm)
|
||||
and "\v" (vertical tab) in command line arguments and regular
|
||||
expressions, further to the support for them in strings added on
|
||||
Apr 9, 1989. These now no longer match as literal "a" and "v"
|
||||
characters (as they don't on other awk implementations).
|
||||
Thanks to Martijn Dekker.
|
||||
|
||||
July 17, 2019:
|
||||
Pull in a number of code cleanups and minor fixes from
|
||||
|
@ -71,6 +71,7 @@ Node *arglist = 0; /* list of args for current function */
|
||||
%type <i> do st
|
||||
%type <i> pst opt_pst lbrace rbrace rparen comma nl opt_nl and bor
|
||||
%type <i> subop print
|
||||
%type <cp> string
|
||||
|
||||
%right ASGNOP
|
||||
%right '?'
|
||||
@ -348,6 +349,11 @@ subop:
|
||||
SUB | GSUB
|
||||
;
|
||||
|
||||
string:
|
||||
STRING
|
||||
| string STRING { $$ = catstr($1, $2); }
|
||||
;
|
||||
|
||||
term:
|
||||
term '/' ASGNOP term { $$ = op2(DIVEQ, $1, $4); }
|
||||
| term '+' term { $$ = op2(ADD, $1, $3); }
|
||||
@ -394,7 +400,7 @@ term:
|
||||
| SPLIT '(' pattern comma varname ')'
|
||||
{ $$ = op4(SPLIT, $3, makearr($5), NIL, (Node*)STRING); } /* default */
|
||||
| SPRINTF '(' patlist ')' { $$ = op1($1, $3); }
|
||||
| STRING { $$ = celltonode($1, CCON); }
|
||||
| string { $$ = celltonode($1, CCON); }
|
||||
| subop '(' reg_expr comma pattern ')'
|
||||
{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, rectonode()); }
|
||||
| subop '(' pattern comma pattern ')'
|
||||
|
2
main.c
2
main.c
@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
****************************************************************/
|
||||
|
||||
const char *version = "version 20190726";
|
||||
const char *version = "version 20190728";
|
||||
|
||||
#define DEBUG
|
||||
#include <stdio.h>
|
||||
|
1
proto.h
1
proto.h
@ -111,6 +111,7 @@ extern char *getsval(Cell *);
|
||||
extern char *getpssval(Cell *); /* for print */
|
||||
extern char *tostring(const char *);
|
||||
extern char *qstring(const char *, int);
|
||||
extern Cell *catstr(Cell *, Cell *);
|
||||
|
||||
extern void recinit(unsigned int);
|
||||
extern void initgetrec(void);
|
||||
|
16
tran.c
16
tran.c
@ -516,6 +516,22 @@ char *tostring(const char *s) /* make a copy of string s */
|
||||
return(p);
|
||||
}
|
||||
|
||||
Cell *catstr(Cell *a, Cell *b) /* concatenate a and b */
|
||||
{
|
||||
Cell *c;
|
||||
char *p;
|
||||
char *sa = getsval(a);
|
||||
char *sb = getsval(b);
|
||||
size_t l = strlen(sa) + strlen(sb) + 1;
|
||||
p = malloc(l);
|
||||
if (p == NULL)
|
||||
FATAL("out of space concatenating %s and %s", sa, sb);
|
||||
snprintf(p, l, "%s%s", sa, sb);
|
||||
c = setsymtab(p, p, 0.0, CON|STR|DONTFREE, symtab);
|
||||
free(p);
|
||||
return c;
|
||||
}
|
||||
|
||||
char *qstring(const char *is, int delim) /* collect string up to next delim */
|
||||
{
|
||||
const char *os = is;
|
||||
|
Loading…
Reference in New Issue
Block a user