Thread: using YACC and lex to make your own shell...

  1. #1
    Registered User
    Join Date
    Nov 2005

    using YACC and lex to make your own shell...

    anyone know of any links that could help me with this? I've read the man pages on YACC and lex and im still a bit's what i have so far..

    YACC part...
    #include <stdio.h>
    int at_end = 0;
    extern int yychar;
    %start cmd
    cmd:            CD WORD                         {chdir($2.sval); YYACCEPT;}
            |       GETENV                          {getenv(); YYACCEPT;}
            |       SETENV                          {setenv(); YYACCEPT;}
            |       EXIT                            {exit(1); YYACCEPT;}
            |       ';'                             {
    lex part:

    #nclude ""
    extern int yylval;
    cd                                                              return CD;
    $[A-Za-z]+                                                      return GETENV;
    setenv                                                          return SETENV;
    setprompt                                                       return SETPROMPT;
    exit                                                            return EXIT;
    [a-zA-Z\/.]                                                     {strcpy(yyval.sval, yytext) return WORD;}
    .                                                               return yytext[0];
    any help would be appreciated

  2. #2
    Sr. Software Engineer filker0's Avatar
    Join Date
    Sep 2005
    West Virginia
    Do you have any previous experience with Lex and Yacc?

    I've written several command shells over the years, but never using either Lex or Yacc. I've used Lex/Yacc for other things, but never thought to use Yacc for an interactive program.

    As with any command shell, you need to build a context and a set of actions (built-ins and defaults) to track the state of the user session. Then, as with any Yacc+Lex program, you write productions and semantic actions that manipulate and invoke the shell framework in response to the tokens that are being processed.

    I hope this helps.
    Insert obnoxious but pithy remark here

  3. #3
    Registered User
    Join Date
    Sep 2003
    I used Lex and Yacc to write a shell. The professor gave us the grammer though. It got really buggy, and I ended up using system() five minutes before submission. I still have the code...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Three Address Code generation using Lex, Yacc
    By Raman in forum C Programming
    Replies: 1
    Last Post: 11-04-2008, 09:04 AM
  2. Anybody into lex and yacc ?
    By spank in forum Tech Board
    Replies: 8
    Last Post: 07-20-2007, 03:30 AM
  3. Yacc and Lex
    By Chronom1 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2005, 08:03 AM
  4. Lex and Yacc
    By Mystic_Skies in forum Linux Programming
    Replies: 2
    Last Post: 12-05-2004, 04:06 PM
  5. Code for C Compiler using lex and yacc
    By jaadugary in forum C Programming
    Replies: 0
    Last Post: 05-10-2003, 09:11 AM