• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

             

              1 #include "PathInterpreter.h"
              2 
              3 // CPathScriptLoader
              4 void CPathScriptLoader::LoadScript( const char *szFile )
              5 {
              6  HANDLE fp = CreateFile(
              7        szFile,//這里輸入需要復(fù)制的文件 src 
              8        GENERIC_READ | GENERIC_WRITE, 
              9        FILE_SHARE_READ, 
             10        NULL, 
             11        OPEN_EXISTING, 
             12        FILE_FLAG_SEQUENTIAL_SCAN, 
             13        NULL);
             14  DWORD dwSize = GetFileSize( fp, 0 );
             15 
             16  HANDLE hFileMapping = CreateFileMapping(
             17        fp, 
             18        NULL, 
             19        PAGE_READWRITE, 
             20        0,//(DWORD)(dwBytesInBlock >> 16), 
             21        dwSize,//(DWORD)(dwBytesInBlock & 0x0000FFFF), 
             22        NULL);
             23 
             24  LPVOID pbFile = (LPVOID)MapViewOfFile(
             25        hFileMapping, 
             26        FILE_MAP_ALL_ACCESS, 
             27        0
             28        0
             29        dwSize);
             30 
             31  Context=(LPTSTR)pbFile;
             32  UnmapViewOfFile(pbFile);
             33  CloseHandle(hFileMapping);
             34 }
             35 
             36 // ContexScan
             37 ContexScan::ContexScan()
             38 {
             39  
             40 }
             41 
             42 ContexScan::~ContexScan()
             43 {
             44 
             45 }
             46 
             47 void ContexScan::SetExpression( const char *szExpr )
             48 {
             49  m_szExpr = (char *)szExpr;
             50  m_pLastChar = (char *)m_szExpr;
             51  m_pCurrChar = (char *)m_pLastChar;
             52 
             53  if ( *m_pLastChar == ' ' || *m_pLastChar == '\t' || *m_pLastChar == 13 )
             54   m_eState = NOPRINT;
             55  else
             56   m_eState = WORD;
             57 }
             58 
             59 bool ContexScan::SkipWord( const char *szWord )
             60 {
             61  if(NextWord())
             62  {
             63   if(strcmp(m_szCurrWord,szWord)==0)
             64    return true;
             65   printf( "Lexme ERROR: %s Excepted, but %s finded!\n", szWord, m_szCurrWord );
             66   return false;
             67  }
             68  return false;
             69 }
             70 
             71 char * ContexScan::GetNextWord()
             72 {
             73  if(NextWord())
             74   return m_szCurrWord;
             75  return NULL;
             76 }
             77 
             78 bool ContexScan::NextWord()
             79 {
             80  while(1)
             81  {
             82   if ( *m_pCurrChar == '\0' )
             83    return false;
             84 
             85   ++m_pCurrChar;
             86 
             87   if ( !isalpha(*m_pCurrChar) && !isdigit(*m_pCurrChar) && *m_pCurrChar != '.' && *m_pCurrChar != '-' )
             88   {
             89    if ( m_eState == WORD )
             90    {
             91     strncpy( m_szCurrWord, m_pLastChar, m_pCurrChar - m_pLastChar + 1 );
             92     m_szCurrWord[ m_pCurrChar - m_pLastChar ] = '\0';
             93     m_eState = NOPRINT;
             94     break;
             95    }
             96    else
             97    {
             98     m_eState = NOPRINT;
             99    }
            100   }
            101   else
            102   {
            103    if ( m_eState == NOPRINT )
            104    {
            105     m_pLastChar = m_pCurrChar;
            106     m_eState = WORD;
            107    }
            108   }
            109  }
            110 
            111  return true;
            112 }
            113 
            114 void ContexScan::RebackWordByCount( int n )
            115 {
            116  if ( *m_pLastChar == ' ' || *m_pLastChar == '\t' || *m_pLastChar == 13 )
            117   m_eState = NOPRINT;
            118  else
            119   m_eState = WORD;
            120 
            121  for(int i=0;i<n;++i)
            122  {
            123   while(1)
            124   {
            125    --m_pCurrChar;
            126    if ( !isalpha(*m_pCurrChar) && !isdigit(*m_pCurrChar) && *m_pCurrChar != '.' && *m_pCurrChar != '-' )
            127    {
            128     if ( m_eState == WORD )
            129     {
            130      m_pLastChar = m_pCurrChar + 1;
            131      m_eState = NOPRINT;
            132      break;
            133     }
            134     else
            135     {
            136      m_eState = NOPRINT;
            137     }
            138    }
            139    else
            140    {
            141     m_eState = WORD;
            142    }
            143   }
            144  }
            145 }
            146 
            147 void ContexScan::RebackNearestWordByName( const char *szWord )
            148 {
            149  if ( *m_pLastChar == ' ' || *m_pLastChar == '\t' || *m_pLastChar == 13 )
            150   m_eState = NOPRINT;
            151  else
            152   m_eState = WORD;
            153 
            154  while(1)
            155  {
            156   --m_pCurrChar;
            157   if ( !isalpha(*m_pCurrChar) && !isdigit(*m_pCurrChar) && *m_pCurrChar != '.' && *m_pCurrChar != '-' )
            158   {
            159    if ( m_eState == WORD )
            160    {
            161     m_pLastChar = m_pCurrChar + 1;
            162     m_eState = NOPRINT;
            163     if(strncmp(m_pLastChar,szWord,strlen(szWord))==0)
            164      break;
            165    }
            166    else
            167    {
            168     m_eState = NOPRINT;
            169    }
            170   }
            171   else
            172   {
            173    m_eState = WORD;
            174   }
            175  }
            176 }
            177 
            178 // AbstractNode
            179 AbstractNode::AbstractNode( ContexScan& contex ) : m_RefContexScan(contex)
            180 {
            181 }
            182 
            183 AbstractNode::~AbstractNode()
            184 {
            185 }
            186 
            187 // ProgramNode
            188 ProgramNode::ProgramNode( ContexScan& contex ) : AbstractNode(contex)
            189 {
            190 }
            191 
            192 ProgramNode::~ProgramNode()
            193 {
            194 }
            195 
            196 void ProgramNode::Parse()
            197 {
            198  m_RefContexScan.SkipWord( "GO" );
            199  if(CPathInterpret::m_Mode==CPathInterpret::DEBUG)
            200   printf("ProgramNode Node!\n");
            201  AbstractNode *pCmdListNode = new CommandListNode( m_RefContexScan );
            202  pCmdListNode->Parse();
            203  delete pCmdListNode;
            204 }
            205 
            206 // CommandListNode
            207 CommandListNode::CommandListNode( ContexScan& contex ) : AbstractNode(contex)
            208 {
            209 }
            210 
            211 CommandListNode::~CommandListNode()
            212 {
            213 }
            214 
            215 void CommandListNode::Parse()
            216 {
            217  if(CPathInterpret::m_Mode==CPathInterpret::DEBUG)
            218   printf("CommandListNode Node!\n");
            219  while(1)
            220  {
            221   char *szNext=m_RefContexScan.GetNextWord();
            222   if(strcmp(szNext,"END")==0)
            223    break;
            224   m_RefContexScan.RebackWordByCount(1);
            225   AbstractNode *pCmdNode = new CommandNode( m_RefContexScan );
            226   pCmdNode->Parse();
            227   delete pCmdNode;
            228  }
            229 }
            230 
            231 // CommandNode
            232 CommandNode::CommandNode( ContexScan& contex ) : AbstractNode(contex)
            233 {
            234 }
            235 
            236 CommandNode::~CommandNode()
            237 {
            238 }
            239 
            240 void CommandNode::Parse()
            241 {
            242  if(CPathInterpret::m_Mode==CPathInterpret::DEBUG)
            243   printf("CommandNode Node!\n");
            244  char *szWord = m_RefContexScan.GetNextWord();
            245  if(strcmp(szWord,"BEGIN")==0// BEGIN --- END
            246  {
            247   AbstractNode *pBlockNode = new BlockNode( m_RefContexScan );
            248   pBlockNode->Parse();
            249   delete pBlockNode;
            250  }
            251  else if(strcmp(szWord,"REPEAT")==0// REPEAT NUMBER
            252  {
            253   AbstractNode *pRepeatNode = new RepeatNode( m_RefContexScan );
            254   pRepeatNode->Parse();
            255   delete pRepeatNode;
            256  }
            257  else
            258  {
            259   printf( "Syntax ERROR!\n" );
            260  }
            261 }
            262 
            263 // RepeatNode
            264 RepeatNode::RepeatNode( ContexScan& contex ) : AbstractNode(contex)
            265 {
            266 }
            267 
            268 RepeatNode::~RepeatNode()
            269 {
            270 }
            271 
            272 void RepeatNode::Parse()
            273 {
            274  if(CPathInterpret::m_Mode==CPathInterpret::DEBUG)
            275   printf("RepeatNode Node!\n");
            276  int times = atoi( m_RefContexScan.GetNextWord() );
            277  for(int i=0;i<times;++i)
            278  {
            279   AbstractNode *pCmdListNode = new CommandListNode( m_RefContexScan );
            280   pCmdListNode->Parse();
            281   delete pCmdListNode;
            282 
            283   if(i==times-1)
            284    break;
            285 
            286   m_RefContexScan.RebackNearestWordByName( "REPEAT" );
            287   m_RefContexScan.NextWord();
            288   m_RefContexScan.NextWord();
            289  }
            290 }
            291 
            292 // BlockNode
            293 BlockNode::BlockNode( ContexScan& contex ) : AbstractNode(contex)
            294 {
            295 }
            296 
            297 BlockNode::~BlockNode()
            298 {
            299 }
            300 
            301 void BlockNode::Parse()
            302 {
            303  if(CPathInterpret::m_Mode==CPathInterpret::DEBUG)
            304   printf("BlockNode Node!\n");
            305  AbstractNode *pPrimNode = new PrimitiveNode( m_RefContexScan );
            306  pPrimNode->Parse();
            307  delete pPrimNode;
            308  m_RefContexScan.SkipWord( "END" );
            309 }
            310 
            311 // PrimitiveNode
            312 PrimitiveNode::PrimitiveNode( ContexScan& contex ) : AbstractNode(contex)
            313 {
            314 }
            315 
            316 PrimitiveNode::~PrimitiveNode()
            317 {
            318 }
            319 
            320 void PrimitiveNode::Parse()
            321 {
            322  if(CPathInterpret::m_Mode==CPathInterpret::DEBUG)
            323   printf("PrimitiveNode Node!\n");
            324  printf("執(zhí)行一個運動關(guān)鍵點\n");
            325  printf("當(dāng)前速度X分量為: %s\n",m_RefContexScan.GetNextWord());
            326  printf("當(dāng)前速度Y分量為: %s\n",m_RefContexScan.GetNextWord());
            327  printf("持續(xù)時間為: %s毫秒\n\n",m_RefContexScan.GetNextWord());
            328 }
            329 
            330 // CPathInterpret
            331 CPathInterpret::InterpretMode CPathInterpret::m_Mode = NDEBUG;
            332 
            333 void CPathInterpret::LoadScript( const char *szFile )
            334 {
            335  m_ScriptLoader.LoadScript( szFile );
            336  m_ContexScaner.SetExpression( m_ScriptLoader.Context.c_str() );
            337 }
            338 
            339 void CPathInterpret::Interpret( InterpretMode mode )
            340 {
            341  m_Mode = mode;
            342 
            343  AbstractNode *pRoot = new ProgramNode( m_ContexScaner );
            344  pRoot->Parse();
            345  delete pRoot;
            346 }
            347 
            348 
            posted on 2009-12-23 21:57 Reno 閱讀(291) 評論(0)  編輯 收藏 引用 所屬分類: 編譯原理/腳本語言開發(fā)

            統(tǒng)計

            久久人与动人物a级毛片| 伊人久久大香线蕉精品| 久久精品国产清自在天天线 | 嫩草伊人久久精品少妇AV| 蜜臀av性久久久久蜜臀aⅴ麻豆| 国产精品内射久久久久欢欢| 久久免费美女视频| 久久香蕉国产线看观看猫咪?v| 一本久久知道综合久久| 亚洲精品国精品久久99热一| 99久久国产综合精品五月天喷水| 久久综合亚洲色HEZYO社区| 狠色狠色狠狠色综合久久| 国产福利电影一区二区三区,免费久久久久久久精 | 久久久www免费人成精品| 97超级碰碰碰久久久久| 伊人久久一区二区三区无码| 久久精品国产亚洲av水果派| 亚洲欧洲精品成人久久奇米网| 精品久久久无码人妻中文字幕豆芽 | 国产福利电影一区二区三区久久久久成人精品综合| 久久精品国产一区二区 | 国产精品久久久久久一区二区三区 | 国产成人无码精品久久久免费 | 亚洲精品国产综合久久一线| 99re久久精品国产首页2020| 波多野结衣AV无码久久一区| 99久久亚洲综合精品成人| 男女久久久国产一区二区三区 | 久久精品综合网| 久久精品国产亚洲7777| 国产福利电影一区二区三区久久久久成人精品综合 | 久久这里的只有是精品23| 久久噜噜久久久精品66| 久久91精品久久91综合| 国产精品久久久久天天影视| 欧美熟妇另类久久久久久不卡| 久久人人爽人人爽人人片AV东京热 | 久久99久久成人免费播放| 国产一区二区三区久久精品| 久久夜色精品国产噜噜亚洲AV|