Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Idiots don't know how to parse...

Name: Cudder !cXCudderUE 2015-11-13 8:45

http://stackoverflow.com/questions/28256/equation-expression-parser-with-precedence

WTF? The accepted answer is from someone who thinks recursive descent is "hard" and a ridiculously bloated parser-generator is "easy"? Pure bisonshit! Almost every real (and toy) compiler uses some variant of recursive-descent. Even GCC, which would probably be the biggest user of Bison, moved to recursive-descent years ago.

These aren't even programmers, these are Java-sipping codemonkeys who know next to nothing about how anything really works and can only parrow "reinventing the wheel" and other "enterprise best practices" bullshit.

Name: Cudder !cXCudderUE 2015-11-13 8:46

parrow. v. to scream repetitively with the force of a runaway wheelbarrow.

Name: Anonymous 2015-11-13 9:14

fuck off namefag

Name: Anonymous 2015-11-13 10:36

That fucking answer.
People here have offered much sound advice. My only warning against skipping the parsing tools or just using the Shunting Yard algorithm or a hand rolled recursive decent parser is that little toy languages1 may someday turn into big actual languages with functions (sin, cos, log) and variables, conditions and for loops.
Well, my house might one day need to be a skyscraper, so I bought half a million bricks that I leave lying around just in case. Reminds me of that "you don't want to buy a hammer, you want to buy a hammer factory factory factory" parable about frameworks.

But ShitOverflow always does this. There is always some cunt who doesn't want to answer the question, but wants you to upgrade to Seeples17 and use aa prealpha development version of Boost when all the asker wanted to do was balance a tree or some shit. It gets accepted, becomes the first google result, and all other vaguely related questions get directed to it, leaving the real question unanswered, or hidden at best.

Name: /lounge/ 2015-11-13 12:44

/lounge/

Name: Anonymous 2015-11-13 13:25

I take offense to this Cudder, please mind the ableism next time (◕‿◕✿)

Name: Anonymous 2015-11-13 14:28

This is the sort of shit that comes from relying on other people as a source of knowledge.

Name: Anonymous 2015-11-13 16:37

>>3
Fuck off, imageboarder moron. Being threatened by a name that is seen like once a week is something only a meme loving fuck like you would do. Get the fuck back to /g/ already.

Name: Anonymous 2015-11-13 16:46

I think Cudder is a pretty cool guy. Eh talks about shit and doesn't afraid of not actually knowing what he's talking about.

Name: Anonymous 2015-11-13 23:04

>>9
Wow, nice classic meme, ``newfag''!

Name: Anonymous 2015-11-14 0:58

What programming language is this thread about?
It seems no-one is talking about programming in this thread?
I thought this was a programming discussion board?

Name: Anonymous 2015-11-14 8:01

>>10
Please stylize your exclamation

Name: Cudder !cXCudderUE 2015-11-14 16:58

>>11
Bison.

>>4
Ironically, even the "big actual languages" don't use parser-generators, because recursive descent is so damn simple and works really, really well. Even Java, a language where you'd probably expect them to have a ParserGeneratorGeneratorGenerator more than anything else, uses recursive-descent. (Full source code for Java's parser here: http://www.docjar.com/html/api/com/sun/tools/javac/parser/JavacParser.java.html - less than 3k lines, it's actually quite good.)

I think you're talking about this article:
http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12&

Name: Anonymous 2015-11-14 17:41

bad thread, stop namefagging

Name: Anonymous 2015-11-14 21:45

>>14
Take a chill sesh

Name: Anonymous 2015-11-14 23:24

>>14
bad poster, stop imageboarding

Name: Anonymous 2015-11-15 0:43

>>16
that's just a non sequiter

Name: Anonymous 2015-11-15 16:47

>>17
Your argument is at >>8.

You're not fine with just throwing "namefag" imageboard memes? Because "oh but that's a ad homiprojection fallacy" is what a Reddit nigger would do.

Name: Anonymous 2015-11-15 17:45

>>18
I killed a reddit nigger with my baguette. score one for the good guys

Name: Cudder !cXCudderUE 2015-11-30 6:07

It's as easy as this:

AST *expr(int level) {
AST *v = atom();
while(tprec >= level) {
int op = token, prec = tprec;
toke();
v = AST_new_binop(op, v, expr(prec + 1));
}
return v;
}


Just add a tokeniser, AST-creator, atom() (unary handler), and operator table, and you'll have a perfectly working, tiny and easily extensible expression parser. I've written a C expression evaluator with this at its core, supporting all the standard C operators and their dozen levels of precedence. I wasn't even aiming for small size, and yet the whole thing is < 300 LoC including comments. The binary is a little below 4KB but that's probably just due to C's inherent bloat. Maybe I'll rewrite in Asm and make it 1/4 of that, because that core function itself should be a few dozen bytes at most.

Messing around with YUCC and Bishit will waste more of your time.

Next up, a full C parser...

Name: Anonymous 2015-11-30 6:20

toke() every day

Name: Cudder !cXCudderUE 2015-11-30 8:07

>>21
I was expecting that.

Name: Anonymous 2015-11-30 8:40

Name: Anonymous 2015-11-30 12:10

When you don't understand something simple obfuscate it in order to seem smart.

Name: Anonymous 2015-11-30 16:04

When you don't understand something complex, write something featureless and claim that you're smarter.

Name: Anonymous 2015-12-01 1:28

When you don't understand something, look it up on stackoverflow to seem ENTERPRISE.

Name: Anonymous 2015-12-01 6:15

>>24
Haskell.
>>25
Go.
>>26
Python.

Name: Cudder !cXCudderUE 2015-12-01 9:27

>>23
I was expecting a PhD thesis, instead I got a crappy Chinese version of the Dragon Book? Most of that 30MB is useless though, as all you need is a FSM tokeniser and recursive-descent parser. The rest is academic wank.

Proof? The grammar of C++ is known to be Turing-complete. According to the academics, it's Chomsky type 0. Yet working C++ compilers obviously exist, and almost every practical one uses a recursive-descent parser.

Don't even get me started on the "dangling else problem", which is NOT AT ALL A PROBLEM but an artificial one created by the circlejerking academics...

if(token == TOKE_IF) {
toke();
expect('(');
expr();
expect(')');
stmt();
/* THIS IS THE SOLUTION - FOUR LINES OF CODE */
if(token == TOKE_ELSE) {
toke();
stmt();
}
}


Check for an 'else' after 'if', if there is one then obviously consume it and the associated statement. Nothing could be simpler. Why do those idiots think it's hard and have to spend innumerable amounts of time convincing others that it's a problem? It's not. It only becomes one if you want to associate elses with outermost ifs, which no programming language I know does because it makes no sense.

Name: Anonymous 2015-12-01 10:15

Yep. well, it's only a page or so of chinese..
Chomsky-Schützenberger hierarchy type 0...

A recursively enumerable language is a formal language for which there exists a Turing machine (or other computable function) that will halt and accept when presented with any string in the language as input but may either halt and reject or loop forever when presented with a string not in the language. Contrast this to recursive languages, which require that the Turing machine halts in all cases.

Sounds like it is a `theoretical' problem

Name: Anonymous 2015-12-01 19:41

>>28,20
It makes me think parser generators only exist to bridge some sort of mental gap between BNF (from compilers 101, naturally) and actual code. Like other algorithms, do it in C and just follow the steps you would follow to consume a language.

It's all code, guys. Keep it simple.

Name: Anonymous 2015-12-02 4:59

>>1
go away. ur like all the losers who hang out on ##programming on irc.freenode.net, bitching and whining all day about which programming language is the best. ur too stupid to write anything useful so u bitch and whine on /prog/ about crap that doesn't matter

fuk off and go back to your porn

Name: Anonymous 2015-12-02 9:41

check 'em

Name: Anonymous 2015-12-02 10:27

parse these doubles

Name: Anonymous 2015-12-02 11:04

>>31
this is funny because I've been in there and holy shit these people do not have a lot going on upstairs. Especially ams, that ...thing makes me very sad for it.

Name: Anonymous 2015-12-02 11:08

Simple custom parsers are generally shit at error reporting. This is one reason parsers are driven by spec instead of hardcoded.

Name: Anonymous 2015-12-02 14:58

>>35
great point. error reporting is a really difficult problem

Name: Anonymous 2015-12-02 20:48

>>35
Counterpoint: parsers have to be custom to be able to encode human-useful information on error.
Generated parse error on function(arg1 arg2): ``error at line 1 column 23, `arg2': expected `,' or `)'''
Custom parse error: ``I couldn't understand line 1: Function call arguments need to be separated by commas; try `function(arg1, arg2)' instead (specifically fell over at column 23)''

Name: Anonymous 2015-12-02 23:28

>>37 has never written a parser. I can tell from having written some parsers myself and from the sheer retardation of her comment.

Come sit on my knee and listen, >>37-chan: you see, the problem when you're parsing a list of function arguments and suddenly encounter "3 + ," is that you encounter the comma when balls deep in the "trying to parse a multiplicand", and at that point you can't say anything more helpful than "I expected a multiplicand or an "(", but got a comma, wtf".

And that's not helpful, my dear >>37. That's not helpful at all, there's not a multiplication operator in sight even, why do you complain about multiplicands? Why are you not helping?

Because to make a helpful error message you got to collect all possibilities from the entire stack trace that got you to that point and weigh them by importance, so that the part where the "+" was expecting something on the right side is more important than what happened deep down below, but also more important than what the "parse a function" expected from that entire list of arguments, or even more so than "parse a program".

And the only way you can do it, my sweet >>37, is by reifying your formal grammar and making a generic parser that can do that figuring out what was expected when a grammar rule failed to apply, and which grammar rule really failed to apply.

*tousles >>37-chan's hair* go play with your legos little one, you are not ready for this.

Name: Anonymous 2015-12-03 0:11

Wtf why does >>38 never talk to me that way? I hate you >>37, I deserved that treatment more than you.

Name: Anonymous 2015-12-03 2:08

Muh dik iz big

Name: Anonymous 2015-12-03 2:44

>>37
I couldn't understand line 1:
What the fuck do you think this is, r/programming?

Name: Anonymous 2015-12-03 8:28

>>37
I agree with >>38, but >>38-sama forgot to also mention that you're a shit-fucking cuntstain who should strangle yourself with your dad's pubes and never touch a keyboard again.

Name: Cudder !cXCudderUE 2015-12-03 9:23

>>38
Bullshit. Generated parsers have horrible errorhandling, so much that you often need to add additional rules just to do it. Nothing quite as simple as RD where you just put the code in the right place. This was one of the main reasons GCC moved to RD from a Bison parser.

But in any case, "X was unexpected here" is usually enough of a clue to the programmer what's wrong.

Name: Anonymous 2015-12-03 13:13

>>43
fuck off namefag

Name: Anonymous 2015-12-03 16:53

/prog/ challenge: write an expression parser with precedence

Name: Anonymous 2015-12-03 17:14

>>40
Thanks

Name: Anonymous 2015-12-03 20:35

>>38
The only tractable way to generate meaningful error messages giving suggested fixes in a non-accusatory tone (I EXPECTED A CLOSING BRACE HERE YOU FUCKING MEATBAG) is to special-case them. By definition you cannot do that generically.
By the way, it makes me hot when you do that.

>>41
A programming languages is a UI too. Treat your users nicely. It's no longer 1989. There's room in your program for a little internal documentation.

Name: Anonymous 2015-12-03 21:11

I was thinking about these pages, but turns out they're about semantic errors rather than syntactic errors. It's still worth caring about this stuff though.
http://elm-lang.org/blog/compiler-errors-for-humans
http://elm-lang.org/blog/compilers-as-assistants

Name: Anonymous 2015-12-04 11:08

>>47
The only tractable way to generate meaningful error messages giving suggested fixes in a non-accusatory tone (I EXPECTED A CLOSING BRACE HERE YOU FUCKING MEATBAG) is to special-case them. By definition you cannot do that generically.

At the very least you can collect _all_ things you could have expected, annotated with human-readable production names and sorted by priority (for example the rule that just consumed a terminal like "+" should be given priority).

Of course you could be doing that in your recursive descent parser too, in an ad-hoc, verbose, and awkward manner. I'm not sure I'd describe it as "tractable".

Name: new meme 2015-12-04 18:59

>>49
Fuck all the way off.

Name: Anonymous 2015-12-05 11:58

>>49
you could be doing that in your recursive descent parser too, in an ad-hoc, verbose, and awkward manner.
You mean with a single extra parameter context[] for each rule? Yeah, so awkward.

Name: Anonymous 2015-12-05 22:16

>>51
That would make compilation SLOW AS BALLS though. Not that it's a bad thing, I'm all for it, though tt might not be feasible in those cases where it actually is the most useful, like compiling a big ``low-level'' language (which might be hard to debug) on a slow embedded device.

Name: Anonymous 2015-12-05 22:37

>>52
Would it? Evidence? I'm going to go out on a limb and say that an additional, explicit stack won't add much overhead.

Name: Cudder !cXCudderUE 2015-12-06 6:42

>>52
The fastest C compiler I know of is TCC. Recursive-descent parser. You're wrong.

Name: Anonymous 2016-07-11 7:15

>>54
faggot
also dubs

Name: Anonymous 2016-08-26 4:50

>>54
What actually makes TCC so fast? GCC is recursive-descent too, isn't it? Yet GCC is a lot slower.

Name: Anonymous 2016-08-26 4:58

>>1
there's a big difference between knowing how to do something and knowing when it's a waste of time.

plenty of compilers you aren't even aware of don't use a hand-written parser, though they may use recursive-descent.

>>56
likely has more to do with the optimizations that gcc does, rather than parsing

Name: Anonymous 2016-08-26 5:05

>>43
i have never used a proper parser generator
nice one bro

Name: Anonymous 2016-08-26 5:06

>>52
doing this thing by hand would make it slower that doing it automatically via parser generator

Name: Anonymous 2016-08-26 6:24

>>56
TCC doesn't optimize much, it has minimal functionality that mimics GCC.

Name: Cudder !cXCudderUE 2016-08-27 14:17

>>56
Because GCC was written by a bunch of GNUtarded academics more interested in the philosophy of software licenses than anything else. RMS wanted to make GCC so convoluted that no one would attempt to modify or extend it, and that's the result. It's not quite enterprisey, but it's a similar attitude that creates other things like their 50-line+ true and false.

It also parses a bunch of other C-ish languages (like C++) in the same code so there are plenty of conditional branches that would always go one way or the other, but the bloat is still there.

>>60
GCC -O0 is still much slower than TCC.

Name: Anonymous 2016-08-27 15:08

C-dder is all talk and no action.

Name: Anonymous 2016-08-27 17:55

Cudder is all talk, and even his talk is shit.

Name: Cudder Internet Defense Force 2016-08-27 18:45

>>63
his

Name: Anonymous 2016-08-27 19:08

WELL FUCK ME IN MY DICKHOLE WITH YOUR 6-INCH CLIT

Name: Anonymous 2016-08-27 19:09

(this space left intentionally androgynous)

Name: Anonymous 2016-08-30 5:35

Check em

Name: sage 2016-08-30 10:42

stop being a namefag

Name: Anonymous 2016-08-30 11:11

>>68
No u

Name: Anonymous 2016-08-30 16:38

>>69
clock quads

Don't change these.
Name: Email:
Entire Thread Thread List