How to make Bison / YACC not recognize the command until it checks the entire line?

I have a bison grammar:

input: /* empty */
       | input command
;

command:
        builtin
        | external
;

builtin:
        CD { printf("Changing to home directory...\n"); }
        | CD WORD { printf("Changing to directory %s\n", $2); }
;

I am wondering how I make Bison not accept (YYACCEPT?) Something like commanduntil it reads ALL the input. That way, I can use all of these rules below, which use recursion or something else to create things that either lead to a valid command, or something that won't work.

One simple test that I am doing with the code above just enters "cd mydir mydir". Bison analyzes CDand WORDgoes “hey! This is a team, put it on top!”. Then the next token that he finds is simply WORDthat which has no rule, and then he reports an error.

, , CD WORD WORD , . , - - !

, input command NEWLINE - , - CD WORD , WORD.

+5
4

, .

lexer (;), Bison, .

sep:   NEWLINE | SEMICOLON
   ;

command:  CD  sep
   |  CD WORD sep
   ;

, , :

args:
    /* empty */
  | args WORD
  ;

command:
      CD args sep
   ;
+2

. , , , . , % destructor, , .

, , .

+1

, .

Bison/Yakk/Lex, , , . Bison/Yakk/Lex , .

, .

, , .

input : /* empty */
      | line


command-break : command-break semi-colon
              | semi-colon

line : commands new-line

commands : commands command-break command
         | commands command-break command command-break
         | command
         | command command-break

...

new-line, 'semi-colon is defined in your lex source as something like\n ,\t`. UNIX , . , , , .

Lex and Yakk are a powerful tool, and I find them quite enjoyable - at least when you're not in deadline.

0
source

Could you just change your compliance actions to add a list of actions you want to take if all of this works? Then, after all the input has been processed, you decide whether you want to do what was in this list of actions, based on if you saw parsing errors.

0
source

All Articles