/* $Id: cmd.l,v 1.26 2004/04/03 04:17:37 jmuelmen Exp $ */ %{ #include "y.tab.h" #include "shell.h" #include "rl.h" #include "stdio.h" double yyfloat; int yyint; extern FILE *yyin; /* void lex_debug (const char *c) */ /* { */ /* SHELL_DEBUG(100, c); */ /* } */ void comment (); #ifdef getc #undef getc #endif int getc (FILE *); %} /* the "incl" state is used for picking up the name * of an include file */ %x incl %% [ \t]+ ; /* eat the whitespace */ [^ \t\n]+ { yyin = fopen( yytext, "r" ); if ( ! yyin ) perror("opening include file"); else yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE)); BEGIN(INITIAL); } <> { /* fprintf(stderr, "Encountered EOF\n"); */ if (isatty(fileno(yyin))) { /* fprintf(stderr, "Probably not safe to pop this guy\n"); */ yyterminate(); } else { yypop_buffer_state(); /* fprintf(stderr, "popped buffer\n"); */ } /* fprintf(stderr, "yyin = %lx\n", (unsigned long)yyin); */ } \#include { BEGIN(incl); } "/*" { comment(); } "if" { return(IF); } at { return(AT); } every { return(EVERY); } int { return(INT); } float { return(FLOAT); } string { return(STRING); } help { print_help(); } atomic { return(ATOMIC); } sequential { return(SEQUENTIAL); } time { return(TIME); } "+=" { return(ADD_ASSIGN); } "-=" { return(SUB_ASSIGN); } "*=" { return(MUL_ASSIGN); } "/=" { return(DIV_ASSIGN); } "%=" { return(MOD_ASSIGN); } "&=" { return(AND_ASSIGN); } "^=" { return(XOR_ASSIGN); } "|=" { return(OR_ASSIGN); } "++" { return(INC_OP); } "--" { return(DEC_OP); } "&&" { return(AND_OP); } "||" { return(OR_OP); } "<=" { return(LE_OP); } ">=" { return(GE_OP); } "==" { return(EQ_OP); } "!=" { return(NE_OP); } ";" { return(';'); } "{" { return('{'); } "}" { return('}'); } "," { return(','); } ":" { return(':'); } "=" { return('='); } "(" { return('('); } ")" { return(')'); } "[" { return('['); } "]" { return(']'); } "." { return('.'); } "&" { return('&'); } "!" { return('!'); } "~" { return('~'); } "-" { return('-'); } "+" { return('+'); } "*" { return('*'); } "/" { return('/'); } "%" { return('%'); } "<" { return('<'); } ">" { return('>'); } "^" { return('^'); } "|" { return('|'); } "?" { return('?'); } ([0-9][0-9]){0,4}[0-9][0-9]:[0-9][0-9](\.[0-9][0-9])? { return(TIME_CONST); } \"[^\"]*\" { return(STRING_LITERAL); } [_A-Za-z][_0-9A-Za-z]* { return(IDENTIFIER); } -?[0-9]+\.[0-9]+ { yyfloat = atof(yytext); return(FLOAT_CONST); } -?[0-9]+ { yyint = atoi(yytext); return(INT_CONST); } [ \t\v\n\f\r] ; . ; %% #ifndef yywrap int yywrap () { return 1; } #endif #ifndef yytext_ptr #define yytext_ptr yytext #endif void comment() { char c, c1; loop: while ((c = input()) != '*' && c != 0) putchar(c); if ((c1 = input()) != '/' && c != 0) { unput(c1); goto loop; } if (c != 0) putchar(c1); } int getc (FILE *stream) { int c = ambush_getc(); return c; } int ambush_lex () { /* printf("Calling lex."); */ return yylex(); } void lex_change_input (FILE *f) { yyin = f; }