Inheritance: LangOrTransDef
Exemplo n.º 1
0
        //Generate the Lookahed computation for a particular language definition
        private static bool GenerateLookaheadExpr(LangDef def, StringBuilder sb, AlphabetDef aDef)
        {
            List<FastToken> children;
            foreach (var ruleCase in def.cases)
            {
                children = ruleCase.pat.children;
                sb.AppendLine("if(this.symbol==" + aDef.id.text + "." + ruleCase.pat.symbol + "){");
                sb.Append("if(");
                PrintExpr(children, ruleCase.where, sb);
                sb.AppendLine("){");

                #region Compute the given subsets
                int childPos = 0;
                string childName, langName;
                HashSet<string>[] givenElelements = new HashSet<string>[children.Count];
                for (int i = 0; i < givenElelements.Length; i++)
                    givenElelements[i] = new HashSet<string>();
                #endregion

                #region Populate given elements
                foreach (var giv in ruleCase.given)
                {
                    if (giv.kind == FExpKind.App)
                    {
                        langName = ((AppExp)giv).func.name.text;
                        childName = ((AppExp)giv).args[0].token.text;
                        childPos = 0;
                        foreach (var child in children)
                        {
                            if (child.text == childName)
                                break;
                            childPos++;
                        }
                        //Array of sets of langauges
                        if (!givenElelements[childPos].Contains(langName))
                            givenElelements[childPos].Add(langName);
                    }
                }
                #endregion

                #region Compute lookahead
                bool needsComma;
                int givenUsed = 0;
                for (int i = 0; i < givenElelements.Length; i++)
                {
                    if (givenElelements[i].Count != 0)
                    {
                        sb.Append("if(this.children[" + i + "].langsLabel.IsSupersetOf(new string[] {");
                        needsComma = false;
                        foreach (var lang in givenElelements[i])
                        {
                            if (needsComma)
                                sb.Append(", ");
                            sb.Append("\"" + lang + "\"");
                            needsComma = true;
                        }
                        sb.Append("})){");
                        sb.AppendLine();
                        givenUsed++;
                    }
                }
                sb.AppendLine("this.langsLabel.Add(\"" + def.func.name.text + "\");");
                #endregion

                for (int i = 0; i < givenUsed; i++)
                    sb.AppendLine("}");
                sb.AppendLine("}");
                sb.AppendLine("}");
            }
            sb.AppendLine();
            return true;
        }
Exemplo n.º 2
0
 //Generate CSharp for languages
 private static bool GenerateLanguage(LangDef def, StringBuilder sb)
 {
     sb.AppendLine("public bool " + def.func.name + "(){");
     sb.AppendLine("return this.langsLabel.Contains(\""+def.func.name+"\");");
     sb.AppendLine("}");
     return true;
 }