%{

#include "scanner.ih"
#define YY_NO_INPUT

%}

%option 8bit

%x str

%%

<str>\"                 {
                            /* having read a "string", unescape it 
                               the returned string does not have surrounding
                               double quotes */
                            BEGIN 0;
                            return STRING;
                        }
<str>.                  {
                            util_catString(yytext);
                        }

<str>\\x[[:xdigit:]]{2} {
                            util_catString(sc_scan("%x", yytext + 2));
                        }

<str>\\[0-7]{3}         {
                            util_catString(sc_scan("%o", yytext + 1));
                        }

<str>\\.                {  
                            util_catString(sc_escapedChar(yytext[1]));
                        }

[ \t]                   ;
\n                      ++yylineno;
^#[0-9]+\n              {
                            sc_setLineNr();
                        }
^#>.*                   {
                            sc_changeFile(yytext + 2);
                        }
^#$                     {
                            sc_popFile();
                        }
'.'                     {
                            sc_charConst();
                            return STRING;
                        }

'\\[0-7]{3}'            {
                            util_setString(sc_scan("%o", yytext + 2));
                            return STRING;
                        }

'\\x[[:xdigit:]]{2}'    {
                            util_setString(sc_scan("%x", yytext + 3));
                            return STRING;
                        }

'\\.'                   {
                            util_setString(sc_escapedChar(yytext[2]));
                            return STRING;
                        }

[1-9][0-9]*             {
                            util_scan("%u", yytext);
                            return NUMBER;
                        }
0[0-7]*                 {
                            util_scan("%o", yytext);
                            return NUMBER;
                        }
0x[[:xdigit:]]+         {
                            util_scan("%x", yytext + 2);
                            return NUMBER;
                        }

\"                      {
                            util_setString(""); 
                            BEGIN str;
                        }

arghead                 {
                            yylval.type = f_arg_head;
                            return ARG_HEAD;
                        }
argtail                 {
                            yylval.type = f_arg_tail;
                            return ARG_TAIL;
                        }
ascii                   {                   /* ascii_int may become ascii_str */
                            yylval.type = f_ascii_int;
                            return ASCII;
                        }
break                   {
                            return BREAK;
                        }
chdir                   {
                            yylval.type = f_chdir;
                            return CHDIR;
                        }
cmdtail                 {
                            yylval.type = f_cmd_tail;
                            return CMD_TAIL;
                        }
cmdhead                 {
                            yylval.type = f_cmd_head;
                            return CMD_HEAD;
                        }
change_base             {
                            yylval.type = f_c_base;
                            return C_BASE;
                        }
change_ext              {
                            yylval.type = f_c_ext;
                            return C_EXT;
                        }
change_path             {
                            yylval.type = f_c_path;
                            return C_PATH;
                        }
continue                {
                            return CONTINUE;
                        }
fprintf                 {
                            yylval.type = f_fprintf;
                            return FPRINTF;
                        }
get_base                {
                            yylval.type = f_g_base;
                            return G_BASE;
                        }
get_ext                 {
                            yylval.type = f_g_ext;
                            return G_EXT;
                        }
get_dext                {
                            yylval.type = f_g_dext;
                            return G_DEXT;
                        }
get_path                {
                            yylval.type = f_g_path;
                            return G_PATH;
                        }
getch                   {
                            yylval.type = f_getch;
                            return GETCH;
                        }
getpid                  {
                            yylval.type = f_getpid;
                            return GETPID;
                        }
gets                    {
                            yylval.type = f_gets;
                            return GETS;
                        }
echo                    {
                            yylval.type = f_echo;
                            return ECHO_TOKEN;
                        }
element                 {
                            yylval.type = f_element;
                            return ELEMENT;
                        }
else                    {
                            return ELSE;
                        }
eval                    {
                            yylval.type = f_eval;
                            return EVAL;
                        }
exec                    {
                            yylval.type = f_exec;
                            return EXEC;
                        }
execute                 {
                            yylval.type = f_execute;
                            return EXECUTE;
                        }
exists                  {
                            yylval.type = f_exists;
                            return EXISTS;
                        }
exit                    {
                            yylval.type = op_exit;
                            return EXIT;
                        }
fgets                   {
                            yylval.type = f_fgets;
                            return FGETS;
                        }
for                     {
                            return FOR;
                        }
getenv                  {
                            yylval.type = f_getenv;
                            return GETENV;
                        }
if                      {
                            return IF;
                        }
void                    {
                            yylval.type = 0;    /* 0 == void */
                            return VOID;
                        }
int                     {
                            yylval.type = e_int;
                            return INT;
                        }
list                    {
                            yylval.type = e_list;
                            return LIST;
                        }
listfind                {
                            yylval.type = f_listfind;
                            return LISTFIND;
                        }
listunion               {
                            yylval.type = f_listunion;
                            return LISTUNION;
                        }
listlen         |
sizeof          |
sizeoflist              {
                            sc_saveInfo();
                            yylval.type = f_listlen;
                            return LISTLEN;
                        }
makelist                {
                            yylval.type = f_makelist;
                            return MAKELIST;
                        }
older                   {
                            yylval.type = op_older;
                            return OLDER;
                        }
printf                  {
                            yylval.type = f_printf;
                            return PRINTF;
                        }
putenv                  {
                            yylval.type = f_putenv;
                            return PUTENV;
                        }
resize                  {
                            yylval.type = f_resize;
                            return RESIZE;
                        }
                            
return                  {
                            yylval.type = op_ret;
                            return RETURN;
                        }
stat                    {
                            yylval.type = f_stat;
                            return STAT;
                        }
strchr                  {
                            yylval.type = f_strchr;
                            return STRCHR;
                        }
string                  {
                            yylval.type = e_str;
                            return STRINGTYPE;
                        }
strlen                  {
                            yylval.type = f_strlen;
                            return STRLEN;
                        }
strlwr                  {
                            yylval.type = f_strlwr;
                            return STRLWR;
                        }
strupr                  {
                            yylval.type = f_strupr;
                            return STRUPR;
                        }
strtok                  {
                            yylval.type = f_strtok;
                            return FIELDS;
                        }
strfind                 {
                            yylval.type = f_strfind;
                            return STRFIND;
                        }
strformat               {
                            yylval.type = f_strformat;
                            return STRFORMAT;
                        }
substr                  {
                            yylval.type = f_substr;
                            return SUBSTR;
                        }
system                  {
                            yylval.type = f_system;
                            return SYSTEM;
                        }
trim                    {
                            yylval.type = f_trim;
                            return TRIMLEFT;
                        }
trimleft                {
                            yylval.type = f_trimleft;
                            return TRIMLEFT;
                        }
trimright               {
                            yylval.type = f_trimright;
                            return TRIMRIGHT;
                        }
while                   {
                            return WHILE;
                        }
newer   |
younger                 {
                            yylval.type = op_younger;
                            return YOUNGER;
                        }
"++"                    {
                            return INC;
                        }
"--"                    {
                            return DEC;
                        }
"/="                    {
                            return DIV_IS;
                        }
"-="                    {
                            return MINUS_IS;
                        }
"*="                    {
                            return MUL_IS;
                        }
"%="                    {
                            return MOD_IS;
                        }
"+="                    {
                            return PLUS_IS;
                        }
"&="                    {
                            return AND_IS;
                        }
"|="                    {
                            return OR_IS;
                        }
"^="                    {
                            return XOR_IS;
                        }
"<<="                   {
                            return SHL_IS;
                        }
">>="                   {
                            return SHR_IS;
                        }
"||"                    {
                            return OR;
                        }
"&&"                    {
                            return AND;
                        }
"=="                    {
                            return EQUAL;
                        }
"!="                    {
                            return NOT_EQUAL;
                        }
"<="                    {
                            return SMALLER_EQUAL;
                        }
">="                    {
                            return GREATER_EQUAL;
                        }
">>"                    {
                            return SHR;
                        }
"<<"                    {
                            return SHL;
                        }
OFF         |
P_CHECK                 {
                            util_setString("0");
                            return NUMBER;
                        }
S_IFDIR     |
O_FILE      |
ON                      {
                            util_setString("1");
                            return NUMBER;
                        }
S_IFCHR     |
P_NOCHECK   |
O_DIR                   {
                            util_setString("2");
                            return NUMBER;
                        }
S_IFREG     |
O_SUBDIR                {
                            util_setString("4");
                            return NUMBER;
                        }
S_IREAD     |
O_ALL                   {
                            util_setString("8");
                            return NUMBER;
                        }
S_IWRITE                {
                            util_setString("16");
                            return NUMBER;
                        }
S_IEXEC                 {
                            util_setString("32");
                            return NUMBER;
                        }
[_A-Za-z][A-Za-z0-9_]*  {
                            util_setString(yytext);
                            return IDENTIFIER;
                        }
.                       return yytext[0];
