📄 shell.c
字号:
result.side = RHS; result.type = pValue1->type; result.value.rv = rv; return (result); }#if (CPU!=PPC403)/********************************************************************************* evalFloat - evaluate for float result*/LOCAL VALUE evalFloat (pValue1, op, pValue2) VALUE *pValue1; int op; VALUE *pValue2; { VALUE *p1 = pValue1; VALUE *p2 = pValue2; VALUE result; /* evaluate as doubles and then convert back */ typeConvert (p1, T_DOUBLE, RHS); typeConvert (p2, T_DOUBLE, RHS); result = evalDouble (p1, op, p2); typeConvert (&result, T_FLOAT, RHS); return (result); }/********************************************************************************* evalDouble - evaluate for double result*/LOCAL VALUE evalDouble (pValue1, op, pValue2) VALUE *pValue1; int op; VALUE *pValue2; {#define OP_DOUBLE(op) dp = e1 op e2; break#define OP_DOUBLE_U(op) dp = op e1; break FAST double e1 = pValue1->value.dp; FAST double e2 = pValue2->value.dp; FAST double dp; VALUE result; switch (op) { case ADDA: case '+': OP_DOUBLE(+); case SUBA: case '-': OP_DOUBLE(-); case MULA: case '*': OP_DOUBLE(*); case DIVA: case '/': OP_DOUBLE(/); case '!': OP_DOUBLE_U(!); case '<': OP_DOUBLE(<); case '>': OP_DOUBLE(>); case OR: OP_DOUBLE(||); case AND: OP_DOUBLE(&&); case EQ: OP_DOUBLE(==); case NE: OP_DOUBLE(!=); case GE: OP_DOUBLE(>=); case LE: OP_DOUBLE(<=); case INCR: OP_DOUBLE_U(++); case DECR: OP_DOUBLE_U(--); case UMINUS: OP_DOUBLE_U(-); default: dp = 0; printf ("operands have incompatible types.\n"); SET_ERROR; } result.side = RHS; result.type = T_DOUBLE; result.value.dp = dp; return (result); }#endif /* (CPU!=PPC403) *//* TYPE CONVERSION */LOCAL void convUnknown ();LOCAL void convByte ();LOCAL void convWord ();LOCAL void convInt ();#if (CPU!=PPC403)LOCAL void convFloat ();LOCAL void convDouble ();#endif /* (CPU!=PPC403) */typedef void (*VOID_FUNCPTR) (); /* ptr to a function returning void */LOCAL VOID_FUNCPTR convType [] = { /* conversion type */ /* ---------- ----------- */ convUnknown, /* T_UNKNOWN*/ convByte, /* T_BYTE */ convWord, /* T_WORD */ convInt, /* T_INT */#if (CPU!=PPC403) convFloat, /* T_FLOAT */ convDouble, /* T_DOUBLE */#endif /* (CPU!=PPC403) */ };/********************************************************************************* typeConvert - change value to specified type*/LOCAL void typeConvert (pValue, type, side) FAST VALUE *pValue; TYPE type; SIDE side; { if (side == FHS) { pValue->side = RHS; pValue->type = type; } else if (side == RHS) { if (pValue->side == LHS) pValue->type = type; else (convType [(int) type]) (pValue); } else if (pValue->side == LHS) pValue->type = type; else { printf ("typeConvert: bad type.\n"); SET_ERROR; } }/********************************************************************************* convUnknown - convert value to unknown** ARGSUSED*/LOCAL void convUnknown (pValue) VALUE *pValue; { printf ("convUnknown: bad type.\n"); SET_ERROR; }/********************************************************************************* convByte - convert value to byte*/LOCAL void convByte (pValue) FAST VALUE *pValue; { char value; if ((int)pValue->type > (int)T_BYTE) { convWord (pValue); value = pValue->value.word; pValue->value.byte = value; pValue->type = T_BYTE; } }/********************************************************************************* convWord - convert value to word*/LOCAL void convWord (pValue) FAST VALUE *pValue; { short value; if ((int)pValue->type < (int)T_WORD) { value = pValue->value.byte; pValue->value.word = value; pValue->type = T_WORD; } else if ((int)pValue->type > (int)T_WORD) { convInt (pValue); value = pValue->value.rv; pValue->value.word = value; pValue->type = T_WORD; } }/********************************************************************************* convInt - convert value to integer*/LOCAL void convInt (pValue) FAST VALUE *pValue; { int value; if ((int)pValue->type < (int)T_INT) { convWord (pValue); value = pValue->value.word; pValue->value.rv = value; pValue->type = T_INT; } else if ((int)pValue->type > (int)T_INT) {#if (CPU!=PPC403) convFloat (pValue); value = pValue->value.fp; pValue->value.rv = value; pValue->type = T_INT;#endif /* (CPU!=PPC403) */ } }#if (CPU!=PPC403)/********************************************************************************* convFloat - convert value to float*/LOCAL void convFloat (pValue) FAST VALUE *pValue; { float value; if ((int)pValue->type < (int)T_FLOAT) { convInt (pValue); value = pValue->value.rv; pValue->value.fp = value; pValue->type = T_FLOAT; } else if ((int)pValue->type > (int)T_FLOAT) { convDouble (pValue); value = pValue->value.dp; pValue->value.fp = value; pValue->type = T_FLOAT; } }/********************************************************************************* convDouble - convert value to double*/LOCAL void convDouble (pValue) FAST VALUE *pValue; { double value; if ((int)pValue->type < (int)T_DOUBLE) { convFloat (pValue); value = pValue->value.fp; pValue->value.dp = value; pValue->type = T_DOUBLE; } }#endif /* (CPU!=PPC403) */int yyexca[] ={-1, 1, 0, -1, -2, 0, };# define YYNPROD 63# define YYLAST 810int yyact[]={ 29, 32, 106, 21, 21, 27, 25, 20, 26, 108, 28, 105, 104, 115, 111, 107, 69, 1, 66, 11, 68, 2, 0, 42, 55, 41, 22, 29, 32, 0, 21, 0, 27, 25, 0, 26, 0, 28, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 0, 42, 55, 41, 22, 23, 23, 110, 33, 0, 0, 0, 0, 0, 0, 0, 29, 32, 0, 21, 103, 27, 25, 0, 26, 0, 28, 0, 0, 0, 0, 0, 23, 0, 0, 33, 0, 0, 34, 42, 55, 41, 22, 29, 32, 0, 21, 0, 27, 25, 0, 26, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34, 42, 55, 41, 22, 23, 0, 0, 33, 0, 0, 0, 0, 0, 29, 32, 0, 21, 0, 27, 25, 0, 26, 0, 28, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 33, 0, 42, 34, 41, 22, 29, 32, 0, 21, 0, 27, 25, 0, 26, 0, 28, 29, 32, 0, 21, 0, 27, 25, 0, 26, 0, 28, 0, 42, 34, 41, 0, 23, 0, 0, 33, 0, 29, 0, 42, 21, 41, 27, 25, 0, 26, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 33, 0, 0, 34, 0, 0, 0, 0, 23, 0, 0, 33, 0, 0, 0, 0, 36, 35, 37, 38, 39, 40, 43, 44, 31, 30, 0, 24, 24, 23, 34, 51, 52, 49, 45, 46, 53, 54, 47, 48, 50, 34, 0, 36, 35, 37, 38, 39, 40, 43, 44, 31, 30, 0, 24, 21, 0, 0, 51, 52, 49, 45, 46, 53, 54, 47, 48, 50, 29, 32, 0, 21, 0, 27, 25, 0, 26, 0, 28, 0, 0, 36, 35, 37, 38, 39, 40, 43, 44, 31, 30, 42, 24, 41, 0, 0, 51, 52, 49, 45, 46, 53, 54, 47, 48, 50, 23, 0, 36, 35, 37, 38, 39, 40, 43, 44, 31, 30, 0, 24, 0, 0, 23, 51, 52, 49, 45, 46, 53, 54, 47, 48, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 35, 37, 38, 39, 40, 43, 44, 31, 30, 0, 24, 0, 0, 29, 32, 0, 21, 0, 27, 25, 0, 26, 0, 28, 0, 0, 0, 35, 37, 38, 39, 40, 43, 44, 31, 30, 42, 24, 41, 37, 38, 39, 40, 43, 44, 31, 30, 0, 24, 29, 0, 0, 21, 0, 27, 25, 0, 26, 0, 28, 0, 0, 0, 0, 43, 44, 0, 23, 15, 24, 33, 0, 42, 13, 41, 10, 0, 12, 0, 0, 14, 29, 0, 0, 21, 0, 27, 25, 0, 26, 29, 28, 0, 21, 0, 27, 25, 0, 26, 0, 28, 0, 0, 23, 42, 15, 41, 0, 0, 0, 13, 0, 10, 29, 12, 0, 21, 14, 27, 0, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0, 0, 0, 43, 44, 0, 23, 0, 24, 0, 0, 0, 0, 0, 0, 37, 38, 39, 40, 43, 44, 31, 30, 16, 24, 0, 0, 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 38, 39, 40, 43, 44, 31, 30, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 38, 39, 40, 43, 44, 31, 30, 0, 24, 0, 0, 0, 0, 5, 4, 19, 8, 7, 6, 9, 0, 0, 0, 0, 0, 0, 17, 18, 0, 0, 0, 0, 57, 39, 40, 43, 44, 31, 30, 0, 24, 0, 0, 0, 43, 44, 31, 30, 0, 24, 5, 4, 19, 8, 7, 6, 9, 0, 0, 0, 0, 0, 3, 17, 18, 0, 0, 43, 44, 0, 0, 0, 24, 56, 58, 59, 60, 61, 62, 63, 64, 65, 0, 0, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 0, 0, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 0, 113, 114 };int yypact[]={ 429, -1000, -52, 55, -1000, -1000, -1000, -1000, -1000, -1000, 392, 429, 429, 429, 429, 429, 429, 429, 429, -1000, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, -1000, -1000, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 429, 28, -29, -1000, -36, -36, -36, -36, -36, -36, -36, -59, -1000, -26, -35, 55, -10, -37, -1000, 433, 433, 227, 227, 227, 150, 150, 369, 243, 333, 129, 118, 401, 401, 410, 410, 410, 410, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, -1000, -1000, -27, 429, -1000, 429, 429, -1000, -28, 91, 55, 91, -1000 };int yypgo[]={ 0, 17, 21, 699, 20, 19, 18, 16 };int yyr1[]={ 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 4, 4, 7, 7, 5, 5 };int yyr2[]={ 0, 2, 6, 0, 3, 2, 3, 3, 2, 2, 2, 7, 9, 5, 5, 5, 5, 5, 5, 11, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 9, 1, 2, 3, 7, 7, 11 };int yychk[]={ -1000, -1, -2, -3, 259, 258, 263, 262, 261, 264, 40, -5, 42, 38, 45, 33, 126, 271, 272, 260, 59, 40, 63, 91, 276, 43, 45, 42, 47, 37, 274, 273, 38, 94, 124, 266, 265, 267, 268, 269, 270, 62, 60, 271, 272, 283, 284, 287, 288, 282, 289, 280, 281, 285, 286, 61, -3, 277, -3, -3, -3, -3, -3, -3, -3, -3, -6, -1, -4, -7, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 41, 41, 40, 61, 41, 44, 58, 93, 41, -3, -3, -3, 41 };int yydef[]={ 3, -2, 1, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 3, 57, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 15, 16, 17, 18, 40, 41, 0, 2, 0, 58, 59, 0, 0, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 11, 61, 0, 0, 12, 0, 0, 20, 0, 56, 60, 19, 62 };typedef struct { char *t_name; int t_val; } yytoktype;#ifndef YYDEBUG# define YYDEBUG 0 /* don't allow debugging */#endif#if YYDEBUGyytoktype yytoks[] ={ "NL", 0, "T_SYMBOL", 258, "D_SYMBOL", 259, "U_SYMBOL", 260, "NUMBER", 261, "CHAR", 262, "STRING", 263, "FLOAT", 264, "OR", 265, "AND", 266, "EQ", 267, "NE", 268, "GE", 269, "LE", 270, "INCR", 271, "DECR", 272, "ROT_LEFT", 273, "ROT_RIGHT", 274, "UMINUS", 275, "PTR", 276, "TYPECAST", 277, "ENDFILE", 278, "LEX_ERROR", 279, "=", 61, "MULA", 280, "DIVA", 281, "MODA", 282, "ADDA", 283, "SUBA", 284, "SHLA", 285, "SHRA", 286, "ANDA", 287, "ORA", 288, "XORA", 289, "?", 63, ":", 58, "|", 124, "^", 94, "&", 38, ">", 62, "<", 60, "+", 43, "-", 45, "*", 42, "/", 47, "%", 37, "UNARY", 290, "[", 91, "(", 40, "-unknown-", -1 /* ends search */};char * yyreds[] ={ "-no such reduction-", "line : stmt", "line : stmt ';' line", "stmt : /* empty */", "stmt : expr", "expr : D_SYMBOL", "expr : T_SYMBOL", "expr : STRING", "expr : CHAR", "expr : NUMBER", "expr : FLOAT", "expr : '(' expr ')'", "expr : expr '(' arglist ')'", "expr : typecast expr", "expr : '*' expr", "expr : '&' expr", "expr : '-' expr", "expr : '!' expr", "expr : '~' expr", "expr : expr '?' expr ':' expr", "expr : expr '[' expr ']'", "expr : expr PTR expr", "expr : expr '+' expr", "expr : expr '-' expr", "expr : expr '*' expr", "expr : expr '/' expr", "expr : expr '%' expr", "expr : expr ROT_RIGHT expr", "expr : expr ROT_LEFT expr", "expr : expr '&' expr", "expr : expr '^' expr", "expr : expr '|' expr", "expr : expr AND expr", "expr : expr OR expr", "expr : expr EQ expr", "expr : expr NE expr", "expr : expr GE expr", "expr : expr LE expr", "expr : expr '>' expr", "expr : expr '<' expr", "expr : INCR expr", "expr : DECR expr", "expr : expr INCR", "expr : expr DECR", "expr : expr ADDA expr", "expr : expr SUBA expr", "expr : expr ANDA expr", "expr : expr ORA expr", "expr : expr MODA expr", "expr : expr XORA expr", "expr : expr MULA expr", "expr : expr DIVA expr", "expr : expr SHLA expr", "expr : expr SHRA expr", "expr : expr '=' expr", "expr : U_SYMBOL", "expr : U_SYMBOL '=' expr", "arglist : /* empty */", "arglist : neArglist", "neArglist : expr", "neArglist : neArglist ',' expr", "typecast : '(' TYPECAST ')'", "typecast : '(' TYPECAST '(' ')' ')'",};#endif /* YYDEBUG */#line 1 "/usr/lib/yaccpar"/* @(#)yaccpar 1.10 89/04/04 SMI; from S5R3 1.10 *//*** Skeleton parser driver for yacc output*//*** yacc user known macros and defines*/#define YYERROR goto yyerrlab#define YYACCEPT { free(yys); free(yyv); return(0); }#define YYABORT { free(yys); free(yyv); return(1); }#define YYBACKUP( newtoken, newvalue )\{\ if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\ {\ yyerror( "syntax error - cannot backup" );\ goto yyerrlab;\ }\ yychar = newtoken;\ yystate = *yyps;\ yylval = newvalue;\ goto yynewstate;\}#define YYRECOVERING() (!!yyerrflag)#ifndef YYDEBUG# define YYDEBUG 1 /* make debugging available */#endif/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -