Class BasicCParser


  • public class BasicCParser
    extends java.lang.Object
    A rudimentary preprocessor and parser for the C programming language. FIXME replace this by a parser generated via ANTLR (if we really need it?!)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.PushbackInputStream is  
    • Constructor Summary

      Constructors 
      Constructor Description
      BasicCParser​(java.io.ByteArrayInputStream is)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static int appendHex​(int i, java.lang.StringBuilder stringBuilder, java.lang.String string)
      Parses the hexadecimal-base escape-sequence found at index i of string.
      private static int appendOct​(int i, java.lang.StringBuilder stringBuilder, java.lang.String string)
      Parses the octal-base escape-sequence found at index i of string.
      java.lang.String nextToken()  
      private static int parseEscape​(int i, java.lang.StringBuilder stringBuilder, java.lang.String string)
      Parses the i:th escape-char in the input string and appends it to stringBuilder.
      static java.io.ByteArrayOutputStream preprocess​(java.io.InputStream is, java.lang.StringBuilder firstComment, java.util.Map<java.lang.String,​java.lang.String> defines)  
      static java.lang.String[] tokenizeRow​(java.lang.String row)  
      static void unescapeString​(java.lang.StringBuilder stringBuilder, java.lang.String string)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • is

        private final java.io.PushbackInputStream is
    • Constructor Detail

      • BasicCParser

        public BasicCParser​(java.io.ByteArrayInputStream is)
    • Method Detail

      • appendHex

        private static int appendHex​(int i,
                                     java.lang.StringBuilder stringBuilder,
                                     java.lang.String string)
                              throws ImagingException
        Parses the hexadecimal-base escape-sequence found at index i of string.

        Helper-function for unescapeString().

        Parameters:
        i - the index of the escape-sequence in the string
        stringBuilder - the stringBuilder to append the escape-char to
        string - the string whose chars are parsed
        Returns:
        the new index i
        Throws:
        ImagingException
        Since:
        1.0-alpha3
      • appendOct

        private static int appendOct​(int i,
                                     java.lang.StringBuilder stringBuilder,
                                     java.lang.String string)
        Parses the octal-base escape-sequence found at index i of string.

        Helper-function for unescapeString().

        Parameters:
        i - the index of the escape-sequence in the string
        stringBuilder - the stringBuilder to append the escape-char to
        string - the string whose chars are parsed
        Returns:
        the new index i
        Since:
        1.0-alpha3
      • parseEscape

        private static int parseEscape​(int i,
                                       java.lang.StringBuilder stringBuilder,
                                       java.lang.String string)
                                throws ImagingException
        Parses the i:th escape-char in the input string and appends it to stringBuilder.

        Helper-function for unescapeString().

        Parameters:
        i - the index of the escape-char in the string
        stringBuilder - the stringBuilder to append the escape-char to
        string - the string whose chars are parsed
        Returns:
        the new index i
        Throws:
        ImagingException
        Since:
        1.0-alpha3
      • preprocess

        public static java.io.ByteArrayOutputStream preprocess​(java.io.InputStream is,
                                                               java.lang.StringBuilder firstComment,
                                                               java.util.Map<java.lang.String,​java.lang.String> defines)
                                                        throws java.io.IOException,
                                                               ImagingException
        Throws:
        java.io.IOException
        ImagingException
      • tokenizeRow

        public static java.lang.String[] tokenizeRow​(java.lang.String row)
      • unescapeString

        public static void unescapeString​(java.lang.StringBuilder stringBuilder,
                                          java.lang.String string)
                                   throws ImagingException
        Throws:
        ImagingException