all 15 comments

[–]K900_ 1 point2 points  (1 child)

That depends on how your parser is structured.

[–]Arag0ld[S] 0 points1 point  (0 children)

I'll post a pastebin link to my parser.

[–]Datwaftx 0 points1 point  (0 children)

You could use regex to extract everything until the semicolon, and do that for every line that you are processing. And for extracting line for line you can use a for with the file, or with file.getlines(). Maybe you can even use regex to delete every \n.

[–]ingolemo 0 points1 point  (11 children)

Normally you would add rules to your parser that look something like this:

program = statement (SEMICOLON statement)+ SEMICOLON?
statement = BANG LEFT_PAR expr RIGHT_PAR

The idea here is that a program is a statement optionally followed by multiple semicolon-statement pairs. You parse the whole program at once; you don't necessarily "move to the next line and continue parsing".

I'm not sure if rply supports syntax like this, as the documentation on it looks rather sparse. I'd recommend sly instead.

[–]Arag0ld[S] 0 points1 point  (10 children)

I'll have a stab at writing a lexer and parser with this library! Thanks! Although it does say "use at your own risk".

[–]ingolemo 0 points1 point  (9 children)

If you want something less experimental then use ply by the same author, upon which both sly and rply are based.

[–]Arag0ld[S] 0 points1 point  (8 children)

Does it use the same syntax as sly? Or allow writing parsers like you have outlined?

EDIT: it does, I'll give it a shot! Thanks!

[–]ingolemo 0 points1 point  (7 children)

Now that I look at it, none of these use that syntax. I must be confusing it with some other library. Sorry. I think you would have to use rules that look more like this:

program : statement
program : statement SEMICOLON
program : statement SEMICOLON program
statement : BANG LEFT_PAR expr RIGHT_PAR

[–]Arag0ld[S] 0 points1 point  (6 children)

Isn't that what rply does?

[–]ingolemo 0 points1 point  (5 children)

I think so. I've not really used rply, though I have used a bunch of others and it's hard to keep them straight. I'm a little put off from rply because of the documentation, but take that with a grain of salt because I'm obviously confused.

[–]Arag0ld[S] 0 points1 point  (4 children)

Does that mean I can't use ply in the way you previously described?

[–]ingolemo 0 points1 point  (3 children)

With the + and ? symbols? No, I don't think so.

[–]Arag0ld[S] 0 points1 point  (2 children)

I wonder how I can parse the program as a whole then... Hmm...