⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expr.c

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 C
📖 第 1 页 / 共 2 页
字号:
/*Copyright (c) 2000, Red Hat, Inc.This file is part of Source-Navigator.Source-Navigator is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public License as publishedby the Free Software Foundation; either version 2, or (at your option)any later version.Source-Navigator is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith Source-Navigator; see the file COPYING.  If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330, Boston,MA 02111-1307, USA.*/#include <stdlib.h>#include <stdio.h>#include <string.h>#include "operator.h"#include "cpdefines.h"#include "cplex.h"#define Save()    Token_t TokenActSave = TokenAct#define Restore() TokenAct = TokenActSave#define CEXP_DEF   0#define CEXP_UNDEF 1#define CEXP_NULL  2typedef struct sCexp Cexp_t;struct sCexp{   int typ;       /* CEXP_DEF, CEXP_UNDEF, CEXP_NULL */   int value;};static Token_t TokenEnd;static Token_t TokenAct;static Cexp_t CexpNull = { CEXP_NULL, 0 };static Cexp_t constant_expression( void );static Cexp_t conditional_expression( void );static Cexp_t logical_or_expression( void );static Cexp_t logical_and_expression( void );static Cexp_t inclusive_or_expression( void );static Cexp_t exclusive_or_expression( void );static Cexp_t and_expression( void );static Cexp_t equality_expression( void );static Cexp_t relational_expression( void );static Cexp_t shift_expression( void );static Cexp_t additive_expression( void );static Cexp_t multiplicative_expression( void );static Cexp_t unary_expression( void );static Cexp_t primary_expression( void );static Cexp_t CexpCreateOp1( int operator, Cexp_t Cexp1 );static Cexp_t CexpCreateOp2( int operator, Cexp_t Cexp1, Cexp_t Cexp2 );static Cexp_t CexpCreateOp3( int operator, Cexp_t Cexp1, Cexp_t Cexp2, Cexp_t Cexp3 );static int token( int i );static void step( int i );static sString_t ident( int i );static long f_Atol( sString_t sString );static long f_Ctol( sString_t sString );extern int __ConstantExpression( Token_t Token ){   Cexp_t Cexp;   TokenAct = Token;   TokenEnd = Token;   Cexp = constant_expression();   if( Cexp.typ == CEXP_NULL  ) return CPLEX_TRUE;   if( Cexp.typ == CEXP_UNDEF ) return CPLEX_UNDEF;   if( Cexp.value )   {      return CPLEX_TRUE;   }   else   {      return CPLEX_FALSE;   }}static Cexp_t constant_expression( void ){   return conditional_expression();}static Cexp_t conditional_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   Cexp_t Cexp3;   Save();#ifdef TRACE   printf( "conditional_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = logical_or_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   if( token( 0 ) != '?' )   {      return Cexp1;   }   step( 1 );   if(( Cexp2 = constant_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp2;   }   if( token( 0 ) != ':' )   {      Restore();      return CexpNull;   }   step( 1 );   if(( Cexp3 = conditional_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp3;   }   return CexpCreateOp3( OPERATOR_CONDITIONAL, Cexp1, Cexp2, Cexp3 );}static Cexp_t logical_or_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   int operator;   Save();#ifdef TRACE   printf( "logical_or_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = logical_and_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   while( True )   {      switch( token( 0 ))      {      case SN_OROR: operator = OPERATOR_OROR; break;      default  : return Cexp1;      }      step( 1 );      if(( Cexp2 = logical_and_expression()).typ == CEXP_NULL )      {         Restore();         return Cexp2;      }      Cexp1 = CexpCreateOp2( operator, Cexp1, Cexp2 );   }}static Cexp_t logical_and_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   int operator;   Save();#ifdef TRACE   printf( "logical_and_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = inclusive_or_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   while( True )   {      switch( token( 0 ))      {      case SN_ANDAND: operator = OPERATOR_ANDAND; break;      default    : return Cexp1;      }      step( 1 );      if(( Cexp2 = inclusive_or_expression()).typ == CEXP_NULL )      {         Restore();         return Cexp2;      }      Cexp1 = CexpCreateOp2( operator, Cexp1, Cexp2 );   }}static Cexp_t inclusive_or_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   int operator;   Save();#ifdef TRACE   printf( "inclusive_or_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = exclusive_or_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   while( True )   {      switch( token( 0 ))      {      case '|': operator = OPERATOR_OR; break;      default : return Cexp1;      }      step( 1 );      if(( Cexp2 = exclusive_or_expression()).typ == CEXP_NULL )      {         Restore();         return Cexp2;      }      Cexp1 = CexpCreateOp2( operator, Cexp1, Cexp2 );   }}static Cexp_t exclusive_or_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   int operator;   Save();#ifdef TRACE   printf( "exclusive_or_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = and_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   while( True )   {      switch( token( 0 ))      {      case '^': operator = OPERATOR_ER; break;      default : return Cexp1;      }      step( 1 );      if(( Cexp2 = and_expression()).typ == CEXP_NULL )      {         Restore();         return Cexp2;      }      Cexp1 = CexpCreateOp2( operator, Cexp1, Cexp2 );   }}static Cexp_t and_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   int operator;   Save();#ifdef TRACE   printf( "and_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = equality_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   while( True )   {      switch( token( 0 ))      {      case '&': operator = OPERATOR_AND; break;      default : return Cexp1;      }      step( 1 );      if(( Cexp2 = equality_expression()).typ == CEXP_NULL )      {         Restore();         return Cexp2;      }      Cexp1 = CexpCreateOp2( operator, Cexp1, Cexp2 );   }}static Cexp_t equality_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   int operator;   Save();#ifdef TRACE   printf( "equality_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = relational_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   while( True )   {      switch( token( 0 ))      {      case SN_EQ: operator = OPERATOR_EQ; break;      case SN_NE: operator = OPERATOR_NE; break;      default: return Cexp1;      }      step( 1 );      if(( Cexp2 = relational_expression()).typ == CEXP_NULL )      {         Restore();         return Cexp2;      }      Cexp1 = CexpCreateOp2( operator, Cexp1, Cexp2 );   }}static Cexp_t relational_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   int operator;   Save();#ifdef TRACE   printf( "relational_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = shift_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   while( True )   {      switch( token( 0 ))      {      case '<': operator = OPERATOR_L ; break;      case '>': operator = OPERATOR_G ; break;      case SN_LE : operator = OPERATOR_LE; break;      case SN_GE : operator = OPERATOR_GE; break;      default : return Cexp1;      }      step( 1 );      if(( Cexp2 = shift_expression()).typ == CEXP_NULL )      {         Restore();         return Cexp2;      }      Cexp1 = CexpCreateOp2( operator, Cexp1, Cexp2 );   }}static Cexp_t shift_expression( void ){   Cexp_t Cexp1;   Cexp_t Cexp2;   int operator;   Save();#ifdef TRACE   printf( "shift_expression: %s\n", ident( 0 ));#endif   if(( Cexp1 = additive_expression()).typ == CEXP_NULL )   {      Restore();      return Cexp1;   }   while( True )   {      switch( token( 0 ))      {      case SN_LS : operator = OPERATOR_LS; break;      case SN_RS : operator = OPERATOR_RS; break;      default : return Cexp1;      }      step( 1 );      if(( Cexp2 = additive_expression()).typ == CEXP_NULL )      {         Restore();         return Cexp2;      }      Cexp1 = CexpCreateOp2( operator, Cexp1, Cexp2 );   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -