View Single Post
Join Date: Jun 2005
Posts: 2,003
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 137
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: New Parser Generator

 
0
  #2
Dec 14th, 2008
    void getline(char* line)  
    {   int n=0;
        while((line[n]=getchar()) != '\n')
        { n++; }
        line[n]=0;
    }

You shouldn't use broken code examples.

parse ws
[   anychar[] Wo
    anyindex an
->  Wo   Wo[ Wo[an]==' ' || Wo[an]=='\t' || Wo[an]=='\n' ]
    [ return true; ]
]

This is _extremely_ verbose for something that just parses whitespace. I'm pretty sure that's simpler to do in other parser generators, and more readable. For example, with ANTLR (and I might be buggy here, I haven't seen ANTLR myself except on IRC channels), you would just see something like
WS : (' '|'\t'|'\f'|'\n'|'\r')+ { $channel=HIDDEN; };

For a parser combinator library like Parsec, it would just be
ws = skipMany1 (satisfy isSpace)
Last edited by Rashakil Fol; Dec 14th, 2008 at 7:32 pm.
Reply With Quote