コード例 #1
0
ファイル: scanner.cpp プロジェクト: forsaken1/compiler
Token* Scanner::GetIdentificator(char currentChar) {
	string s = "";
	int pos = currentPos, line = currentLine;
	s += currentChar;

	while( !IsEndOfLine( currentChar = GetChar() ) && !IsSpace(currentChar) ) {
		if( IsLetter(currentChar) || IsNumber(currentChar) )
			s += currentChar;
		else {
			BackToPreviousChar();
			break;
		}
	}
	return new Token(line, pos, IsKeyWord(s) ? KEYWORD : IDENTIFIER, IsKeyWord(s) ? keyWord[s] : DEFAULT, s);
}
コード例 #2
0
int SymbolTableMgr::AllCapsCheck(string aname){
	if (IsKeyWord(aname)){
		//printf("The name conflicts with the key word.\n");
		return 0;
	}
	int res = pCurrentTable -> AllCapsCheck(aname);
	if (res != -1){
		pCurrentItem = pCurrentTable -> itemList[res];
		//printf("Found in the current module:%d.\n", res);
		return res;
	}
	else{
		if (pCurrentTable -> pParentItem != NULL){
			int res = pCurrentTable -> pParentItem -> pParentTable -> AllCapsCheck(aname);
			if (res != -1){
				pCurrentItem = pCurrentTable -> pParentItem -> pParentTable -> itemList[res];
				//printf("Found in the father module:%d.\n", res);
				return res;
			}
			else{
				pCurrentItem = NULL;
				//printf("Not found.\n");
				return -1;
			}
		}
		else{
			pCurrentItem = NULL;
			//printf("Not found.\n");
			return -1;
		}
	}
}
コード例 #3
0
int SymbolTableMgr::AllCapsLayerCheck(string aname){
	if (IsKeyWord(aname)){
		//printf("The name conflicts with the key word.\n");
		return 0;
	}
	int res = pCurrentTable -> AllCapsCheck(aname);
	if (res != -1){
		pCurrentItem = pCurrentTable -> itemList[res];
		//printf("Found in the current module:%d.\n", res);
	}
	else 
		;//printf("Not found in the current module.\n");
	return res;
}
コード例 #4
0
ファイル: as_tokenizer.cpp プロジェクト: Anndressa/ethanon
asETokenClass asCTokenizer::ParseToken(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const
{
	if( IsWhiteSpace(source, sourceLength, tokenLength, tokenType) ) return asTC_WHITESPACE;
	if( IsComment(source, sourceLength, tokenLength, tokenType)    ) return asTC_COMMENT;
	if( IsConstant(source, sourceLength, tokenLength, tokenType)   ) return asTC_VALUE;
	if( IsIdentifier(source, sourceLength, tokenLength, tokenType) ) return asTC_IDENTIFIER;
	if( IsKeyWord(source, sourceLength, tokenLength, tokenType)    ) return asTC_KEYWORD;

	// If none of the above this is an unrecognized token
	// We can find the length of the token by advancing
	// one step and trying to identify a token there
	tokenType   = ttUnrecognizedToken;
	tokenLength = 1;

	return asTC_UNKNOWN;
}
コード例 #5
0
int asCTokenizer::ParseToken()
{
	if( IsWhiteSpace() ) return 0;
	if( IsComment()    ) return 0;
	if( IsConstant()   ) return 0;
	if( IsIdentifier() ) return 0;
	if( IsKeyWord()    ) return 0;

	// If none of the above this is an unrecognized token
	// We can find the length of the token by advancing
	// one step and trying to identify a token there
	tokenType = ttUnrecognizedToken;
	tokenLength = 1;

	return -1;
}
コード例 #6
0
ファイル: hzoezsyn.cpp プロジェクト: arksoftgit/10c
/*
**----------------------------------------------------------------------
** .Klasse:       ZeidonSyntax
**
** .Methode:      RTFParseAll
**
** .Beschreibung: Den gesamten Text parsen und in RTF - Format umwandeln
**
** .Parameter: char* , pQuelle   , I, Pointer auf zu untersuchenden Text
**             char* , pZiel     , I, Pointer auf Schreibpuffer
**             char* , pNormalFarbe   , I, Pointer auf RTF Farbstring
**             char* , pKeywordFarbe  , I, Pointer auf RTF Farbstring
**             char* , pKommentarFarbe, I, Pointer auf RTF Farbstring
**             char* , pZeile    , I, Pointer auf RTF NewLineString
**
** .Rueckgabewert:
**
** ---------------------------------------------------------------------
**
** .Methodenbeschreibung:
**      Die Methode sucht im gesamten Text nach Keywords oder Kommentaren. Sie
**      wird beim Laden eines Files aufgerufen. Sie wandelt den Text in
**      RichText Format um. Dies beschleunigt das Laden.
**-----------------------------------------------------------------
*/
void ZeidonSyntax::RTFParseAll( char *pQuelle, char *pZiel, char *pNormalFarbe,
                                char *pKeywordFarbe, char *pKommentarFarbe,
                                char *pZeile )
{
    char *pMerk;
    char ups;
    char cHilf[500]; //[KEY_ARR_SIZE+2];
    BOOL bInTextString = FALSE;

    long lKommStringLen = lstrlen( pKommentarFarbe );
    long lKeyStringLen = lstrlen( pKeywordFarbe );
    long lNormStringLen = lstrlen( pNormalFarbe );
    long lZeilStringLen = lstrlen( pZeile );


    do
    {
        if( bInTextString ) //bin ich in einem TextString
        { // -> alle Zeichen uberlesen
            while( *pQuelle && *pQuelle != '"' && *pQuelle != '\r' )
            {
                if( *pQuelle == '{' || *pQuelle == '}' || *pQuelle == '\\' )
                    *pZiel++ = '\\';

                *pZiel++ = *pQuelle++;
            }

            if( ! *pQuelle  ) //alle anderen Faelle werden weiter unten gehandelt
                continue;
        }

        pMerk = pQuelle;

        while( IsCharAlphaNumeric( *pQuelle ) || *pQuelle == '_' )
        {
            pQuelle++;
        }

        if( pMerk != pQuelle )
        {
            ups = *pQuelle;
            *pQuelle = '\0';
            lstrcpyn( cHilf, pMerk, 498 ); //KEY_ARR_SIZE +1 );

            if( IsKeyWord( cHilf ) )
            {
                lstrcpy( pZiel, pKeywordFarbe );
                pZiel += lKeyStringLen;
                lstrcpy( pZiel, pMerk );
                pZiel += lstrlen( pMerk );
                lstrcpy( pZiel, pNormalFarbe );
                pZiel += lNormStringLen;
            }
            else
            {
                lstrcpy( pZiel, pMerk );
                pZiel += lstrlen( pMerk );
            }

            *pQuelle = ups;
        }


        if( *pQuelle == '/' && *(pQuelle+1) == '*' )
        {
            lstrcpy( pZiel, pKommentarFarbe );
            pZiel += lKommStringLen;

            do
            {
                if( *pQuelle == '{' || *pQuelle == '}' || *pQuelle == '\\' )
                    *pZiel++ = '\\';

                *pZiel++ = *pQuelle++;

                if( *pQuelle == '\r' )
                {
                    while( *pQuelle && *pQuelle == '\r' )
                        pQuelle++;

                    *pZiel++ = '\r';

                    while( *pQuelle && *pQuelle == '\n' )
                        pQuelle++;

                    *pZiel++ = '\n';
                    lstrcpy( pZiel, pZeile );
                    pZiel += lZeilStringLen;
                }

            } while( *pQuelle && ( *pQuelle != '*' || *(pQuelle+1) != '/' ) );

            if( *pQuelle )
            { //noch das Kommentarende uebertragen
                *pZiel++ = *pQuelle++;
                *pZiel++ = *pQuelle++;
            }
            lstrcpy( pZiel, pNormalFarbe );
            pZiel += lNormStringLen;
        }

        //ANfang eines Zeilenkommentars
        if( *pQuelle == '/' && *(pQuelle+1) == '/' )
        {
            lstrcpy( pZiel, pKommentarFarbe );
            pZiel += lKommStringLen;

            do
            {
                if( *pQuelle == '{' || *pQuelle == '}' || *pQuelle == '\\' )
                    *pZiel++ = '\\';

                *pZiel++ = *pQuelle++;
            } while( *pQuelle && *pQuelle != '\r' );

            lstrcpy( pZiel, pNormalFarbe );
            pZiel += lNormStringLen;
        }

        //bin ich am Zeilenende?
        if( *pQuelle == '\r' )
        {
            bInTextString = FALSE;

            *pZiel++ = '\r';

            if( *( pQuelle + 1 ) == '\n' )
                pQuelle++;

            *pZiel++ = '\n';
            lstrcpy( pZiel, pZeile );
            pZiel += lZeilStringLen;

            continue;
        }


        //bin ich am Zeilenende? ( Zeile nicht durch \r\n
        //gekennzeichnet sondern nur durch \n )
        if( *pQuelle =='\n' )
        {
            bInTextString = FALSE;

            *pZiel++ = '\r';
            *pZiel++ = '\n';

            lstrcpy( pZiel, pZeile );
            pZiel += lZeilStringLen;

            continue;
        }


        //spezielle RTF - Zeichen durch '\' abschirmen
        if( *pQuelle == '{' || *pQuelle == '}' || *pQuelle == '\\' )
        {
            *pZiel++ = '\\';
            *pZiel++ = *pQuelle;
            continue;
        }

        if( *pQuelle )
        {
            if( *pQuelle == '"' )
                bInTextString = ! bInTextString;
            *pZiel++ = *pQuelle;
        }

    } while( *pQuelle++ );
}
コード例 #7
0
ファイル: hzoezsyn.cpp プロジェクト: arksoftgit/10c
/*
**----------------------------------------------------------------------
** .Klasse:       ZeidonSyntax
**
** .Methode:      ParseTextBuffer
**
** .Beschreibung: Schnelles Parsen eines Textpuffers
**
** .Parameter:    char*, pdata   , I, Pointer auf zu untersuchenden Text
**                long , lVersatz, I, Versatzwert, wenn der Pufferanfang
**                                    nicht mit dem Textanfang ueberein-
**                                    stimmt ( fuer EM_EXSETSEL ! )
**
** .Rueckgabewert:
**
** ---------------------------------------------------------------------
**
** .Methodenbeschreibung:
**      Die Methode sucht den gesamten Puffer nach Keywords und Kommentaren.
**      Sie wird von ParseText unt TestCommentPuffer aufgerufen.
**-----------------------------------------------------------------
*/
void ZeidonSyntax::ParseTextBuffer( char* pData, long lVersatz )
{
    m_pData = pData;
    m_iLine = 0;
    long dMerk;
    char ups;


    ::SendMessage( m_hWnd, WM_SETREDRAW, FALSE, 0L );

    //nur gebraucht fuer TestCommentPuffer
    m_cha.cpMin = lVersatz;
    m_cha.cpMax = lVersatz + m_pT->m_dComSize;
    SetColor( m_pT->m_crForeground );

    do
    {
        if( m_pData[m_iLine] == '"' ) //Textstrings ueberlesen
        {
            m_iLine++;

            while( m_pData[m_iLine] && m_pData[m_iLine] != '"' &&
                   m_pData[m_iLine] != '\r' )
                m_iLine++;
        }

        dMerk = m_iLine;

        while( IsCharAlphaNumeric( m_pData[m_iLine] ) || m_pData[m_iLine] == '_' )
        {
            m_iLine++;
        }

        if( dMerk != m_iLine )
        {
            ups = m_pData[m_iLine];
            m_pData[m_iLine] = '\0';

            if( IsKeyWord( m_pData + dMerk ) )
            {
                m_cha.cpMin = dMerk + lVersatz;
                m_cha.cpMax = m_iLine + lVersatz;

                ::SendMessage( m_hWnd, EM_EXSETSEL, 0,(LPARAM) &m_cha );
                m_pT->m_cf.crTextColor = m_pT->m_crKeyword;
                ::SendMessage( m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION,
                                   (LPARAM) &m_pT->m_cf );
            }

            m_pData[m_iLine] = ups;
        }

        if( m_pData[m_iLine] == '/' && m_pData[m_iLine+1] == '*' )
        {
            dMerk = m_iLine;

            m_iLine += 2;

            while( m_pData[m_iLine] && ( m_pData[m_iLine] != '*' || m_pData[m_iLine+1] != '/' ) )
                m_iLine++;
            //mache Kommentar
            if( m_pData[m_iLine] )
            { //bei Textende darf m_iLine nicht mehr erhoeht werden! -> else-Fall
                m_iLine++;
                m_cha.cpMax = m_iLine+1+lVersatz;
            }
            else
                m_cha.cpMax = m_iLine+2+lVersatz;

            m_cha.cpMin = dMerk+lVersatz;
            ::SendMessage( m_hWnd, EM_EXSETSEL, 0,(LPARAM) &m_cha );
            m_pT->m_cf.crTextColor = m_pT->m_crComment;
            ::SendMessage( m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &m_pT->m_cf );
            continue;
        }

        if( m_pData[m_iLine] == '/' && m_pData[m_iLine+1] == '/' )
        {
            dMerk = m_iLine;

            m_iLine += 2;

            while( m_pData[m_iLine] && m_pData[m_iLine] != '\r' )
                m_iLine++;

            m_cha.cpMax = m_iLine+lVersatz;
            m_cha.cpMin = dMerk+lVersatz;
            ::SendMessage( m_hWnd, EM_EXSETSEL, 0,(LPARAM) &m_cha );
            m_pT->m_cf.crTextColor = m_pT->m_crComment;
            ::SendMessage( m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &m_pT->m_cf );
            continue;
        }

    } while( m_pData[m_iLine++] );

    ::SendMessage( m_hWnd, WM_SETREDRAW, TRUE, 0L );
    InvalidateRect( m_hWnd, NULL, FALSE );
}
コード例 #8
0
ファイル: hzoezsyn.cpp プロジェクト: arksoftgit/10c
/*
**----------------------------------------------------------------------
** .Klasse:       ZeidonSyntax
**
** .Methode:      ParseRestOfRange
**
** .Beschreibung: Untersuchen des Eingabebereichs
**
** .Parameter:
**
** .Rueckgabewert:  BOOL-> TRUE, wenn Kommentar ueber das Ende des
**                               Bereichs reicht
**
** ---------------------------------------------------------------------
**
** .Methodenbeschreibung:
**      Die Methode wird von ParseLine aufgerufen um den Eingabebereich
**      oder Reste des Eingabebereiches auf notwendiges Coloring zu
**      untersuchen.
**-----------------------------------------------------------------
*/
BOOL ZeidonSyntax::ParseRestOfRange()
{
    m_iWord = 0;
    m_iLine = 0;
    char ups;
    long lMerk;

    while( m_pData[m_iLine] )
    {
        m_cha.cpMin = m_dAnfang + m_iLine;

        if( m_pData[m_iLine] == '"' )
        {
            lMerk = m_iLine++;

            while( m_pData[m_iLine] && m_pData[m_iLine] != '"' &&
                   m_pData[m_iLine] != '\r' )
                m_iLine++;

            m_cha.cpMax = m_dAnfang + m_iLine;
            SetColor( m_pT->m_crForeground );
            m_cha.cpMin = m_cha.cpMax;
        }

        while( IsCharAlphaNumeric( m_pData[m_iLine] ) || m_pData[m_iLine] == '_' )
        {
            m_iWord++;
            m_iLine++;
        }

        if( m_iWord )
        {
            ups = m_pData[m_iLine];
            m_pData[m_iLine] = '\0';

            m_cha.cpMax = m_dAnfang + m_iLine;

            // Stop setting keywords that are part of a V.E.A from
            // being translated to uppercase (DKS).
            if( (m_iLine <= m_iWord ||
                 m_pData[ m_cha.cpMin - m_dAnfang - 1 ] != '.') &&
                IsKeyWord( m_pData + m_cha.cpMin - m_dAnfang ) )
            {
                m_chMerk = m_cha;
                SetColor( m_pT->m_crKeyword );

                m_cha.cpMin = m_cha.cpMax;
                m_cha.cpMax += 1;
                SetColor( m_pT->m_crForeground );

                if( ups == ' ' && m_pT->m_chAlt.cpMin == (long) (m_dAnfang + m_iLine) )
                {
                    if( m_iLine ) //&& m_pT->m_bInsertMode )
                    {
                        ::SendMessage( m_hWnd, EM_EXSETSEL, 0,(LPARAM) &m_chMerk );
                        ::SendMessage( m_hWnd, EM_REPLACESEL, FALSE,(LPARAM) (LPCSTR)m_pBigKeyword );
                    }
                }
            }
            else
            {
                SetColor( m_pT->m_crForeground );
            }

            m_pData[m_iLine] = ups;
            m_iWord = 0;
        }

        if( ! m_pData[m_iLine] )
            return FALSE;

        if( m_pData[m_iLine] == '/' && m_pData[m_iLine+1] == '*' )
        {
            m_cha.cpMin = m_dAnfang + m_iLine;

            m_iLine += 2;

            //Zeile nach KommentarEnde durchsuchen
            while( m_pData[m_iLine] && ( m_pData[m_iLine] != '*' || m_pData[m_iLine+1] != '/' ) )
                m_iLine++;

            if( m_pData[m_iLine] ) //Kommentarende innerhalb der Zeile
            {
                m_iLine += 2;
                m_cha.cpMax = m_dAnfang + m_iLine;

                SetColor( m_pT->m_crComment );

                if( !m_pData[m_iLine] ) //Kommentarende am Ende der Zeile
                    return FALSE;
            }
            else
            {
                m_cha.cpMax = m_dEnde;
                SetColor( m_pT->m_crComment );
                return TRUE;
            }
        }

        // ist es ein C++-Syntax Kommentar
        if( m_pData[m_iLine] == '/' && m_pData[m_iLine+1] == '/' )
        {
            m_cha.cpMin = m_dAnfang + m_iLine;

            m_iLine += 2;

            while( m_pData[m_iLine] && m_pData[m_iLine] != '\r' )
                m_iLine++;

            m_cha.cpMax = m_dAnfang + m_iLine;
            SetColor( m_pT->m_crComment );

            if( ! m_pData[m_iLine] )
                return FALSE;
        }


        if( m_pData[m_iLine] )
        {
            //pruefen ob nicht-charakter Zeichen richtige Farbe  haben
            m_cha.cpMin = m_dAnfang + m_iLine;
            m_cha.cpMax = m_cha.cpMin + 1;
            SetColor( m_pT->m_crForeground );

            m_iLine++;
        }
    }

    return FALSE;
}
コード例 #9
0
ファイル: Colorizer.cpp プロジェクト: GalacticSoft/DikuEdit
void CColorizer::SetLineColors(CString &csString, vector<COLORREF>& colors) 
{
   // nothing to do
   if (csString.GetLength() ==0) 
   {
      colors.clear();
      return;
   }

   // one COLORREF per input char
   colors.resize(csString.GetLength());

   // look for keywords

	CString word;
	word = csString;
	word.TrimLeft();
	word.TrimRight();
	word = word.Left(3);
	
	//set the line to all black
	int k = 0;
	int j = csString.GetLength();
	for(int i=0; i<j; i++)
	{
		colors.at(i) = NORMAL_COLOR;
	}

   // do keyword coloring and auto-case correction
	while(k<j)
	{
      // find "words" (sequences of alpha-numeric characters)
		word.Empty();
		while((k<j) && (!isalnum(csString.GetAt(k))))
		{
			k++;
		}

		int s = k;
		while((k < j) && (isalnum(csString.GetAt(k))))
		{
			word = word + csString.GetAt(k);
			k++;
		}
		
      int e = k;
		
      word.TrimLeft();
		word.TrimRight();

		if(IsKeyWord(word))
		{
			int l = 0;
			for(int i=s; i<e; i++)
			{
				l++;
				colors.at(i) = KEYWORD_COLOR;
			}
		}
	}
}
コード例 #10
0
ファイル: SyntaxColorizer.cpp プロジェクト: deNULL/seman
void CSyntaxColorizer::Colorize( CRichEditCtrl *pCtrl, int lineIndex, bool bModified ) 
{
	CString SourceText;
	pCtrl->GetWindowText(SourceText);
	int k = SourceText.Replace("\r\n", "\n");
	
	long nStartChar=0, nEndChar=SourceText.GetLength();
	
	if( lineIndex>=-1 && lineIndex < pCtrl->GetLineCount() ) 
	{
		nStartChar = pCtrl->LineIndex(lineIndex);
		nEndChar = nStartChar + pCtrl->LineLength(lineIndex);
	}

	CHARFORMAT2 cf = m_cfDefault;
	if( bModified ) 
	{
		cf.crBackColor = CLR_BKGRD_MODIFIED;
		cf.dwEffects = 0;
	}

	pCtrl->SetSel(nStartChar,nEndChar);
	pCtrl->SetSelectionCharFormat(cf);

	cf = m_cfDefault;
	cf.dwMask = CFM_BOLD;
	cf.crBackColor = CLR_BKGRD_UNKNOWN_ACCENT;
	cf.dwEffects = CFE_BOLD;

	for( int wordStart=nStartChar; wordStart<nEndChar; )
	{
		int lineEnd = SourceText.Find("\n",wordStart);
		if( lineEnd==-1 || lineEnd>nEndChar ) lineEnd=nEndChar;
		// пропускаем пробелы в начале строки
		for( ; wordStart<lineEnd && SourceText[wordStart]==' '; ++wordStart );
		if( wordStart<lineEnd ) 
		{
			// ищем ударение
			bool hasAccent=false;
			int i=wordStart;
			for( ; i<lineEnd && SourceText[i]!=' '; ++i )
			{	
				if( SourceText[i]=='\'' ) hasAccent=true;
			}

			if( !hasAccent ) 
				cf.dwMask |= CFM_BACKCOLOR;
			else
				cf.dwMask &= ~CFM_BACKCOLOR;

			pCtrl->SetSel(wordStart, i);
			pCtrl->SetSelectionCharFormat(cf);
		}
		wordStart = lineEnd + 1;
	}

	cf = m_cfDefault;
	cf.dwMask = CFM_BOLD | CFM_COLOR;
	cf.dwEffects = 0;

	const size_t MaxKeyWordLen = 50;
	char buffer[MaxKeyWordLen+1];

	for (long x = nStartChar; x < nEndChar; x++)
	{
		long end = x;
		for (; ((end - x) < MaxKeyWordLen) &&  Alphas[(unsigned char) SourceText.GetAt(end) ]; end++)
			buffer[end - x] = SourceText.GetAt(end);

		if (end == x) 
			continue;

		if ( (end - x) >= MaxKeyWordLen)
		{
			while (Alphas[(unsigned char) SourceText.GetAt(end) ])
				end++;
		}
		else
		{
			buffer[end-x] = 0;
			if (IsKeyWord(buffer, cf.crTextColor, m_UserData))
			{
				pCtrl->SetSel(x, end);
				pCtrl->SetSelectionCharFormat(cf);
			};
		};
		x = end;
	}
}