Re:So you want to write your own language?
by gamegoblin on Monday February 03, 2014 @08:26PM
(#7174885)
Agreed. I wrote a recursive descent parser generator in python and it took about an hour. Takes a BNF grammar and spits out a parser. End of story. Recursive descent parsers are dead simple.
Yes, the complexity of the parser is related to the size of the language. A smaller language needs a smaller, easier to write parser.
Have you ever written a recursive descent parser for C?
I realize now what was inaccurate about what I wrote. It's that the things you have to do after you parse might be the more harmful parts. Processing the parse tree you get back.
edit: rewording
Re:So you want to write your own language?
by joe_the_user on Tuesday February 04, 2014 @03:58PM
(#7180213)
I would point out that a recursive descent parsing does not have to return an AST or any particular tree, and often it doesn't.
Instead, when you create a recursive descent parser, you create a series of functions called whenever a syntax element is discover. In these functions, you construct whatever your final data structures are going to be.
Of course, you still can create and return a full abstract syntax tree but one nice thing about recursive descent is that if you are only going to do a few things, you can just have those few operations in your parser and be done with it.
Re:So you want to write your own language?
by seanmcdirmid on Tuesday February 04, 2014 @01:14AM
(#7175823)
I've gotten really far with a precedence parser before, and as a bonus they are intrinsically incremental. However, beware of braces to match separately.
If you understand abstract languages, writing a recursive descent parser is a simple, paper and pencil exercise.
If you don't understand abstract languages, you should not be designing a language till you stop and learn them and you should STFU about what people designing languages should do until then.