Parser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Cunningham

    #1

    Parser

    In comp.programmin g I asked for advice for writing a parser. The code
    someone showed me wouldn't compile. I don't know what's wrong. I just want
    to write the simpliest of parsers.

    int parser(FILE *in,FILE *out);

    int main(void){
    parser(stdin,st dout);
    return0;}

    Won't compile. My guess is maybe this should be written

    parser(&stdin,& stdout);

    But that's my opinion.

    Bill



  • Joona I Palaste

    #2
    Re: Parser

    Bill Cunningham <nospam@nspam.n et> scribbled the following:[color=blue]
    > In comp.programmin g I asked for advice for writing a parser. The code
    > someone showed me wouldn't compile. I don't know what's wrong. I just want
    > to write the simpliest of parsers.[/color]
    [color=blue]
    > int parser(FILE *in,FILE *out);[/color]
    [color=blue]
    > int main(void){
    > parser(stdin,st dout);
    > return0;}[/color]
    [color=blue]
    > Won't compile. My guess is maybe this should be written[/color]
    [color=blue]
    > parser(&stdin,& stdout);[/color]
    [color=blue]
    > But that's my opinion.[/color]

    Your opinion is wrong. stdin and stdout are of type FILE *, not of
    type FILE. The reason it won't compile is the same as in your
    previous post - the function parser() isn't defined anywhere, just
    declared.

    --
    /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "Remember: There are only three kinds of people - those who can count and those
    who can't."
    - Vampyra

    Comment

    • Mike Wahler

      #3
      Re: Parser


      "Joona I Palaste" <palaste@cc.hel sinki.fi> wrote in message
      news:c5e7h7$ln4 $1@oravannahka. helsinki.fi...[color=blue]
      > Bill Cunningham <nospam@nspam.n et> scribbled the following:[color=green]
      > > In comp.programmin g I asked for advice for writing a parser. The[/color][/color]
      code[color=blue][color=green]
      > > someone showed me wouldn't compile. I don't know what's wrong. I just[/color][/color]
      want[color=blue][color=green]
      > > to write the simpliest of parsers.[/color]
      >[color=green]
      > > int parser(FILE *in,FILE *out);[/color]
      >[color=green]
      > > int main(void){
      > > parser(stdin,st dout);
      > > return0;}[/color]
      >[color=green]
      > > Won't compile. My guess is maybe this should be written[/color]
      >[color=green]
      > > parser(&stdin,& stdout);[/color]
      >[color=green]
      > > But that's my opinion.[/color]
      >
      > Your opinion is wrong. stdin and stdout are of type FILE *, not of
      > type FILE. The reason it won't compile is the same as in your
      > previous post - the function parser() isn't defined anywhere, just
      > declared.[/color]

      That won't stop a compile (but the missing #include <stdio.h>
      as well as the syntax error in the 'return' statement will.)
      The missing definition will prevent successful linking
      though.

      -Mike


      Comment

      • Martin Ambuhl

        #4
        Re: Parser

        Bill Cunningham wrote:
        [color=blue]
        > In comp.programmin g I asked for advice for writing a parser. The code
        > someone showed me wouldn't compile. I don't know what's wrong. I just want
        > to write the simpliest of parsers.
        >
        > int parser(FILE *in,FILE *out);
        >
        > int main(void){
        > parser(stdin,st dout);
        > return0;}
        >
        > Won't compile. My guess is maybe this should be written
        >
        > parser(&stdin,& stdout);
        >
        > But that's my opinion.[/color]

        And it's a bad one. The following should compile without diagnostics:

        #include <stdio.h>

        int parser(FILE * in, FILE * out);

        int main(void)
        {
        parser(stdin, stdout);
        return 0;
        }

        int parser(FILE * in, FILE * out)
        {
        (void) in; /* noops here to quiet */
        (void) out; /* 'unused parameter' warnings. */
        return 0;
        }


        Comment

        • Bill Cunningham

          #5
          Re: Parser

          [color=blue]
          > int parser(FILE * in, FILE * out)
          > {
          > (void) in; /* noops here to quiet */
          > (void) out; /* 'unused parameter' warnings. */
          > return 0;
          > }
          >[/color]
          What do the voids in parenthesis mean? Are they casts? This NG always
          makes me feel dumb.

          Bill


          Comment

          • Julien Oster

            #6
            Re: Parser

            "Bill Cunningham" <nospam@nspam.n et> writes:

            Hello Bill,
            [color=blue][color=green]
            >> int parser(FILE * in, FILE * out)
            >> {
            >> (void) in; /* noops here to quiet */
            >> (void) out; /* 'unused parameter' warnings. */
            >> return 0;
            >> }[/color][/color]
            [color=blue]
            > What do the voids in parenthesis mean? Are they casts? This NG always
            > makes me feel dumb.[/color]

            Yes! It's a cast. A cast to void seems pretty useless, especially in
            this case where the casted value isn't even used, but it's actually
            quite useful here to remove the warning.

            Julien

            Comment

            Working...