public override string ToString()
        {
            string s = Core.ToString();

            if (this.Core.IsFinal)
            {
                s += " [" + Lookaheads.ToString() + "]";
            }
            return(s);
        }
        public string ToString(BnfTermSet exceptLookaheads)
        {
            string s = Core.ToString();

            if (!this.Core.IsFinal)
            {
                return(s);
            }
            var lkhds = new BnfTermSet();

            lkhds.UnionWith(Lookaheads);
            lkhds.ExceptWith(exceptLookaheads);
            s += " [" + lkhds.ToString() + "]";
            return(s);
        }
Esempio n. 3
0
 private void ReportAndCreateDefaultActionsForConflicts(ParserState state, 
     BnfTermSet shiftReduceConflicts, BnfTermSet reduceReduceConflicts)
 {
     var stateData = state.BuilderData;
       if (shiftReduceConflicts.Count > 0)
     _language.Errors.Add(GrammarErrorLevel.Conflict, state,
     "Shift-reduce conflict. State {0}, lookaheads [{1}]. Set to shift as preferred action.", state, shiftReduceConflicts.ToString());
       if (reduceReduceConflicts.Count > 0)
     _language.Errors.Add(GrammarErrorLevel.Conflict, state,
       "Reduce-reduce conflict. State {0}, lookaheads: {1}. Set to reduce on first production in conflict set.", state, reduceReduceConflicts.ToString());
       //Create default actions for these conflicts. For shift-reduce, default action is shift, and shift action already
       // exist for all shifts from the state, so we don't need to do anything, only report it
       //For reduce-reduce create reduce actions for the first reduce item (whatever comes first in the set).
       foreach (var conflict in reduceReduceConflicts) {
     var reduceItems = stateData.ReduceItems.SelectByLookahead(conflict);
     var firstProd = reduceItems.First().Core.Production;
     var action = ParserAction.CreateReduce(firstProd);
     state.Actions[conflict] = action;
       }
       //Update ResolvedConflicts and Conflicts sets
       stateData.ResolvedConflicts.UnionWith(shiftReduceConflicts);
       stateData.ResolvedConflicts.UnionWith(reduceReduceConflicts);
       stateData.Conflicts.ExceptWith(stateData.ResolvedConflicts);
 }
        private void ReportParseConflicts(string description, ParserState state, BnfTermSet lookaheads)
        {
            string msg = description + " State " + state.Name + ", lookaheads: " + lookaheads.ToString();

            AddError(msg);
        }
Esempio n. 5
0
 private void ValidateGrammar()
 {
     //Check CreateAst flag and give a warning if this flag is not set, but node types or NodeCreator methods are assigned
     // in any of non-terminals
     if (!_grammar.FlagIsSet(LanguageFlags.CreateAst))
     {
         var ntSet = new BnfTermSet();
         foreach (var nt in _grammarData.NonTerminals)
         {
             if (nt.NodeCreator != null || nt.NodeType != null)
             {
                 ntSet.Add(nt);
             }
         }
         if (ntSet.Count > 0)
         {
             this._language.Errors.Add("Warning: LanguageFlags.CreateAst flag is not set in grammar's Flags, but there are" +
                                       " non-terminals that have NodeType or NodeCreator property set. If you want Irony to construct AST tree during parsing," +
                                       " set CreateAst flag in Grammar. Non-terminals: " + ntSet.ToString());
         }
     }
 }//method
 private void ReportParseConflicts(string description, ParserState state, BnfTermSet lookaheads) {
   string msg = description + " State " + state.Name + ", lookaheads: " + lookaheads.ToString();
   AddError(msg);
 }
 private void ValidateGrammar() {
   //Check CreateAst flag and give a warning if this flag is not set, but node types or NodeCreator methods are assigned
   // in any of non-terminals
   if (!_grammar.FlagIsSet(LanguageFlags.CreateAst)) {
     var ntSet = new BnfTermSet();
     foreach (var nt in _grammarData.NonTerminals)
       if (nt.NodeCreator != null || nt.NodeType != null)
         ntSet.Add(nt); 
     if (ntSet.Count > 0)
       this._language.Errors.Add("Warning: LanguageFlags.CreateAst flag is not set in grammar's Flags, but there are" +
         " non-terminals that have NodeType or NodeCreator property set. If you want Irony to construct AST tree during parsing," +
         " set CreateAst flag in Grammar. Non-terminals: " + ntSet.ToString()); 
   }
 }//method