1. Parser

I have recently wrote a parser which reads in a file and turns it into a 
stream of tokens.

A file containing:

     hello world 123 456 'comment
    'c' "hello"

would return

   {{ID, "hello", 1},         -- {Token description (constant), token 
string, line number}
    {ID, "world", 1},
    {NUM, "123", 1},
    {NUM, "456", 1},
    {CHR, 'c', 2},
    {STR, "hello", 2}}

The characters for comments, chars, strings etc. can be set.  However, they 
can only be single chars.

Does anyone have any other ideas for it before I finish it off and upload it 
to the archive?

Thanks

_________________

StewartML

new topic     » topic index » view message » categorize

2. Re: Parser

how about using ATOM and INTEGER instead of NUM? and maybe parse sequence
brackets "{}" as SEQ_START and SEQ_END and commas ',' as COMMA or
SEQ_SEP(ARATOR). this would make parsing sequences from a file much easier.
it would also allow us to catch errors such as a never ending sequence or a
comma and end bracket right next to each other.

----- Original Message -----
From: "Stewart MacKenzie-Leigh" <stewartml89 at msn.com>
To: <EUforum at topica.com>
Subject: Parser


>
>
> I have recently wrote a parser which reads in a file and turns it into a
> stream of tokens.
>
> A file containing:
>
>      hello world 123 456 'comment
>     'c' "hello"
>
> would return
>
>    {{ID, "hello", 1},         -- {Token description (constant), token
> string, line number}
>     {ID, "world", 1},
>     {NUM, "123", 1},
>     {NUM, "456", 1},
>     {CHR, 'c', 2},
>     {STR, "hello", 2}}
>
> The characters for comments, chars, strings etc. can be set.  However,
they
> can only be single chars.
>
> Does anyone have any other ideas for it before I finish it off and upload
it
> to the archive?
>
> Thanks
>
> _________________
>
> StewartML
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Parser

As long as your string type can handle spaces...

Either in linux shell fashion:  Hello\ World!

or "Hello World"

------------------------------------------------------------------------
magnae clunes mihi placent, nec possum de hac re mentiri.


>From: Stewart MacKenzie-Leigh <stewartml89 at msn.com>
>Reply-To: EUforum at topica.com
>To: EUforum at topica.com
>Subject: Parser
>Date: Fri, 21 Nov 2003 17:23:55 +0000
>
>
>I have recently wrote a parser which reads in a file and turns it into a 
>stream of tokens.
>
>A file containing:
>
>     hello world 123 456 'comment
>    'c' "hello"
>
>would return
>
>   {{ID, "hello", 1},         -- {Token description (constant), token 
>string, line number}
>    {ID, "world", 1},
>    {NUM, "123", 1},
>    {NUM, "456", 1},
>    {CHR, 'c', 2},
>    {STR, "hello", 2}}
>
>The characters for comments, chars, strings etc. can be set.  However, they 
>can only be single chars.
>
>Does anyone have any other ideas for it before I finish it off and upload 
>it to the archive?
>
>Thanks
>
>_________________
>
>StewartML
>
>
>
>TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu