Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #5610 > unrolled thread

Passing a Method Name to a Method, Redux

Started byGene Wirchenko <genew@ocis.net>
First post2011-06-23 16:03 -0700
Last post2011-06-24 15:50 -0700
Articles 20 on this page of 50 — 10 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 16:03 -0700
    Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 16:26 -0700
      Re: Passing a Method Name to a Method, Redux blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-27 21:41 +0000
    Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-23 17:24 -0700
      Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 19:46 -0700
        Re: Passing a Method Name to a Method, Redux blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-04 03:26 +0000
          Re: Passing a Method Name to a Method, Redux lewbloch <lewbloch@gmail.com> - 2011-07-04 03:41 -0700
            Re: Passing a Method Name to a Method, Redux blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-05 19:07 +0000
    Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-23 17:34 -0700
      Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 19:42 -0700
    Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-23 18:30 -0700
      Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 19:48 -0700
        Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-23 21:02 -0700
          Re: Passing a Method Name to a Method, Redux lewbloch <lewbloch@gmail.com> - 2011-06-24 08:38 -0700
            Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-24 09:04 -0700
              Re: Passing a Method Name to a Method, Redux Lew <noone@lewscanon.com> - 2011-06-26 13:43 -0400
                Re: Passing a Method Name to a Method, Redux Lew <noone@lewscanon.com> - 2011-06-26 14:31 -0400
          Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-24 11:45 -0700
            Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-24 12:19 -0700
              Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-26 20:39 -0700
                Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-26 23:33 -0700
                  Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-27 13:53 -0700
                    Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-27 18:03 -0700
                      Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-28 11:41 -0700
          Re: Passing a Method Name to a Method, Redux blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-24 19:19 +0000
    Re: Passing a Method Name to a Method, Redux Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-23 19:36 -0700
      Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-24 11:50 -0700
        Re: Passing a Method Name to a Method, Redux Jeff Higgins <jeff@invalid.invalid> - 2011-06-24 17:25 -0400
          Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-26 20:42 -0700
            Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-26 23:27 -0700
            Re: Passing a Method Name to a Method, Redux Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-27 03:04 -0400
              Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-27 13:12 -0700
                Re: Passing a Method Name to a Method, Redux Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-27 13:36 -0700
                Re: Passing a Method Name to a Method, Redux Arne Vajhøj <arne@vajhoej.dk> - 2011-07-21 20:43 -0400
                  Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-07-22 12:35 -0700
                    Re: Passing a Method Name to a Method, Redux Patricia Shanahan <pats@acm.org> - 2011-07-22 13:09 -0700
                    Re: Passing a Method Name to a Method, Redux lewbloch <lewbloch@gmail.com> - 2011-07-22 13:35 -0700
                    Re: Passing a Method Name to a Method, Redux Arne Vajhøj <arne@vajhoej.dk> - 2011-07-22 16:53 -0400
                    Re: Passing a Method Name to a Method, Redux Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-23 13:19 +0000
                      Re: Passing a Method Name to a Method, Redux Arne Vajhøj <arne@vajhoej.dk> - 2011-07-23 11:19 -0400
                        Re: Passing a Method Name to a Method, Redux lewbloch <lewbloch@gmail.com> - 2011-07-23 09:20 -0700
                          Re: Passing a Method Name to a Method, Redux Arne Vajhøj <arne@vajhoej.dk> - 2011-07-23 13:33 -0400
                            Re: Passing a Method Name to a Method, Redux lewbloch <lewbloch@gmail.com> - 2011-07-23 11:43 -0700
                              Re: Passing a Method Name to a Method, Redux lewbloch <lewbloch@gmail.com> - 2011-07-23 12:14 -0700
                                Re: Passing a Method Name to a Method, Redux Arne Vajhøj <arne@vajhoej.dk> - 2011-07-23 19:19 -0400
                              Re: Passing a Method Name to a Method, Redux Arne Vajhøj <arne@vajhoej.dk> - 2011-07-23 19:12 -0400
                        Re: Passing a Method Name to a Method, Redux Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-23 17:24 +0000
                          Re: Passing a Method Name to a Method, Redux Arne Vajhøj <arne@vajhoej.dk> - 2011-07-23 19:22 -0400
                            Re: Passing a Method Name to a Method, Redux Martin Gregorie <martin@address-in-sig.invalid> - 2011-07-24 10:02 +0000
        Re: Passing a Method Name to a Method, Redux Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-24 15:50 -0700

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#5703

Frommarkspace <-@.>
Date2011-06-26 23:33 -0700
Message-ID<iu9889$vbj$1@dont-email.me>
In reply to#5700
On 6/26/2011 8:39 PM, Gene Wirchenko wrote:

>       You are misunderstanding.  The test code that I am referring to
> is proof-of-concept code to test ideas, *not* my test cases.

I don't see what you are doing then.  Is the code you showed us not your 
"test/proof of concept?"

First, a proof of concept is a little silly for a parser.  Of course 
it's feasible.  And then you are running timing test on it.  Shouldn't 
you be doing time tests on something you intend to throw away?  Profile 
the real code!

You seem to be making a lot of extra work for yourself, or at least 
confusing the heck out of us.


>       But I do not want to do that.  I am writing a preprocessor to
> process files like:

You should be using input like what you showed to test then.  The test 
code you showed us won't parse this correctly.

[toc] | [prev] | [next] | [standalone]


#5713

FromGene Wirchenko <genew@ocis.net>
Date2011-06-27 13:53 -0700
Message-ID<0eqh071t45p7582aqk4qqdu59eplcmft93@4ax.com>
In reply to#5703
On Sun, 26 Jun 2011 23:33:44 -0700, markspace <-@.> wrote:

>On 6/26/2011 8:39 PM, Gene Wirchenko wrote:
>
>>       You are misunderstanding.  The test code that I am referring to
>> is proof-of-concept code to test ideas, *not* my test cases.
>
>I don't see what you are doing then.  Is the code you showed us not your 
>"test/proof of concept?"

     It is.

>First, a proof of concept is a little silly for a parser.  Of course 
>it's feasible.  And then you are running timing test on it.  Shouldn't 
>you be doing time tests on something you intend to throw away?  Profile 
>the real code!

     I wanted to know which way to jump on character identification. I
figured that squential would be bad though it is not as bad as I
thought.  I did not know which of a binary search on a String or a
Treeset search would be faster.  That was why I wrote the test.

>You seem to be making a lot of extra work for yourself, or at least 
>confusing the heck out of us.

     I am an experienced programmer, but I am not so experienced with
Java.  I am trying to remedy the latter.

     On the confusion, I see that a number of people have
micro-optimised for my code.  I am looking at a bigger picture.

>>       But I do not want to do that.  I am writing a preprocessor to
>> process files like:
>
>You should be using input like what you showed to test then.  The test 
>code you showed us won't parse this correctly.

     Of course not.  The test code is just for dealing with
identifiers, and it is a simplified version to boot.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5717

Frommarkspace <-@.>
Date2011-06-27 18:03 -0700
Message-ID<iub99g$k15$1@dont-email.me>
In reply to#5713
On 6/27/2011 1:53 PM, Gene Wirchenko wrote:
>
>       I am an experienced programmer, but I am not so experienced with
> Java.  I am trying to remedy the latter.


Honestly, what you've done so far is pretty crazy.  I figured you were a 
2nd year student who got in over his head on a personal project, or a 
homework problem.  No sane programmer would try to search for characters 
the way you are.

If you want to tell us what your actual experience is, it might help. 
I'm guessing your experience isn't actually programming, maybe HTML and 
Flash or something.  But I don't want to get into an argument here so if 
you don't want to tell us then it's ok to drop it.


>       On the confusion, I see that a number of people have
> micro-optimised for my code.  I am looking at a bigger picture.


It's hard to give you a big picture.  Well, a couple have tried.  JavaCC 
or parboiled or similar compiler-compiler would help you the most.  But 
besides that you've given us only a very micro example.  We can't do 
anything else with the code other than micro-optimize.

And on my system using a StringBuilder instead of '+' yields a 200% 
speed up.  Times go from 22 seconds to around 6.  I don't really call 
that micro.


>
>       Of course not.  The test code is just for dealing with
> identifiers, and it is a simplified version to boot.


Part of the problem is that you aren't really testing those three search 
routines.  You're testing other things like string concatenation, 
because those are dominating the running time of your tests.

I'd start over.  Download an IDE like NetBeans.  Start a new project 
with a single class with just the search routines (shown below).  Use 
Tools -> Create Unit Tests.  That will at least generate a saner 
framework for you to put your testing.  It does need testing, and you 
can make a couple of tests do timing for you.  I think it'll help you 
think about the problem more clearly too, things were kinda messy in there.

class TimingTesting
{

     static String cParseString =
      "//identifier//IDENTIFIER//a_b_c "
      +"abc1234b5%$__dbl;one;two;three;END";
     static String IdentChars =
         "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "_"
         + "abcdefghijklmnopqrstuvwxyz";     // sorted order!
     static SortedSet<Character> IdentCharsSet
         = new TreeSet<Character>();
     static int nRepetitions = 1000000;


     // Just these three methods and no more!!!

     static boolean SequentialSearch(
             char CurrChar )
     {
         boolean fFound = false;
         for( int i = 0; i < IdentChars.length() && !fFound; i++ ) {
             fFound = IdentChars.charAt( i ) == CurrChar;
         }
         return fFound;
     }

     static boolean BinarySearch(
             char CurrChar )
     {
         int xLow = 0;
         int xHigh = IdentChars.length() - 1;
         int xTry;
         boolean fFound = false;
         while( xLow <= xHigh ) {
             xTry = ( xLow + xHigh ) / 2;
             if( CurrChar == IdentChars.charAt( xTry ) ) {
                 return true;
             }
             if( CurrChar < IdentChars.charAt( xTry ) ) {
                 xHigh = xTry - 1;
             } else {
                 xLow = xTry + 1;
             }
         }
         return false;
     }

     static boolean TreesetSearch(
             char CurrChar )
     {
         return IdentCharsSet.contains( CurrChar );
     }

}

[toc] | [prev] | [next] | [standalone]


#5744

FromGene Wirchenko <genew@ocis.net>
Date2011-06-28 11:41 -0700
Message-ID<6v7k079ovl0hiis4uph8avhg5vd49gb1hh@4ax.com>
In reply to#5717
On Mon, 27 Jun 2011 18:03:42 -0700, markspace <-@.> wrote:

>On 6/27/2011 1:53 PM, Gene Wirchenko wrote:
>>
>>       I am an experienced programmer, but I am not so experienced with
>> Java.  I am trying to remedy the latter.

>Honestly, what you've done so far is pretty crazy.  I figured you were a 
>2nd year student who got in over his head on a personal project, or a 
>homework problem.  No sane programmer would try to search for characters 
>the way you are.

     You do not know my requirements, but you claim I am not sane?

<plonk>

[snip]

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5654

Fromblmblm@myrealbox.com <blmblm.myrealbox@gmail.com>
Date2011-06-24 19:19 +0000
Message-ID<96k6atFt60U2@mid.individual.net>
In reply to#5626
In article <iu129n$d0q$1@dont-email.me>, markspace  <-@.> wrote:
> On 6/23/2011 7:48 PM, Gene Wirchenko wrote:
> > On Thu, 23 Jun 2011 18:30:21 -0700, markspace<-@.>  wrote:

[ snip ]

> BTW I refactored your test that you were copy-and-pasting around into 
> one method.  Using techniques I mentioned in my first post to you on 
> this subject.
> 
>      private static void time( TestCase r ) {
>          long StartTime = System.nanoTime();
>          for( int i = 1; i <= nRepetitions; i++ ) {
>             r.parse();
>          }
>          long EndTime = System.nanoTime();
>          long Duration = EndTime - StartTime;
>          System.out.println( " Duration=" + (Duration/1e9) );
>      }

Gene --

Below is my revision, along similar lines to what markspace suggests
above but a complete program program based on your code.  I tried not
to make gratuitous additional changes, but I admit that I did move the
declaration of the loop counter into the "for" construct because, well,
*one* gratuitous change to make the program look less Java-unidiomatic?
(Also I admit I ran the whole program through vim's "reindent", but
that should change only whitespace.)

Non-whitespace changes marked "// (blmblm)".


import java.util.*;



public class TimingTesting2
{

    // (blmblm) added
    interface Searcher {
        boolean search(char CurrChar);
    }

    static String cParseString=
        "//identifier//IDENTIFIER//a_b_c abc1234b5%$__dbl;one;two;three;END";

    static String IdentChars=
        "0123456789"+
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+
        "_"+
        "abcdefghijklmnopqrstuvwxyz";     // sorted order!

    static SortedSet<Character> IdentCharsSet=new TreeSet<Character>();

    static int nRepetitions=1000000;



    static boolean SequentialSearch
        (
         char CurrChar
        )
        {
            boolean fFound=false;
            for (int i=0; i<IdentChars.length() && !fFound; i++)
                fFound=IdentChars.charAt(i)==CurrChar;
            return fFound;
        }



    static boolean BinarySearch
        (
         char CurrChar
        )
        {
            int xLow=0;
            int xHigh=IdentChars.length()-1;
            int xTry;
            boolean fFound=false;
            while (xLow<=xHigh)
            {
                xTry=(xLow+xHigh)/2;
                if (CurrChar==IdentChars.charAt(xTry))
                    return true;
                if (CurrChar<IdentChars.charAt(xTry))
                    xHigh=xTry-1;
                else
                    xLow=xTry+1;
            }
            return false;
        }



    static boolean TreesetSearch
        (
         char CurrChar
        )
        {
            return IdentCharsSet.contains(CurrChar);
        }


    // (blmblm) merge three separate Parse routines
    static void Parse(Searcher searcher)
    {
        int xScan=0;
        boolean fBuildingIdent=false;
        boolean fInIdentChars;
        String cIdent="";     // fussy init
        while (xScan<cParseString.length())
        {
            char CurrChar=cParseString.charAt(xScan);
            fInIdentChars=SequentialSearch(CurrChar);
            if (searcher.search(CurrChar))     // (blmblm)
                if (fBuildingIdent)
                    cIdent+=CurrChar;
                else
                {
                    fBuildingIdent=true;
                    cIdent=""+CurrChar;
                }
            else
                if (fBuildingIdent)
                {
                    fBuildingIdent=false;
                    if (nRepetitions==1)
                        System.out.println(cIdent);
                }
                else
                {}
            xScan++;
        }
        if (fBuildingIdent)
            if (nRepetitions==1)
                System.out.println(cIdent);
    }


    // (blmblm) factor out common code, as suggested by markspace
    static void time(Searcher searcher) {
        long StartTime;
        long EndTime;
        long Duration;

        StartTime=System.nanoTime();
        // (blmblm) gratuitous change (declare loop counter within "for")
        for (int i=1; i<=nRepetitions; i++)
            Parse(searcher);
        EndTime=System.nanoTime();
        Duration=EndTime-StartTime;
        System.out.println(" Duration="+Duration);
    }


    public static void main(String[] args)
    {
        System.out.println("Timing Testing of Character Searching");
        System.out.println();

        // Initialise Set.
        // (blmblm) gratuitous change (declare loop counter within "for")
        for (int i=0; i<IdentChars.length(); i++)
            IdentCharsSet.add(IdentChars.charAt(i));

        // Character Sequential
        System.out.print("Character Sequential Search");
        // (blmblm) use common-code method
        time(new Searcher() {
            public boolean search(char CurrChar) {
                return SequentialSearch(CurrChar);
            }
        });

        // Character Binary Search
        System.out.print("Character Binary Search    ");
        // (blmblm) use common-code method
        time(new Searcher() {
            public boolean search(char CurrChar) {
                return BinarySearch(CurrChar);
            }
        });

        // Character Treeset
        System.out.print("Character Treeset Search   ");
        // (blmblm) use common-code method
        time(new Searcher() {
            public boolean search(char CurrChar) {
                return TreesetSearch(CurrChar);
            }
        });
    }

}

-- 
B. L. Massingill
ObDisclaimer:  I don't speak for my employers; they return the favor.

[toc] | [prev] | [next] | [standalone]


#5621

FromJoshua Cranmer <Pidgeot18@verizon.invalid>
Date2011-06-23 19:36 -0700
Message-ID<iu0t8a$kqc$1@dont-email.me>
In reply to#5610
On 6/23/2011 4:03 PM, Gene Wirchenko wrote:
> Dear Java'ers:
>
>       I have completed my benchmarking.  The code is below.  Note that
> the difference in the bodies between ParseSequentialSearch(),
> ParseBinarySearch(), and ParseTreesetSearch() is but one line.  I
> really would have preferred not having to duplicate the code.
>
>       Oddly, the timings have a LOT of noise in them.  In some runs, a
> sequential search has out-performed a binary search.  Occasionally, a
> sequential search has beaten both a binary search and a Treeset
> search.  The times for sequential searching are only a bit worse than
> for binary searching.  Treeset searching is about 20% faster.  Any
> explanations?

Here is probably the best implementation:

static boolean[] isIdentifierChar;
static String slowSearch;
static void initIdentifierChars(String validChars) {
   isIdentifierChar = new boolean[128];
   for (char c : validChars.toCharArray())
     if (c < 128)
       isIdentifierChar[c] = true;
   slowSearch = validChars;
}

static boolean isValidChar(char c) {
   if (c >= 128)
     return slowSearch.indexOf(c) >= 0;
   return isIdentifieChar[c];
}

If it's really performance critical, you can just make the character 
array the full 64K characters and skip the search, so testing for valid 
identifiers is simply an index lookup.

There are other performance improvements:
1. Use StringBuilder. It's mutable, so it avoids copies (kind of like 
ArrayList). Heck, that's what your code is doing, it just keeps copying 
back and forth between strings.

2. It's probably better to throw out StringBuilder and use token extents 
(i.e., from index 5 to 9 is this identifier). It saves copying and can 
allow for better error messages in parsers by being able to pinpoint 
line/column numbers accurately.

But yeah, I would have coded my benchmark like that. Since you seem to 
be concerned with microoptimization here, anything which looks different 
from what the real parser implementation would show up as having impact 
in timing numbers.

Finally, I might add, if you're writing a full parser, it might be 
better to just use an existing Java lexer rather than rolling your own 
unless you have a *very* good reason not to.

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

[toc] | [prev] | [next] | [standalone]


#5652

FromGene Wirchenko <genew@ocis.net>
Date2011-06-24 11:50 -0700
Message-ID<dsm9071kpkj0s4uabgupfmg49evfmhvs6h@4ax.com>
In reply to#5621
On Thu, 23 Jun 2011 19:36:53 -0700, Joshua Cranmer
<Pidgeot18@verizon.invalid> wrote:

>On 6/23/2011 4:03 PM, Gene Wirchenko wrote:
>> Dear Java'ers:
>>
>>       I have completed my benchmarking.  The code is below.  Note that
>> the difference in the bodies between ParseSequentialSearch(),
>> ParseBinarySearch(), and ParseTreesetSearch() is but one line.  I
>> really would have preferred not having to duplicate the code.
>>
>>       Oddly, the timings have a LOT of noise in them.  In some runs, a
>> sequential search has out-performed a binary search.  Occasionally, a
>> sequential search has beaten both a binary search and a Treeset
>> search.  The times for sequential searching are only a bit worse than
>> for binary searching.  Treeset searching is about 20% faster.  Any
>> explanations?
>
>Here is probably the best implementation:

     Nope.  I want a configurable character set for identifiers

[snip]

>There are other performance improvements:
>1. Use StringBuilder. It's mutable, so it avoids copies (kind of like 
>ArrayList). Heck, that's what your code is doing, it just keeps copying 
>back and forth between strings.

     Noted.

>2. It's probably better to throw out StringBuilder and use token extents 
>(i.e., from index 5 to 9 is this identifier). It saves copying and can 
>allow for better error messages in parsers by being able to pinpoint 
>line/column numbers accurately.

     I plan to for the real thing.  I have other changes as well.

>But yeah, I would have coded my benchmark like that. Since you seem to 
>be concerned with microoptimization here, anything which looks different 
>from what the real parser implementation would show up as having impact 
>in timing numbers.

     Nah, I just do not have a sense of how fast various Java things
are.  Benchmark to find out.

>Finally, I might add, if you're writing a full parser, it might be 
>better to just use an existing Java lexer rather than rolling your own 
>unless you have a *very* good reason not to.

     I am writing a *simple* parser.  It is not for grovelling over
Java code.  It is for a preprocessor for SQL Server for better code
management.  I mean for it to be fairly language-agnostic.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5657

FromJeff Higgins <jeff@invalid.invalid>
Date2011-06-24 17:25 -0400
Message-ID<iu2v22$6nh$1@dont-email.me>
In reply to#5652
On 06/24/2011 02:50 PM, Gene Wirchenko wrote:
> On Thu, 23 Jun 2011 19:36:53 -0700, Joshua Cranmer

>> Finally, I might add, if you're writing a full parser, it might be
>> better to just use an existing Java lexer rather than rolling your own
>> unless you have a *very* good reason not to.
>
>       I am writing a *simple* parser.  It is not for grovelling over
> Java code.  It is for a preprocessor for SQL Server for better code
> management.  I mean for it to be fairly language-agnostic.
>
What means simple? JavaCC is the parser generator that I'm most familiar 
with. <http://javacc.java.net/>

[toc] | [prev] | [next] | [standalone]


#5701

FromGene Wirchenko <genew@ocis.net>
Date2011-06-26 20:42 -0700
Message-ID<3uuf071k5c0b32cdlv31s7p1u6cjn3t11j@4ax.com>
In reply to#5657
On Fri, 24 Jun 2011 17:25:01 -0400, Jeff Higgins
<jeff@invalid.invalid> wrote:

>On 06/24/2011 02:50 PM, Gene Wirchenko wrote:
>> On Thu, 23 Jun 2011 19:36:53 -0700, Joshua Cranmer

[snip]

>>       I am writing a *simple* parser.  It is not for grovelling over
>> Java code.  It is for a preprocessor for SQL Server for better code
>> management.  I mean for it to be fairly language-agnostic.
>>
>What means simple? JavaCC is the parser generator that I'm most familiar 
>with. <http://javacc.java.net/>

     There are preprocessor commands.  For them, the first character
of the line is "$".  All of the other lines are text to be processed.
There is one level of string substitution.

     Think simple version of the C preprocessor.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5702

Frommarkspace <-@.>
Date2011-06-26 23:27 -0700
Message-ID<iu97sr$tko$1@dont-email.me>
In reply to#5701
On 6/26/2011 8:42 PM, Gene Wirchenko wrote:

> On Fri, 24 Jun 2011 17:25:01 -0400, Jeff Higgins
>> What means simple? JavaCC is the parser generator that I'm most familiar
>> with.<http://javacc.java.net/>

>       There are preprocessor commands.  For them, the first character
> of the line is "$".  All of the other lines are text to be processed.
> There is one level of string substitution.


A parser generator makes parsers for you.  You give it a syntax (like 
"starts with $") and it makes the parser.  Generally very efficient as 
it will do optimizations in the code that are hard to find.

[toc] | [prev] | [next] | [standalone]


#5704

FromJoshua Cranmer <Pidgeot18@verizon.invalid>
Date2011-06-27 03:04 -0400
Message-ID<iu9a1b$8h4$1@dont-email.me>
In reply to#5701
On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>       Think simple version of the C preprocessor.

Then why not use the C preprocessor?

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

[toc] | [prev] | [next] | [standalone]


#5710

FromGene Wirchenko <genew@ocis.net>
Date2011-06-27 13:12 -0700
Message-ID<71ph07l246l93uf4umn5tjgp6dtfgnr4a9@4ax.com>
In reply to#5704
On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
<Pidgeot18@verizon.invalid> wrote:

>On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>       Think simple version of the C preprocessor.
>
>Then why not use the C preprocessor?

     I could not find one that would run standalone on my system.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#5711

FromJoshua Cranmer <Pidgeot18@verizon.invalid>
Date2011-06-27 13:36 -0700
Message-ID<iuapk0$dtd$1@dont-email.me>
In reply to#5710
On 6/27/2011 1:12 PM, Gene Wirchenko wrote:
> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
> <Pidgeot18@verizon.invalid>  wrote:
>
>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>>        Think simple version of the C preprocessor.
>>
>> Then why not use the C preprocessor?
>
>       I could not find one that would run standalone on my system.

Then if I may make a recommendation, try using mcpp.
-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

[toc] | [prev] | [next] | [standalone]


#6386

FromArne Vajhøj <arne@vajhoej.dk>
Date2011-07-21 20:43 -0400
Message-ID<4e28c7a0$0$308$14726298@news.sunsite.dk>
In reply to#5710
On 6/27/2011 4:12 PM, Gene Wirchenko wrote:
> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
> <Pidgeot18@verizon.invalid>  wrote:
>
>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>>        Think simple version of the C preprocessor.
>>
>> Then why not use the C preprocessor?
>
>       I could not find one that would run standalone on my system.

Almost all C compiler has a way to do only preprocessing.

GCC, MS, DEC/CPQ/HP etc. has.

Arne

[toc] | [prev] | [next] | [standalone]


#6412

FromGene Wirchenko <genew@ocis.net>
Date2011-07-22 12:35 -0700
Message-ID<c5kj27pehob8m91ilr27gq4ndg853j3h56@4ax.com>
In reply to#6386
On Thu, 21 Jul 2011 20:43:10 -0400, Arne Vajhøj <arne@vajhoej.dk>
wrote:

>On 6/27/2011 4:12 PM, Gene Wirchenko wrote:
>> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
>> <Pidgeot18@verizon.invalid>  wrote:
>>
>>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>>>        Think simple version of the C preprocessor.
>>>
>>> Then why not use the C preprocessor?
>>
>>       I could not find one that would run standalone on my system.
>
>Almost all C compiler has a way to do only preprocessing.
>
>GCC, MS, DEC/CPQ/HP etc. has.

     I did not want a C compiler.  I simply wanted a preprocessor.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#6413

FromPatricia Shanahan <pats@acm.org>
Date2011-07-22 13:09 -0700
Message-ID<fJqdnRBtDbBwRbTTnZ2dnUVZ_rudnZ2d@earthlink.com>
In reply to#6412
On 7/22/2011 12:35 PM, Gene Wirchenko wrote:
> On Thu, 21 Jul 2011 20:43:10 -0400, Arne Vajhøj<arne@vajhoej.dk>
> wrote:
>
>> On 6/27/2011 4:12 PM, Gene Wirchenko wrote:
>>> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
>>> <Pidgeot18@verizon.invalid>   wrote:
>>>
>>>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>>>>         Think simple version of the C preprocessor.
>>>>
>>>> Then why not use the C preprocessor?
>>>
>>>        I could not find one that would run standalone on my system.
>>
>> Almost all C compiler has a way to do only preprocessing.
>>
>> GCC, MS, DEC/CPQ/HP etc. has.
>
>       I did not want a C compiler.  I simply wanted a preprocessor.

The easiest and simplest way to get the C pre-processing function is
often to install a C compiler and invoke it with parameters set to
preprocess only.

Patricia

[toc] | [prev] | [next] | [standalone]


#6417

Fromlewbloch <lewbloch@gmail.com>
Date2011-07-22 13:35 -0700
Message-ID<9292cedf-4844-4192-ae7e-e64f41913ffb@t8g2000prm.googlegroups.com>
In reply to#6412
On Jul 22, 12:35 pm, Gene Wirchenko <ge...@ocis.net> wrote:
> On Thu, 21 Jul 2011 20:43:10 -0400, Arne Vajhøj <a...@vajhoej.dk>
> wrote:
>
> >On 6/27/2011 4:12 PM, Gene Wirchenko wrote:
> >> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
> >> <Pidgeo...@verizon.invalid>  wrote:
>
> >>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
> >>>>        Think simple version of the C preprocessor.
>
> >>> Then why not use the C preprocessor?
>
> >>       I could not find one that would run standalone on my system.
>
> >Almost all C compiler has a way to do only preprocessing.
>
> >GCC, MS, DEC/CPQ/HP etc. has.
>
>      I did not want a C compiler.  I simply wanted a preprocessor.

Awwwww.  You get a free C compiler that gives you the preprocessor you
want, and you're complaining that it gives you more than you want?
Wow.  That's pretty petulant.

--
Lew

[toc] | [prev] | [next] | [standalone]


#6418

FromArne Vajhøj <arne@vajhoej.dk>
Date2011-07-22 16:53 -0400
Message-ID<4e29e35b$0$308$14726298@news.sunsite.dk>
In reply to#6412
On 7/22/2011 3:35 PM, Gene Wirchenko wrote:
> On Thu, 21 Jul 2011 20:43:10 -0400, Arne Vajhøj<arne@vajhoej.dk>
> wrote:
>
>> On 6/27/2011 4:12 PM, Gene Wirchenko wrote:
>>> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
>>> <Pidgeot18@verizon.invalid>   wrote:
>>>
>>>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>>>>         Think simple version of the C preprocessor.
>>>>
>>>> Then why not use the C preprocessor?
>>>
>>>        I could not find one that would run standalone on my system.
>>
>> Almost all C compiler has a way to do only preprocessing.
>>
>> GCC, MS, DEC/CPQ/HP etc. has.
>
>       I did not want a C compiler.  I simply wanted a preprocessor.

If the C compilers preprocessor can be invoked separately, then
why not use it.

Arne

[toc] | [prev] | [next] | [standalone]


#6446

FromMartin Gregorie <martin@address-in-sig.invalid>
Date2011-07-23 13:19 +0000
Message-ID<j0ehp2$l3l$1@localhost.localdomain>
In reply to#6412
On Fri, 22 Jul 2011 12:35:00 -0700, Gene Wirchenko wrote:

> On Thu, 21 Jul 2011 20:43:10 -0400, Arne Vajhøj <arne@vajhoej.dk> wrote:
> 
>>On 6/27/2011 4:12 PM, Gene Wirchenko wrote:
>>> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
>>> <Pidgeot18@verizon.invalid>  wrote:
>>>
>>>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>>>>        Think simple version of the C preprocessor.
>>>>
>>>> Then why not use the C preprocessor?
>>>
>>>       I could not find one that would run standalone on my system.
>>
>>Almost all C compiler has a way to do only preprocessing.
>>
>>GCC, MS, DEC/CPQ/HP etc. has.
> 
>      I did not want a C compiler.  I simply wanted a preprocessor.
>
The last C compilers I remember that had separate preprocessors were K&R, 
so were very old. In these, cc was effectively a shell that invoked the 
preprocessor, the C --> assembler translator, the assembler and the 
linker in turn. Actually, I'm still using one - the standard OS/9 v2.4 C 
compiler, which dates from 1992 and runs on 68xxx hardware.

I don't remember any ANSI C compilers I've used being structured this 
way: certainly I've not seen any version of the GNU compiler or its 
derivatives that aren't a monolithic chunk that includes all compilation 
stages except the linker. AFAICR this also applied to the Borland 
compilers.

So, if that's really what you want, go and find a old K&R compiler or its 
source.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

[toc] | [prev] | [next] | [standalone]


#6449

FromArne Vajhøj <arne@vajhoej.dk>
Date2011-07-23 11:19 -0400
Message-ID<4e2ae67d$0$303$14726298@news.sunsite.dk>
In reply to#6446
On 7/23/2011 9:19 AM, Martin Gregorie wrote:
> On Fri, 22 Jul 2011 12:35:00 -0700, Gene Wirchenko wrote:
>
>> On Thu, 21 Jul 2011 20:43:10 -0400, Arne Vajhøj<arne@vajhoej.dk>  wrote:
>>
>>> On 6/27/2011 4:12 PM, Gene Wirchenko wrote:
>>>> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
>>>> <Pidgeot18@verizon.invalid>   wrote:
>>>>
>>>>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>>>>>         Think simple version of the C preprocessor.
>>>>>
>>>>> Then why not use the C preprocessor?
>>>>
>>>>        I could not find one that would run standalone on my system.
>>>
>>> Almost all C compiler has a way to do only preprocessing.
>>>
>>> GCC, MS, DEC/CPQ/HP etc. has.
>>
>>       I did not want a C compiler.  I simply wanted a preprocessor.
>>
> The last C compilers I remember that had separate preprocessors were K&R,
> so were very old. In these, cc was effectively a shell that invoked the
> preprocessor, the C -->  assembler translator, the assembler and the
> linker in turn. Actually, I'm still using one - the standard OS/9 v2.4 C
> compiler, which dates from 1992 and runs on 68xxx hardware.
>
> I don't remember any ANSI C compilers I've used being structured this
> way: certainly I've not seen any version of the GNU compiler or its
> derivatives that aren't a monolithic chunk that includes all compilation
> stages except the linker. AFAICR this also applied to the Borland
> compilers.
>
> So, if that's really what you want, go and find a old K&R compiler or its
> source.

GCC still has a separate executable for preprocessing!

The driver gcc or g++ calls cpp, cc1 or cc1plus, as and ld.

Arne

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.java.programmer


csiph-web