Inheritance: Parser
Ejemplo n.º 1
0
        void Parse(string s)
        {
            Parser parserMyParser = new syntax();

            //parserMyParser.m_symbols.EOFSymbol.
            parserMyParser.Parse(new StreamReader(s));
            symTable.Dump();
        }
Ejemplo n.º 2
0
            public static syntax parseF1(syntax str) //F' -> ^F | пусто
            {
                switch (str.Lexems.FirstOrDefault().Value)
                {
                case "^":
                    str.tree(str.Lexems.FirstOrDefault().TokType, str.Lexems.FirstOrDefault().Value);
                    str.Lexems.RemoveAt(0);
                    return(parseF(str));

                default:
                    return(str);
                }
            }
 /// <summary>
 /// This function allows a text description (or query) of set 
 /// of pocket hands to be specified such that all of the hands that match
 /// this query will be returned.
 /// </summary>
 /// <param name="s">Query String</param>
 /// <returns></returns>
 public static PocketHands Query(string s)
 {
     try
     {
         syntax p = new syntax();
         // For debugging the parser
         //p.m_debug = true;
         object obj = p.Parse(s);
         return (PocketHands)((Expr)((SpecDoc)obj).yylval).yylval;
     }
     catch
     {
         throw new ArgumentException("Syntax Error");
     }
 }
 /// <summary>
 /// This function allows a text description (or query) of set
 /// of pocket hands to be specified such that all of the hands that match
 /// this query will be returned.
 /// </summary>
 /// <param name="s">Query String</param>
 /// <returns></returns>
 static public PocketHands Query(string s)
 {
     try
     {
         syntax p = new syntax();
         // For debugging the parser
         //p.m_debug = true;
         object obj = p.Parse(s);
         return((PocketHands)((Expr)((SpecDoc)obj).yylval).yylval);
     }
     catch
     {
         throw new ArgumentException("Syntax Error");
     }
 }
Ejemplo n.º 5
0
            public static syntax parseV(syntax str) //V -> (E) | id | numb
            {
                switch (str.Lexems.FirstOrDefault().TokType)
                {
                case "Lparen":
                    str.tree(str.Lexems.FirstOrDefault().TokType, str.Lexems.FirstOrDefault().Value);
                    str.Lexems.RemoveAt(0);
                    syntax resLp = parseE(str);

                    switch (resLp.Lexems.FirstOrDefault().TokType)
                    {
                    case "Rparen":
                        str.tree(str.Lexems.FirstOrDefault().TokType, str.Lexems.FirstOrDefault().Value);
                        resLp.Lexems.RemoveAt(0);
                        return(resLp);

                    default:
                        Console.WriteLine(" Error - nonexistent )");
                        break;
                    }
                    return(resLp);

                case "Identifier":
                    str.Results.Add(str.Lexems.FirstOrDefault().Value);
                    str.Lexems.RemoveAt(0);
                    return(str);

                case "Number":
                    str.Results.Add(str.Lexems.FirstOrDefault().Value);
                    str.Lexems.RemoveAt(0);
                    return(str);

                case "Operator":
                    if (str.Lexems.First().Value == "-")
                    {
                        str.Results.Add("-" + str.Lexems.FirstOrDefault().Value);
                        str.Lexems.RemoveAt(0);
                        return(str);
                    }
                    return(str);

                default:
                    break;
                }
                return(str);
            }
Ejemplo n.º 6
0
            public static syntax parseT1(syntax str) //T' -> *FT' | /FT' | пусто
            {
                switch (str.Lexems.FirstOrDefault().Value)
                {
                case "*":
                    str.tree(str.Lexems.FirstOrDefault().TokType, str.Lexems.FirstOrDefault().Value);
                    str.Lexems.RemoveAt(0);
                    return(parseT1(parseF(str)));

                case "/":
                    str.tree(str.Lexems.FirstOrDefault().TokType, str.Lexems.FirstOrDefault().Value);
                    str.Lexems.RemoveAt(0);
                    return(parseT1(parseF(str)));

                default:
                    return(str);    //Возвращаем то же самое выражение
                }
            }
Ejemplo n.º 7
0
            public static syntax parseE1(syntax str) //E' -> +TE' | -TE' | пусто
            {
                switch (str.Lexems.FirstOrDefault().Value)
                {
                case "+":
                    str.tree(str.Lexems.FirstOrDefault().TokType, str.Lexems.FirstOrDefault().Value);
                    str.Lexems.RemoveAt(0);
                    return(parseE1(parseT(str)));

                case "-":
                    str.tree(str.Lexems.FirstOrDefault().TokType, str.Lexems.FirstOrDefault().Value);
                    str.Lexems.RemoveAt(0);
                    return(parseE1(parseT(str)));

                default:
                    return(str);    //Возвращаем то же самое выражение
                }
            }
Ejemplo n.º 8
0
        public LexicalAnalyzer()
        {
            using (StreamWriter write = new StreamWriter(@"C:\Users\justh\Desktop\abc1.wc", true))
            {
                write.Write("\n");
                write.Close();
            }
            using (StreamReader reader = new StreamReader(@"C:\Users\justh\Desktop\abc1.wc", true))
            {
                abc = reader.ReadToEnd();
                reader.Close();
            }
            //Keywords
            keywords.Add("None", "None");
            keywords.Add("True", "Bool_Const");
            keywords.Add("False", "Bool_Const");
            keywords.Add("Begin", "Begin");
            keywords.Add("Bool", "DT");
            keywords.Add("Char", "DT");
            keywords.Add("Num", "DT");
            keywords.Add("Dec", "DT");
            keywords.Add("string", "DT");
            keywords.Add("Loop", "Loop");
            keywords.Add("Check", "Check");
            keywords.Add("Then", "Then");
            keywords.Add("Default", "Default");
            keywords.Add("return", "return");
            keywords.Add("Enum", "Enum");
            keywords.Add("Continue", "Continue");
            keywords.Add("Break", "Break");
            keywords.Add("Create", "Create");
            keywords.Add("Public", "AM");
            keywords.Add("Private", "AM");

            keywords.Add("Start", "Start");
            keywords.Add("Class", "Class");

            //Operators
            Operators.Add("+", "PM");
            Operators.Add("-", "PM");
            Operators.Add("*", "MDM");
            Operators.Add("/", "MDM");
            Operators.Add("%", "MDM");
            Operators.Add("=", "=");
            Operators.Add(">", "RO");
            Operators.Add("<", "RO");
            Operators.Add("+=", "ASS_OP");
            Operators.Add("-=", "ASS_OP");
            Operators.Add("*=", "ASS_OP");
            Operators.Add("%=", "ASS_OP");
            Operators.Add("/=", "ASS_OP");
            Operators.Add("++", "++");
            Operators.Add("--", "--");
            Operators.Add("==", "RO");
            Operators.Add("<=", "RO");
            Operators.Add(">=", "RO");
            Operators.Add("&&", "&&");
            Operators.Add("||", "||");
            Operators.Add("!", "!");
            Operators.Add("<-", "Cast Operator");
            Operators.Add("!=", "ASS_OP");
            Operators.Add("|", "|");
            Operators.Add("&", "&");



            //Punctuators
            Punctuators.Add("\\", "MOP");
            Punctuators.Add("[", "[");
            Punctuators.Add("]", "]");
            Punctuators.Add("{", "{");
            Punctuators.Add("}", "}");
            Punctuators.Add("(", "(");
            Punctuators.Add(")", ")");
            Punctuators.Add(",", ",");
            Punctuators.Add(":", ":");
            Punctuators.Add(".", ".");

            Write();
            t.Add(new token("$", "$", NewLineCounter));
            token_ind++;
            display();

            syntax S1 = new syntax(t);
        }
Ejemplo n.º 9
0
 (syntax, semantic) = resultSetter(syntax, semantic, a.Diagnostics);
 var(syntax, symbol) = clazz;
 new InstanceReferenceOperation(InstanceReferenceKind.ImplicitReceiver, _semanticModel, syntax, type.GetPublicSymbol(), constantValue: default, isImplicit: true);
Ejemplo n.º 12
0
            public static void getParse(List <Lexem> lexems)
            {
                syntax parsStr = new syntax(lexems);

                parseE(parsStr).output();
            }
 new InstanceReferenceExpression(InstanceReferenceKind.ImplicitReceiver, _semanticModel, syntax, type, constantValue: default, isImplicit: true);
Ejemplo n.º 14
0
 internal string getHeader(syntax s)
 {
     switch (s)
     {
         case syntax.C: return "/*" + this.comment + "*/\r\ntypedef enum _PGM_" + this.name + "_TYPE {";
         case syntax.CSHARP: return "/*" + this.comment + "*/\r\npublic enum PGM_" + this.name + "_TYPE : ushort {";
     }
     return "";
 }
Ejemplo n.º 15
0
 internal string getFooter(syntax s)
 {
     switch (s)
     {
         case syntax.C: return "} PGM_" + this.name + "_TYPE;";
         case syntax.CSHARP: return "};";
     }
     return "";
 }
Ejemplo n.º 16
0
 ReportIfInvalidTargetNamespace(diagnosticReceiver, symbol, syntax, arguments, context.CancellationToken);
Ejemplo n.º 17
0
 //Правила
 public static syntax parseE(syntax str) //E -> TE'
 {
     return(parseE1(parseT(str)));
 }
Ejemplo n.º 18
0
 public static syntax parseT(syntax str) // T -> FT'
 {
     return(parseT1(parseF(str)));
 }
Ejemplo n.º 19
0
 public static syntax parseF(syntax str) //F -> VF'
 {
     return(parseF1(parseV(str)));
 }