Example #1
0
        public readonly Parser Parser; //combination of Scanner (with token filters inside) and CoreParser

        #endregion Fields

        #region Constructors

        public Compiler(Grammar grammar)
        {
            Language = new LanguageData(grammar);
              var builder = new LanguageDataBuilder(Language);
              builder.Build();
              this.Language = builder.Language;
              if (Language.CanParse())
            Parser = new Parser(Language);
        }
Example #2
0
 public static string PrintTerminals(LanguageData language)
 {
     StringBuilder sb = new StringBuilder();
       foreach (Terminal term in language.GrammarData.Terminals) {
     sb.Append(term.ToString());
     sb.AppendLine();
       }
       return sb.ToString();
 }
Example #3
0
 public static string PrintNonTerminals(LanguageData language)
 {
     StringBuilder sb = new StringBuilder();
       foreach (NonTerminal nt in language.GrammarData.NonTerminals) {
     sb.Append(nt.Name);
     sb.Append(nt.IsSet(TermOptions.IsNullable) ? "  (Nullable) " : "");
     sb.AppendLine();
     foreach (Production pr in nt.Productions) {
       sb.Append("   ");
       sb.AppendLine(pr.ToString());
     }
       }//foreachc nt
       return sb.ToString();
 }
Example #4
0
 public static string PrintStateList(LanguageData language)
 {
     StringBuilder sb = new StringBuilder();
       foreach (ParserState state in language.ParserData.States) {
     sb.Append("State " + state.Name);
     if (state.BuilderData.IsInadequate) sb.Append(" (Inadequate)");
     sb.AppendLine();
     var srConflicts = state.BuilderData.GetShiftReduceConflicts();
     if (srConflicts.Count > 0)
       sb.AppendLine("  Shift-reduce conflicts on inputs: " + srConflicts.ToString());
     var ssConflicts = state.BuilderData.GetReduceReduceConflicts();
     if (ssConflicts.Count > 0)
       sb.AppendLine("  Reduce-reduce conflicts on inputs: " + ssConflicts.ToString());
     //LRItems
     if (state.BuilderData.ShiftItems.Count > 0) {
       sb.AppendLine("  Shift items:");
       foreach (var item in state.BuilderData.ShiftItems)
     sb.AppendLine("    " + item.ToString());
     }
     if (state.BuilderData.ReduceItems.Count > 0) {
       sb.AppendLine("  Reduce items:");
       foreach (LRItem item in state.BuilderData.ReduceItems)
     sb.AppendLine("    " + item.ToString(state.BuilderData.JumpLookaheads));
     }
     bool headerPrinted = false;
     foreach (BnfTerm key in state.Actions.Keys) {
       ParserAction action = state.Actions[key];
       if (action.ActionType != ParserActionType.Shift && action.ActionType != ParserActionType.Jump) continue;
       if (!headerPrinted)
     sb.Append("  Shifts: ");
       headerPrinted = true;
       sb.Append(key.ToString());
       if (action.ActionType == ParserActionType.Shift)
     sb.Append("->"); //shift
       sb.Append(action.NewState.Name);
       sb.Append(", ");
     }
     sb.AppendLine();
     if (state.BuilderData.JumpLookaheads.Count > 0)
       //two spaces between 'state' and state name - important for locating state from parser trace
       sb.AppendLine("  Jump to non-canonical state  " + state.BuilderData.JumpTarget + " on lookaheads: " + state.BuilderData.JumpLookaheads.ToString());
     sb.AppendLine();
       }//foreach
       return sb.ToString();
 }
Example #5
0
 public GrammarData(LanguageData language)
 {
     Language = language;
       Grammar = language.Grammar;
 }
Example #6
0
 public virtual void OnParserDataConstructed(LanguageData language)
 {
 }
Example #7
0
 //The method is called after GrammarData is constructed
 public virtual void OnGrammarDataConstructed(LanguageData language)
 {
 }
Example #8
0
 public Compiler(LanguageData language)
 {
     this.Language = language;
       Parser = new Parser(Language);
 }
Example #9
0
 public Parser(LanguageData language)
 {
     Language = language;
       Scanner = new Scanner(Language.ScannerData);
       CoreParser = new CoreParser(Language.ParserData, Scanner);
 }
Example #10
0
 public ScriptEngine(Grammar grammar)
 {
     Compiler = new Compiler(grammar);
       Language = Compiler.Language;
 }
Example #11
0
 public ScriptEngine(LanguageData language)
 {
     Language = language;
       Compiler = new Compiler(Language);
 }
Example #12
0
 public ScriptEngine(Compiler compiler)
 {
     Compiler = compiler;
       Language = Compiler.Language;
 }