Quote:
Originally Posted by MTK358
How would I turn a comma-seperated list of expressions into a C++ vector in the grammar?
Second, how do you implement left-associative operators in a parser that does not allow left recursion?
|
If you are asking YACC questions, your thread title should say you are asking YACC questions, not questions about "making an interpreter".
I took the stupid formal grammar portion of a computer science course far too long ago to remember much beyond how unrealistic it all was. So maybe there are answers to your questions within the realm of grammar that don't assume the specific tool (YACC or some specific other). But even if so, I suspect it would be too abstract an answer to be useful.
When you just code a parser from scratch (no YACC, nor ANTLR nor whatever), none of those issues are ever problems. Having used YACC and ANTLR (and other tools) and coded from scratch, each multiple times, my own experience is that coding from scratch feels tedious and wasteful as you are doing it (lots of doing almost the same thing over and over) but none of it is ever hard and debugging the result (if that ever is necessary) is trivial.
VS. using a tool starts out quick and easy (after some delay for reading about the tool) but then one detail after another that ought to be trivial turns out to be hard. Then you need a lot of debugging and the debugging is a nightmare.
The best feature of YACC is that it isn't too hard to use for a good language, but becomes a nightmare for a bad language. That is a very positive feature in academic use where you typically invent the language and the parser together. If a language feature is hard to parse, must be a stupid language feature, so change the language spec, rather than struggle with the parser.
Outside of academia, YACC is garbage. In the real world the language is typically spec'ed by an idiot and that spec is forced onto the programmer (too often me) responsible for the parser with no path to push back against bad language design.
I assume you are inventing your own language. So I still don't like YACC, but I won't say you are absolutely wrong to choose it.
Just if you want to ask a YACC question, explicitly ask a YACC question. (and wait for someone other than me to answer it).
Quote:
And third, what would be the best internal representation of integers? A C++ int seems simplest, but limited. Using GMP seems more versatile, but I'm afraid it might seriously slow down the interpreter compared to C++ ints.
|
Don't ask that!
How do we know the design goals and tradeoffs of your project? Take some responsibility for your design.
That said, there is a serious amount of overhead to all but the most perfect interpreter designs. The higher the overhead is, the less noticeable the real work will be. In a compiled language unnecessarily using GMP when int or long long would have been enough would be outrageously inefficient. Percentage wise, the same choice in an interpreter isn't as important.