Example #1
0
 private void AddActionToProduction(Production prod, ActionProxy proxy)
 {
     // Version 1.3.1 no longer explicitly calls FixInternalReduction().
     // It is easier to adopt a consistent approach and
     // let AddXxxToProd check for a trailing action
     // prior to adding symbols or a new action.
     //
     if (proxy != null)
     {
         if (prod.semanticAction != null || prod.precSpan != null)
         {
             FixInternalReduction(prod);
         }
         LexSpan cSpan = proxy.codeBlock;            // LexSpan of action code
         LexSpan pSpan = proxy.precedenceToken;      // LexSpan of ident in %prec ident
         if (pSpan != null)
         {
             prod.prec     = grammar.LookupTerminal(Token.ident, pSpan.ToString()).prec;
             prod.precSpan = proxy.precedenceSpan;
         }
         if (cSpan != null)
         {
             prod.semanticAction = new SemanticAction(prod, prod.rhs.Count, cSpan);
         }
     }
 }
Example #2
0
        internal static string GetVerbatimString(LexSpan span)
        {
            string text = span.ToString();

            if (text[0] != '@' || text[1] != '\"' || text[text.Length - 1] != '\"')
            {
                throw new GppgInternalException("Internal error: invalid litstring");
            }
            text = text.Substring(2, text.Length - 3);
            return(CharacterUtilities.InterpretEscapesInVerbatimString(text));
        }
Example #3
0
        // ===============================================================
        //
        //  Various helpers for the semantic actions of the parser
        //  Rules Part Helpers
        //
        // ===============================================================

        private void SetCurrentLHS(LexSpan lhs)
        {
            string      lhsName = lhs.ToString();
            NonTerminal nt      = grammar.LookupNonTerminal(lhsName);

            if (grammar.terminals.ContainsKey(lhsName))
            {
                handler.ListError(lhs, 76);
            }
            currentLHS = nt;
            if (grammar.startSymbol == null)
            {
                grammar.startSymbol = nt;
            }

            if (grammar.productions.Count == 0)
            {
                grammar.CreateSpecialProduction(grammar.startSymbol);
            }
        }