/* * CS-413 Spring 98 * shell.y: parser for shell * * This parser compiles the following grammar: * * cmd [arg]* [> filename] * * you have to extend it for the complete shell grammar * */ %token WORD %token NOTOKEN, GREAT, NEWLINE %union { char *string_val; } %{ extern "C" int yylex(); #define yylex yylex #include #include "command.h" %} %% goal: commands ; commands: command | commands command ; command: simple_command ; simple_command: command_and_args iomodifier_opt NEWLINE { printf(" Yacc: Execute command\n"); Command::_currentCommand.execute(); } | NEWLINE | error NEWLINE { yyerrok; } ; command_and_args: command_word arg_list { Command::_currentCommand. insertSimpleCommand( Command::_currentSimpleCommand ); } ; arg_list: arg_list argument | /* empty */ ; argument: WORD { printf(" Yacc: insert argument \"%s\"\n", $1); Command::_currentSimpleCommand->insertArgument( $1 );\ } ; command_word: WORD { printf(" Yacc: insert command \"%s\"\n", $1); Command::_currentSimpleCommand = new SimpleCommand(); Command::_currentSimpleCommand->insertArgument( $1 ); } ; iomodifier_opt: GREAT WORD { printf(" Yacc: insert output \"%s\"\n", $2); Command::_currentCommand._outFile = $2; } | /* empty */ ; %% void yyerror(const char * s) { fprintf(stderr,"%s", s); } #if 0 main() { yyparse(); } #endif