Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private string[] ParseParameterList(CTokenReader Tokens, bool JustIdentifiers = false)
        {
            //Console.WriteLine("++++++++");
            var Params = new List <string>();

            Tokens.ExpectCurrentAndMoveNextSpace("(");
            while (Tokens.HasMore && Tokens.Current.Raw != ")")
            {
                string Param = "";

                if (JustIdentifiers)
                {
                    Param = Tokens.Current.Raw;
                    Tokens.MoveNextNoSpace();
                    if (Tokens.Current.Raw == ",")
                    {
                        Tokens.ExpectCurrentAndMoveNextNoSpace(",");
                    }
                }
                else
                {
                    int OpenCount = 0;
                    while (Tokens.HasMore)
                    {
                        if (Tokens.Current.Raw == ")")
                        {
                            if (OpenCount <= 0)
                            {
                                break;
                            }
                            else
                            {
                                OpenCount--;
                            }
                        }
                        Param += Tokens.Current.Raw;
                        if (Tokens.Current.Raw == "(")
                        {
                            OpenCount++;
                        }
                        Tokens.MoveNextSpace();
                        if (Tokens.Current.Raw == "," && OpenCount == 0)
                        {
                            Tokens.ExpectCurrentAndMoveNextNoSpace(",");
                            break;
                        }
                    }
                }

                //Console.WriteLine("aa: {0} : {1}", Param, Tokens.Current);
                Params.Add(Param);
            }
            //Console.WriteLine("--------");
            Tokens.ExpectCurrentAndMoveNextSpace(")");
            return(Params.ToArray());
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Process"></param>
        private bool ParseDirective(bool Process = true)
        {
            Tokens.ExpectCurrentAndMoveNextNoSpace("#");
            var PreprocessorDirective = Tokens.Current.Raw;

            //Console.WriteLine("kk: {0}", PreprocessorDirective);

            switch (PreprocessorDirective)
            {
            case "elif": return(false);

            case "else": return(false);

            case "endif": return(false);

            case "if": ParseDirectiveIf(Process); break;

            case "ifndef": ParseDirectiveIfdef(Process, false); break;

            case "ifdef": ParseDirectiveIfdef(Process, true); break;

            case "define": if (Process)
                {
                    ParseDirectiveDefine();
                }
                else
                {
                    ReadTokensUntilLineEnd();
                } break;

            case "undef": if (Process)
                {
                    ParseDirectiveUndef();
                }
                else
                {
                    ReadTokensUntilLineEnd();
                } break;

            case "include": if (Process)
                {
                    ParseDirectiveInclude();
                }
                else
                {
                    ReadTokensUntilLineEnd();
                } break;

            case "error": if (Process)
                {
                    ParseDirectiveError();
                }
                else
                {
                    ReadTokensUntilLineEnd();
                } break;

            case "pragma": if (Process)
                {
                    ParseDirectivePragma();
                }
                else
                {
                    ReadTokensUntilLineEnd();
                } break;

            case "line": ReadTokensUntilLineEnd(); break;                     // Ignore

            default:
                throw (new NotImplementedException(String.Format("Can't handle preprocessor '{0}'", PreprocessorDirective)));
            }

            return(true);
        }