2016-09-29 2 views
0

대학에서 C 언어로 미니 셸을 만드는 프로젝트가 있습니다. 명령 행을 구문 분석하기 위해 필자는 lex 및 yacc 도구를 사용합니다. YACC로 컴파일 할 때 이러한 경고가 표시되지만 그 이유는 알 수 없습니다.왜 YACC에이 경고가 표시됩니까?

파일 parser.yacc :

%{ 
#include <stdio.h> 
void yyerror(char *s); 
extern int yylex(); 
%} 
%token NEWLINE PIPE AND OR AMPERSAND BLANK WORD IDENTIFIER GREAT GREAT_GREAT LESS ERR_GREAT ERR_GREAT_GREAT GREAT_AMP GREAT_GREAT_AMP SEMICOLON 
%start cmd_lists 
%% 
cmd_lists 
    : cmd_lists command 
    | 
    ; 
command 
    : pipeline io_list background NEWLINE 
    | NEWLINE 
    | error NEWLINE 
    ; 
pipeline 
    : pipeline PIPE cmd_args 
    | pipeline SEMICOLON cmd_args 
    | pipeline AND cmd_args 
    | pipeline OR cmd_args 
    | cmd_args 
    ; 
cmd_args 
    : WORD list_arg 
    ; 
list_arg 
    : list_arg WORD 
    ; 
io_list 
    : io_list io 
    ; 
background 
    : AMPERSAND 
    ; 
io 
    : GREAT WORD 
    | GREAT_GREAT WORD 
    | LESS WORD 
    | ERR_GREAT WORD 
    | ERR_GREAT_GREAT WORD 
    | GREAT_AMP WORD 
    | GREAT_GREAT_AMP WORD 
    ; 
%% 
void yyerror(char *s){ 
    fprintf(stderr,"yyerror : erreur : %s.\n",s); 
} 

그리고 경고 :

parser.yacc: warning: 6 nonterminals useless in grammar[-Wother] 
parser.yacc: warning: 17 rules useless in grammar [-Wother] 
parser.yacc:13.10-17: warning: nonterminal useless in grammar: : pipeline [-Wother] 
command: pipeline io_list background NEWLINE | NEWLINE | error NEWLINE; 
     ^^^^^^^^ 
parser.yacc:14.25-32: awarning: nonterminal useless in grammar: : cmd_args [-Wother] 
pipeline: pipeline PIPE cmd_args | pipeline SEMICOLON cmd_args | pipeline AND cmd_args | pipeline OR cmd_args | cmd_args; 
        ^^^^^^^^ 
parser.yacc:15.16-23:warning: nonterminal useless in grammar: : list_arg [-Wother] 
cmd_args: WORD list_arg; 
      ^^^^^^^^ 
parser.yacc:13.19-25: warning: nonterminal useless in grammar: : io_list [-Wother] 
command: pipeline io_list background NEWLINE | NEWLINE | error NEWLINE; 
       ^^^^^^^ 
parser.yacc:13.27-36: warning: nonterminal useless in grammar: : background [-Wother] 
command: pipeline io_list background NEWLINE | NEWLINE | error NEWLINE; 
         ^^^^^^^^^^ 
parser.yacc:17.18-19: warning: nonterminal useless in grammar: : io [-Wother] 
io_list: io_list io; 
       ^^ 
parser.yacc:13.10-44: warning: nonterminal useless in grammar:[-Wother] 
command: pipeline io_list background NEWLINE | NEWLINE | error NEWLINE; 
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
parser.yacc:14.11-32: warning: nonterminal useless in grammar: [-Wother] 
pipeline: pipeline PIPE cmd_args | pipeline SEMICOLON cmd_args | pipeline AND cmd_args | pipeline OR cmd_args | cmd_args; 
     ^^^^^^^^^^^^^^^^^^^^^^ 
parser.yacc:14.36-62: warning: nonterminal useless in grammar: [-Wother] 
pipeline: pipeline PIPE cmd_args | pipeline SEMICOLON cmd_args | pipeline AND cmd_args | pipeline OR cmd_args | cmd_args; 
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
parser.yacc:14.66-86:warning: nonterminal useless in grammar:[-Wother] 
pipeline: pipeline PIPE cmd_args | pipeline SEMICOLON cmd_args | pipeline AND cmd_args | pipeline OR cmd_args | cmd_args; 
                   ^^^^^^^^^^^^^^^^^^^^^ 
parser.yacc:14.90-109: warning: nonterminal useless in grammar: [-Wother] 
pipeline: pipeline PIPE cmd_args | pipeline SEMICOLON cmd_args | pipeline AND cmd_args | pipeline OR cmd_args | cmd_args; 
                         ^^^^^^^^^^^^^^^^^^^^ 
parser.yacc:14.113-120: warning: nonterminal useless in grammar:[-Wother] 
pipeline: pipeline PIPE cmd_args | pipeline SEMICOLON cmd_args | pipeline AND cmd_args | pipeline OR cmd_args | cmd_args; 
                              ^^^^^^^^ 
parser.yacc:15.11-23: warning: warning: nonterminal useless in grammar:[-Wother] 
cmd_args: WORD list_arg; 
     ^^^^^^^^^^^^^ 
parser.yacc:16.11-23: warning: warning: nonterminal useless in grammar: [-Wother] 
list_arg: list_arg WORD ; 
     ^^^^^^^^^^^^^ 
parser.yacc:17.10-19: warning: nonterminal useless in grammar:[-Wother] 
io_list: io_list io; 
     ^^^^^^^^^^ 
parser.yacc:18.13-21:warning: nonterminal useless in grammar:[-Wother] 
background: AMPERSAND; 
     ^^^^^^^^^ 
parser.yacc:19.5-14: warning: nonterminal useless in grammar:[-Wother] 
io: GREAT WORD| GREAT_GREAT WORD| LESS WORD| ERR_GREAT WORD| ERR_GREAT_GREAT WORD| GREAT_AMP WORD| GREAT_GREAT_AMP WORD; 
^^^^^^^^^^ 
parser.yacc:19.17-32: warning: nonterminal useless in grammar:[-Wother] 
io: GREAT WORD| GREAT_GREAT WORD| LESS WORD| ERR_GREAT WORD| ERR_GREAT_GREAT WORD| GREAT_AMP WORD| GREAT_GREAT_AMP WORD; 
      ^^^^^^^^^^^^^^^^ 
parser.yacc:19.35-43: warning: nonterminal useless in grammar: [-Wother] 
io: GREAT WORD| GREAT_GREAT WORD| LESS WORD| ERR_GREAT WORD| ERR_GREAT_GREAT WORD| GREAT_AMP WORD| GREAT_GREAT_AMP WORD; 
           ^^^^^^^^^ 
parser.yacc:19.46-59: warning: nonterminal useless in grammar:[-Wother] 
io: GREAT WORD| GREAT_GREAT WORD| LESS WORD| ERR_GREAT WORD| ERR_GREAT_GREAT WORD| GREAT_AMP WORD| GREAT_GREAT_AMP WORD; 
              ^^^^^^^^^^^^^^ 
parser.yacc:19.62-81: warning: nonterminal useless in grammar: [-Wother] 
io: GREAT WORD| GREAT_GREAT WORD| LESS WORD| ERR_GREAT WORD| ERR_GREAT_GREAT WORD| GREAT_AMP WORD| GREAT_GREAT_AMP WORD; 
                  ^^^^^^^^^^^^^^^^^^^^ 
parser.yacc:19.84-97:warning: nonterminal useless in grammar:[-Wother] 
io: GREAT WORD| GREAT_GREAT WORD| LESS WORD| ERR_GREAT WORD| ERR_GREAT_GREAT WORD| GREAT_AMP WORD| GREAT_GREAT_AMP WORD; 
                       ^^^^^^^^^^^^^^ 
parser.yacc:19.100-119: warning: nonterminal useless in grammar:[-Wother] 
io: GREAT WORD| GREAT_GREAT WORD| LESS WORD| ERR_GREAT WORD| ERR_GREAT_GREAT WORD| GREAT_AMP WORD| GREAT_GREAT_AMP WORD; 

내가 Yacc에 새로운입니다. 도움 주셔서 감사합니다. 나는 괜찮아 내 parser.y 파일을 변경 한

+0

'bison' ?,'yacc '?을 실행할 때, 우리는 "LANG = C bison options bla bla bla"와 같이하십시오. 'LANG = C'라고 쓰면 bison이 시스템 로케일을 영어로 생각하게하여 영어 경고를줍니다. –

+0

'yacc' 또는'bison'을 C 로케일 ('LC_ALL = C yacc parser.yacc')로 호출 할 수 있습니까? 그렇게하면 경고 메시지가 영어로 표시되며 더 많은 사람들이 무슨 일이 벌어지고 있는지 알게됩니다. (읽을 수없는 사람들을 위해 : 기본적으로 모든 제작과 비 터미널은 "사용되지 않는"것으로 표시됩니다.) –

+0

안녕하세요, 편집되었습니다. – Oneill

답변

0

:

%{ 
#include <stdio.h> 
void yyerror(char *s); 
extern int yylex(); 
%} 
%token NEWLINE PIPE AND OR AMPERSAND BLANK WORD IDENTIFIER GREAT GREAT_GREAT LESS ERR_GREAT ERR_GREAT_GREAT GREAT_AMP GREAT_GREAT_AMP SEMICOLON 
%start cmd_lists 
%% 
cmd_lists: cmd_lists command | ; 
command: pipeline io_list background NEWLINE | NEWLINE | error NEWLINE; 
pipeline: pipeline PIPE cmd_args | pipeline SEMICOLON cmd_args | pipeline AND cmd_args | pipeline OR cmd_args | cmd_args; 
cmd_args: WORD list_arg; 
list_arg: list_arg WORD | /*empty*/; 
io_list: io_list io| /*empty*/ ; 
background: AMPERSAND | /*empty*/ ; 
io: GREAT WORD | GREAT_GREAT WORD | LESS WORD | ERR_GREAT WORD | ERR_GREAT_GREAT WORD | GREAT_AMP WORD | GREAT_GREAT_AMP WORD; 
%% 

void yyerror(char *s){ 
    fprintf(stderr,"yyerror : erreur : %s.\n",s); 
} 

감사합니다.

관련 문제