Simplify and improve parser.

Clarify manpage.
This commit is contained in:
Andrey A. Chernov 1996-10-16 03:12:22 +00:00
parent 856541b91f
commit 7c4355120c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=18955
3 changed files with 38 additions and 244 deletions

View File

@ -124,11 +124,7 @@ representation, and can be only one character in length.
.Pp .Pp
Symbol names cannot be specified in Symbol names cannot be specified in
.Ar substitute .Ar substitute
fields. Symbol names also cannot be combined with fields.
any other representation, such as, <c>h, c<h>,
<c>\ex68, or <c><h>. Symbol names can be used with
primary and secondary ordering as in the following
example.
.Pp .Pp
The The
.Ar charmap .Ar charmap
@ -153,14 +149,15 @@ statement is optional.
.Ar order order_list .Ar order order_list
.Pp .Pp
.Ar order_list .Ar order_list
is a list of symbols, separated by semi colons, that defines the collating sequence. The is a list of symbols, separated by semi colons, that defines the
collating sequence. The
special symbol special symbol
.Ar ... .Ar ...
specifies, in a short-hand specifies, in a short-hand
form, symbols that are sequential in machine code form, symbols that are sequential in machine code
order. order.
.Pp .Pp
A symbol can be up to two characters in length and An order list element
can be represented in any one of the following can be represented in any one of the following
ways: ways:
.Bl -bullet .Bl -bullet
@ -208,18 +205,33 @@ Symbols
.Ar \er , .Ar \er ,
.Ar \ev .Ar \ev
are permitted in its usual C-language meaning are permitted in its usual C-language meaning
.It
The symbol range (for example,
.Ar a;...;z )
.It
Comma-separated symbols, ranges and chains enclosed in parenthesis (for example
.Ar \&(
.Ar sym1 ,
.Ar sym2 ,
.Ar ...
.Ar \&) )
are assigned the
same primary ordering but different secondary
ordering.
.It
Comma-separated symbols, ranges and chains enclosed in curly brackets (for example
.Ar \&{
.Ar sym1 ,
.Ar sym2 ,
.Ar ...
.Ar \&} )
are assigned the same primary ordering only.
.El .El
.Pp .Pp
The backslash character The backslash character
.Ar \e .Ar \e
is used for continuation. In this case, no characters are permitted is used for continuation. In this case, no characters are permitted
after the backslash character. And as a quotation mark. after the backslash character.
.Pp
Symbols enclosed in parentheses are assigned the
same primary ordering but different secondary
ordering. Symbols enclosed in curly brackets are
assigned only the same primary ordering
and different secondary ordering.
.Sh EXIT STATUS .Sh EXIT STATUS
.Ar colldef .Ar colldef
exits with the following values: exits with the following values:

View File

@ -61,7 +61,6 @@ char *out_file = "LC_COLLATE";
} }
%token SUBSTITUTE WITH ORDER RANGE %token SUBSTITUTE WITH ORDER RANGE
%token <str> STRING %token <str> STRING
%token <str> NAME
%token <str> CHAIN %token <str> CHAIN
%token <str> DEFN %token <str> DEFN
%token <ch> CHAR %token <ch> CHAR
@ -116,17 +115,6 @@ item : CHAR { __collate_char_pri_table[$1].prim = prim_pri++; }
yyerror("__collate_chain_pri_table overflow"); yyerror("__collate_chain_pri_table overflow");
strcpy(__collate_chain_pri_table[chain_index].str, $1); strcpy(__collate_chain_pri_table[chain_index].str, $1);
__collate_chain_pri_table[chain_index++].prim = prim_pri++; __collate_chain_pri_table[chain_index++].prim = prim_pri++;
}
| NAME {
u_int i;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0)
goto findi;
yyerror("Name <%s> not defined", $1);
findi:
__collate_char_pri_table[i].prim = prim_pri++;
} }
| CHAR RANGE CHAR { | CHAR RANGE CHAR {
u_int i; u_int i;
@ -136,68 +124,6 @@ item : CHAR { __collate_char_pri_table[$1].prim = prim_pri++; }
for (i = $1; i <= $3; i++) for (i = $1; i <= $3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri++; __collate_char_pri_table[(u_char)i].prim = prim_pri++;
}
| NAME RANGE CHAR {
u_int i, c1;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto find1;
}
yyerror("Name <%s> not defined", $1);
find1:
if ($3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, $3);
for (i = c1; i <= $3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri++;
}
| CHAR RANGE NAME {
u_int i, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto find3;
}
yyerror("Name <%s> not defined", $3);
find3:
if (c3 <= $1)
yyerror("Illegal range 0x%02x -- 0x%02x",
$1, c3);
for (i = $1; i <= c3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri++;
}
| NAME RANGE NAME {
u_int i, c1, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto find21;
}
yyerror("Name <%s> not defined", $1);
find21:
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto find23;
}
yyerror("Name <%s> not defined", $3);
find23:
if (c3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, c3);
for (i = c1; i <= c3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri++;
} }
| '{' prim_order_list '}' { | '{' prim_order_list '}' {
prim_pri++; prim_pri++;
@ -225,79 +151,6 @@ prim_sub_item : CHAR {
for (i = $1; i <= $3; i++) for (i = $1; i <= $3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri; __collate_char_pri_table[(u_char)i].prim = prim_pri;
}
| NAME RANGE CHAR {
u_int i, c1;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto findpsi1;
}
yyerror("Name <%s> not defined", $1);
findpsi1:
if ($3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, $3);
for (i = c1; i <= $3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri;
}
| CHAR RANGE NAME {
u_int i, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto findpsi3;
}
yyerror("Name <%s> not defined", $3);
findpsi3:
if (c3 <= $1)
yyerror("Illegal range 0x%02x -- 0x%02x",
$1, c3);
for (i = $1; i <= c3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri;
}
| NAME RANGE NAME {
u_int i, c1, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto findpsi21;
}
yyerror("Name <%s> not defined", $1);
findpsi21:
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto findpsi23;
}
yyerror("Name <%s> not defined", $3);
findpsi23:
if (c3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, c3);
for (i = c1; i <= c3; i++)
__collate_char_pri_table[(u_char)i].prim = prim_pri;
}
| NAME {
u_int i;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0)
goto findpsi;
yyerror("Name <%s> not defined", $1);
findpsi:
__collate_char_pri_table[i].prim = prim_pri;
} }
| CHAIN { | CHAIN {
if (chain_index >= TABLE_SIZE - 1) if (chain_index >= TABLE_SIZE - 1)
@ -321,86 +174,6 @@ sec_sub_item : CHAR {
__collate_char_pri_table[(u_char)i].prim = prim_pri; __collate_char_pri_table[(u_char)i].prim = prim_pri;
__collate_char_pri_table[(u_char)i].sec = sec_pri++; __collate_char_pri_table[(u_char)i].sec = sec_pri++;
} }
}
| NAME RANGE CHAR {
u_int i, c1;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto findssi1;
}
yyerror("Name <%s> not defined", $1);
findssi1:
if ($3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, $3);
for (i = c1; i <= $3; i++) {
__collate_char_pri_table[(u_char)i].prim = prim_pri;
__collate_char_pri_table[(u_char)i].sec = sec_pri++;
}
}
| CHAR RANGE NAME {
u_int i, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto findssi3;
}
yyerror("Name <%s> not defined", $3);
findssi3:
if (c3 <= $1)
yyerror("Illegal range 0x%02x -- 0x%02x",
$1, c3);
for (i = $1; i <= c3; i++) {
__collate_char_pri_table[(u_char)i].prim = prim_pri;
__collate_char_pri_table[(u_char)i].sec = sec_pri++;
}
}
| NAME RANGE NAME {
u_int i, c1, c3;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0) {
c1 = i;
goto findssi21;
}
yyerror("Name <%s> not defined", $1);
findssi21:
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $3) == 0) {
c3 = i;
goto findssi23;
}
yyerror("Name <%s> not defined", $3);
findssi23:
if (c3 <= c1)
yyerror("Illegal range 0x%02x -- 0x%02x",
c1, c3);
for (i = c1; i <= c3; i++) {
__collate_char_pri_table[(u_char)i].prim = prim_pri;
__collate_char_pri_table[(u_char)i].sec = sec_pri++;
}
}
| NAME {
u_int i;
for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], $1) == 0)
goto findssi;
yyerror("Name <%s> not defined", $1);
findssi:
__collate_char_pri_table[i].prim = prim_pri;
__collate_char_pri_table[i].sec = sec_pri++;
} }
| CHAIN { | CHAIN {
if (chain_index >= TABLE_SIZE - 1) if (chain_index >= TABLE_SIZE - 1)

View File

@ -41,6 +41,7 @@ int line_no = 1, save_no;
u_char buf[STR_LEN], *ptr; u_char buf[STR_LEN], *ptr;
FILE *map_fp; FILE *map_fp;
extern char map_name[]; extern char map_name[];
extern u_char charmap_table[UCHAR_MAX + 1][STR_LEN];
YY_BUFFER_STATE main_buf, map_buf; YY_BUFFER_STATE main_buf, map_buf;
#ifdef FLEX_DEBUG #ifdef FLEX_DEBUG
YYSTYPE yylval; YYSTYPE yylval;
@ -137,13 +138,21 @@ YYSTYPE yylval;
*ptr++ = '"'; *ptr++ = '"';
} }
<name>\> { <name>\> {
u_int i;
if (ptr == buf) if (ptr == buf)
errx(EX_UNAVAILABLE, "name expected near line %u", errx(EX_UNAVAILABLE, "non-empty name expected near line %u",
line_no); line_no);
*ptr = '\0'; *ptr = '\0';
strcpy(yylval.str, buf); for (i = 0; i <= UCHAR_MAX; i++)
if (strcmp(charmap_table[i], buf) == 0)
goto findit;
errx(EX_UNAVAILABLE, "name <%s> not 'charmap'-defined near line %u",
buf, line_no);
findit:
yylval.ch = i;
BEGIN(INITIAL); BEGIN(INITIAL);
return NAME; return CHAR;
} }
<string>\" { <string>\" {
*ptr = '\0'; *ptr = '\0';