bus labels with trailing chars (A[15:0]_xx): fix rule conflicts in grammar parser. Add a trailer token in lexer

This commit is contained in:
stefan schippers 2023-09-17 21:17:35 +02:00
parent 898cfcc2e1
commit e5286a7f12
2 changed files with 28 additions and 3 deletions

View File

@ -285,6 +285,7 @@ int *idx; /* for bus index & bus index ranges */
%token <val> B_IDXNUM
%token <val> B_DOUBLEDOT
%token <str> B_NAME
%token <str> B_TRAILER
%token <str> B_LINE
/* BISON Declarations: non terminal symbols*/
%type <ptr> list
@ -292,6 +293,7 @@ int *idx; /* for bus index & bus index ranges */
%type <idx> index_nobracket
/* operator precedences (bottom = highest) and associativity */
%left B_TRAILER
%left B_NAME
%left B_DOUBLEDOT
%left ':'
@ -384,7 +386,7 @@ list: B_NAME {
my_free(_ALLOC_ID_, &$3);
idxsize=INITIALIDXSIZE;
}
| B_NAME '[' index ']' B_NAME
| B_NAME '[' index ']' B_TRAILER
{
dbg(dbg_var, "yyparse(): B_NAME [ index ] B_NAME, $1=%s $3=%d, $5=%s\n", $1, $3[0], $5);
$$.str=expandlabel_strbus_suffix($1, $3, $5);
@ -404,7 +406,7 @@ list: B_NAME {
my_free(_ALLOC_ID_, &$3);
idxsize=INITIALIDXSIZE;
}
| B_NAME '[' index_nobracket ']' B_NAME
| B_NAME '[' index_nobracket ']' B_TRAILER
{
dbg(dbg_var, "yyparse(): B_NAME [ index_nobracket ] $1=%s $3=%d, $5=%s\n",$1, $3[0], $5);
$$.str=expandlabel_strbus_nobracket_suffix($1, $3, $5);

View File

@ -139,6 +139,7 @@ const char *expandlabel(const char *s, int *m)
*/
%x index
%x trailer
%x mult
SP [ \t\n]*
@ -185,6 +186,19 @@ ID_EXT_PARENTHESIS ([-~"#+/=_a-zA-Z][-#!@\\/:.=_+a-zA-Z0-9]*\([-~"#!@\\/:.=_+a-z
}
} /* end <mult> */
<trailer>{
/* recognize characters after a bus label: AA[33:31]_xx --> _xx */
{IDX_ID_N} {
yylval.ptr.str=NULL;/*19102004 */
my_strdup(_ALLOC_ID_, &yylval.ptr.str, yytext); /* freed after use in expandlabel.y */
if(parselabel_debug >= 3) fprintf(errfp, "yylex(): B_TRAILER: |%s|\n", yytext);
BEGIN(INITIAL);
return B_TRAILER;
}
}
/* node indexes: "3:2" "5:1:2" "5..1" "7..1..2" "b:a" "c:b:a" .... */
<index>{
{INT} {
@ -196,9 +210,18 @@ ID_EXT_PARENTHESIS ([-~"#+/=_a-zA-Z][-#!@\\/:.=_+a-zA-Z0-9]*\([-~"#!@\\/:.=_+a-z
if(parselabel_debug >= 3) fprintf(errfp, "yylex(): B_DOUBLEDOT: |%s|\n", yytext);
return B_DOUBLEDOT;
}
/* end vector node index "...]" followed by trailing chars (excluding , and *) : A[33:31]_xx */
\]/[^*,] {
if(parselabel_debug >= 3) fprintf(errfp, "yylex(): close bracket2: %s\n", yytext);
BEGIN(trailer);
return yytext[0];
}
/* end vector node index "...]" */
\] {
if(parselabel_debug >= 3) fprintf(errfp, "yylex(): close bracket: %s\n", yytext);
if(parselabel_debug >= 3) fprintf(errfp, "yylex(): close bracket1: %s\n", yytext);
BEGIN(INITIAL);
return yytext[0];
}