Esempio n. 1
0
        public void findIdentifiers()
        {
            //  code.structAsDatatype(this.tokens);
            for (int i = 0; i < tokens.Count - 1; i++)
            {
                if ((tokens[i].isIdentifierTokenObject()) && (tokens[i + 1].getLexeme() == "("))
                {
                    functionCallCounter fc = new functionCallCounter(tokens[i]);
                    tokens[i] = fc;
                    for (int q = 0; q < holeCodeTokens.Count; q++)
                    {
                        if (holeCodeTokens[q].id == tokens[i].id)
                        {
                            holeCodeTokens[q] = fc;
                        }
                    }
                }
            }

            for (int i = 0; i < tokens.Count; i++)
            {
                bool pointer = (upperLevelPointers.Concat(thisScopePointers).ToList().Select(a => a.getLexeme()).ToList()).Contains(tokens[i].getLexeme());
                bool array   = upperLevelArray.Concat(thisScopeArray).ToList().Select(a => a.getLexeme()).ToList().Contains(tokens[i].getLexeme());
                if (((tokens[i].isPointer) || pointer))
                {
                    if ((i > 0) && tokens[i].isPointer && ((tokens[i - 1].isDatatype() || (tokens[i - 1].getLexeme() == ","))))
                    {
                        pointer p = (pointer)tokens[i];

                        if (tokens[i - 1].isDatatype())
                        {
                            p.dataType = tokens[i - 1];
                        }
                        else if (tokens[i - 1].getLexeme() == ",")
                        {
                            int k = i - 1;
                            while ((k > 0) && (!tokens[k].isDatatype()))
                            {
                                k--;
                            }
                            if (k != 0)
                            {
                                p.dataType = tokens[k];
                            }
                        }
                        thisScopePointers.Add(p);
                        for (int q = 0; (holeCodeTokens != null) && (q < holeCodeTokens.Count); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = p;
                            }
                        }

                        tokens[i] = p;
                    }
                    else if (thisScopePointers.Select(a => a.getLexeme()).ToList().Contains(tokens[i].getLexeme()))
                    {
                        pointer id;
                        id = thisScopePointers.Find(a => a.getLexeme() == tokens[i].getLexeme());

                        for (int q = 0; (holeCodeTokens != null) && (q < holeCodeTokens.Count); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = id;
                            }
                        }
                        tokens[i] = id;
                    }
                    else if (upperLevelPointers.Select(a => a.getLexeme()).ToList().Contains(tokens[i].getLexeme()))
                    {
                        pointer id;
                        id = upperLevelPointers.Find(a => a.getLexeme() == tokens[i].getLexeme());

                        for (int q = 0; (holeCodeTokens != null) && (q < holeCodeTokens.Count); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = id;
                            }
                        }
                        tokens[i] = id;
                    }
                    continue;
                }
                if ((i > 0) && ((tokens[i].isArray) || array))
                {
                    if ((i > 0) && tokens[i].isPointer && (tokens[i - 1].isDatatype()))
                    {
                        array p = (array)tokens[i];
                        if (tokens[i - 1].isDatatype())
                        {
                            p.dataType = tokens[i - 1];
                        }
                        else if (tokens[i - 1].getLexeme() == ",")
                        {
                            int k = i - 1;
                            while ((k > 0) && (!tokens[k].isDatatype()))
                            {
                                k--;
                            }
                            if (k != 0)
                            {
                                p.dataType = tokens[k];
                            }
                        }
                        thisScopeArray.Add(p);
                    }
                    else if (thisScopeArray.Select(a => a.getLexeme()).ToList().Contains(tokens[i].getLexeme()))
                    {
                        array id;
                        id = thisScopeArray.Find(a => a.getLexeme() == tokens[i].getLexeme());

                        for (int q = 0; (holeCodeTokens != null) && (q < holeCodeTokens.Count); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = id;
                            }
                        }
                        tokens[i] = id;
                    }
                    else if (upperLevelArray.Select(a => a.getLexeme()).ToList().Contains(tokens[i].getLexeme()))
                    {
                        array id;
                        id = upperLevelArray.Find(a => a.getLexeme() == tokens[i].getLexeme());

                        for (int q = 0; (holeCodeTokens != null) && (q < holeCodeTokens.Count); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = id;
                            }
                        }
                        tokens[i] = id;
                    }
                    continue;
                }
                if ((tokens[i].isIdentifierTokenObject()) && !tokens[i].isPointer && !tokens[i].isArray && !array && !pointer)
                {
                    identifier id;
                    if ((i > 0) && tokens[i].isIdentifierTokenObject() && ((tokens[i - 1].isDatatype() || tokens[i - 1].getLexeme() == ",")))
                    {
                        id = new identifier(tokens[i]);
                        if ((i > 0) && (tokens[i - 1].isDatatype()))
                        {
                            id.dataType = tokens[i - 1];
                        }
                        else if (tokens[i - 1].getLexeme() == ",")
                        {
                            int k = i - 1;
                            while ((k > 0) && (!tokens[k].isDatatype()))
                            {
                                k--;
                            }
                            if (k != 0)
                            {
                                id.dataType = tokens[k];
                            }
                        }
                        thisScopeVars.Add(id);

                        //for (int q = 0; q < thisCodeToken.Count; q++)
                        //    if (thisCodeToken[q].id == globalScobeTokens[i].id)
                        //        thisCodeToken[q] = id;

                        for (int q = 0; (holeCodeTokens != null) && (q < holeCodeTokens.Count); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = id;
                            }
                        }

                        tokens[i] = id;
                    }
                    else if (thisScopeVars.Select(a => a.getLexeme()).ToList().Contains(tokens[i].getLexeme()))
                    {
                        id = thisScopeVars.Find(a => a.getLexeme() == tokens[i].getLexeme());

                        //for (int q = 0; q < thisCodeToken.Count; q++)
                        //    if (thisCodeToken[q].id == globalScobeTokens[i].id)
                        //        thisCodeToken[q] = id;
                        for (int q = 0; (holeCodeTokens != null) && (q < holeCodeTokens.Count); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = id;
                            }
                        }
                        tokens[i] = id;
                    }
                    else if (upperLevelVar.Select(a => a.getLexeme()).ToList().Contains(tokens[i].getLexeme()))
                    {
                        id = upperLevelVar.Find(a => a.getLexeme() == tokens[i].getLexeme());
                        //for (int q = 0; q < thisCodeToken.Count; q++)
                        //    if (thisCodeToken[q].id == globalScobeTokens[i].id)
                        //        thisCodeToken[q] = id;
                        for (int q = 0; (holeCodeTokens != null) && (q < holeCodeTokens.Count); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = id;
                            }
                        }
                        tokens[i] = id;
                    }
                    else
                    {
                        id = new identifier(tokens[i]);
                        if ((i > 0) && (tokens[i - 1].isDatatype()))
                        {
                            id.dataType = tokens[i - 1];
                        }
                        thisScopeVars.Add(id);
                        //for (int q = 0; q < thisCodeToken.Count; q++)
                        //    if (thisCodeToken[q].id == globalScobeTokens[i].id)
                        //        thisCodeToken[q] = id;
                        for (int q = 0; (q < holeCodeTokens.Count) && (holeCodeTokens != null); q++)
                        {
                            if (holeCodeTokens[q].id == tokens[i].id)
                            {
                                holeCodeTokens[q] = id;
                            }
                        }
                        tokens[i] = id;
                    }
                    continue;
                }
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <result> rs = new List <result>();

            foreach (cppFile cq in Program.cppFiles)
            {
                rs.Add(cq.result);
            }
            choice c      = new choice(rs);
            var    result = c.ShowDialog();

            if (result == DialogResult.OK)
            {
                List <token> val = choice.ReturnValue;

                string s = "";
                //s += "<br/>=========================================================<br/> " + val.scopeName;
                s += "<br/>========================================================<br/>";
                if (val != null)
                {
                    foreach (token t in val)
                    {
                        if (t.isIdentifierObject())
                        {
                            identifier p = (identifier)t;
                            s += "<br/>";
                            s += "id: " + t.id + " , " + t.getLexeme() + " , DT: " + t.getType() + " , DATATYPE_LEXEME: " + p.dataType.getLexeme() + "<br/>";
                        }
                        else if (t.isPointer)
                        {
                            pointer p = (pointer)t;

                            s += "<br/>";
                            s += "id: " + t.id + " , " + t.getLexeme() + " , DT: " + t.getType() + " , DATATYPE_LEXEME: " + p.dataType.getLexeme()
                                 + " , pointer_level: " + p.pointerLevel.ToString() + "<br/>";
                        }
                        else if (t.isArray)
                        {
                            array p = (array)t;
                            s += "<br/>";
                            s += "id: " + t.id + " , " + t.getLexeme() + " , DT: " + t.getType() + " , DATATYPE_LEXEME: " + p.dataType.getLexeme()
                                 + " , array_indecies: <br/>";
                            foreach (token i in p.arrayIndices)
                            {
                                s += i.getLexeme().ToString() + "<br/>";
                            }
                            s += "<br/>";
                        }
                        else if (t.isFunctionCall)
                        {
                            s += "<br/>";
                            s += "id: " + t.id + " , " + t.getLexeme() + " , " + t.getType() + "<br/>";
                        }
                        else
                        {
                            s += "<br/>";
                            s += "id: " + t.id + " , " + t.getLexeme() + " , " + t.getType() + "<br/>";
                        }
                    }
                }
                webBrowser1.DocumentText = s;
            }
        }