Пример #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);
         }
     }
 }
Пример #2
0
 // This constructor ignores explicit numeric value declarations
 // This might change later ...
 internal TokenInfo(LexSpan name, LexSpan alias)
 {
     this.name = name.ToString();
     if (alias != null)
     {
         this.alias = alias.ToString();
     }
 }
Пример #3
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));
        }
Пример #4
0
        // ===============================================================
        //
        //  Various helpers for the semantic actions of the parser
        //  Definition Part Helpers
        //
        // ===============================================================

        internal void SetSemanticType(LexSpan span)
        {
            if (grammar.ValueTypeNameSpan != null)
            {
                handler.ListError(grammar.ValueTypeNameSpan, 72);
                handler.ListError(span, 72);
            }
            else
            {
                grammar.ValueTypeNameSpan = span;
                grammar.ValueTypeName     = span.ToString();
            }
        }
Пример #5
0
        internal string GetLitString(LexSpan span)
        {
            string text = span.ToString();

            if (text[0] != '\"' || text[text.Length - 1] != '\"')
            {
                throw new GppgInternalException("Internal error: invalid litstring");
            }
            text = text.Substring(1, text.Length - 2);
            try
            {
                text = CharacterUtilities.InterpretCharacterEscapes(text);
            }
            catch (StringInterpretException e)
            {
                handler.ListError(span, 70, e.Message, '\'');
            }
            return(text);
        }
Пример #6
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);
            }
        }