コード例 #1
0
 // Returns NLitInt, NLitBool, NLitChar, NLitString or NArrayList
 public Node LitAlt()
 {
     if (firstOfLit.Contains(CurrentToken))
     {
         return(Lit());
     }
     else if (CurrentToken == TokenCategory.STRING)
     {
         NLitString nLitString = new NLitString()
         {
             AnchorToken = Expect(TokenCategory.STRING)
         };
         return(nLitString);
     }
     else if (CurrentToken == TokenCategory.CURLY_BRACE_LEFT)
     {
         return(ArrayList());
     }
     else
     {
         throw new SyntaxError(new HashSet <TokenCategory>()
         {
             TokenCategory.STRING,
             TokenCategory.CURLY_BRACE_LEFT,
             TokenCategory.TRUE,
             TokenCategory.FALSE,
             TokenCategory.BASE_2,
             TokenCategory.BASE_8,
             TokenCategory.BASE_10,
             TokenCategory.BASE_16,
             TokenCategory.CHARACTER
         }
                               , tokenStream.Current);
     }
 }
コード例 #2
0
//-----------------------------------------------------------
        public void Visit(NLitString node)
        {
            Console.WriteLine($"+++++++++++++++ NLitString ++++++++++++++++");

            /*var intStr = node.AnchorToken.Lexeme;
             *
             * try {
             *      Convert.ToInt32(intStr);
             *
             * } catch (OverflowException) {
             *      throw new SemanticError(
             *                    "Integer literal too large: " + intStr,
             *                    node.AnchorToken);
             * }*/
        }
コード例 #3
0
        public string Visit(NLitString nLitString)
        {
            string retVal = "\t\tldc.i8 0\n";

            retVal += "\t\tcall int64 class ['int64lib']'Int64'.'Utils'::'New'(int64)\n";
            string lexeme          = nLitString.AnchorToken.Lexeme;
            int    lexemeLength    = lexeme.Length;
            string sanitizedLexeme = Regex.Replace(lexeme.Substring(1, lexemeLength - 2), @"\\[u]([0-9A-Fa-f]{6})", m => char.ToString((char)ushort.Parse(m.Groups[1].Value, NumberStyles.AllowHexSpecifier)));

            sanitizedLexeme = Regex.Unescape(sanitizedLexeme);
            IEnumerable <long> codePoints = Utils.AsCodePoints(sanitizedLexeme);

            foreach (long codePoint in codePoints)
            {
                retVal += "\t\tdup\n";
                retVal += "\t\tldc.i8 " + codePoint + "\n";
                retVal += "\t\tcall int64 class ['int64lib']'Int64'.'Utils'::'add'(int64, int64)\n";
                retVal += "\t\tpop\n";
            }
            return(retVal);
        }
コード例 #4
0
//-----------------------------------------------------------
        public void Visit(NLitString node)
        {
            Console.WriteLine($"+++++++++++++++ NLitString ++++++++++++++++");
            //Console.WriteLine($"aki v ala bubi {node.AnchorToken.Lexeme}");
            if (pasones == 3)
            {
                File.AppendAllText(lePatheo,
                                   $@"ldstr {node.AnchorToken.Lexeme}
        ");
            }

            /*var intStr = node.AnchorToken.Lexeme;
             *
             * try {
             *      Convert.ToInt32(intStr);
             *
             * } catch (OverflowException) {
             *      throw new SemanticError(
             *                    "Integer literal too large: " + intStr,
             *                    node.AnchorToken);
             * }*/
        }
コード例 #5
0
 public void Visit(NLitString nLitString)
 {
     // Do nothing
 }