6 ms·
I am currently following a compiler class, and I must say that I am really amazed and impressed. For an assignment, we of course had to write an interpreter for
by caissy 13y ago
I am currently following a compiler class, and I must say that I am really amazed and impressed. For an assignment, we of course had to write an interpreter for our own mini language. The fealing you have after creating this interpreter was overwhelming.
For the lexer and parser, we used SableCC, an object oriented framework that generates a compiler in Java. I've never used anything else (yacc, lex, etc), so I can't compare the tool, but it provides a rich, useful and easy interface to use.
- pjmlp 13y agoSableCC is quite good. yacc and lex are handy to have around, but feel like Jurassic tools when compared to more modern parser generators tooling like ANTLR.
- Taniwha 13y agokids these days, when I wrote my first compiler I had to write my own yacc equivalent, and parser FYI: My generator allowed for dynamic resolution of shift/reduce conflicts which allows you to compile some languages yacc wont let you (languages that let you change the priority of operators for example)
- pjmlp 13y agoGiven that one of my CS specialization areas was compiler design, me too. I implemented a left recursive parser in x86 Assembly for MS-DOS systems. As I said, yacc and lex are nice to have, but nowadays there is little incentive to keep using them. Specially as you say, they are not able to parse all types of languages.
- Taniwha 13y agoDid something similar in 6800 assembly, left recursion of course limits you even more - but it helps fit that tiny tiny compiler into 2k. I actually like yacc/bison - they're good for most purposes and deliberately designing a non-LALR (or more a non-LR) language on purpose (rather than because you don't know any better) is usually silly - you do need to 'get' the concept of building a parse tree from bottom up - assembling it from larger and larger snippets as you go Oh and yacc/bison run about 10 times faster than equivalent I wrote 10 years before they existed so I'm not complaining I tend to use the same bespoke lexical analyser I've used for years and hack it to suit - it includes support for symbol tables/etc and runs really fast, no need to reinvent the wheel
- eli_gottlieb 13y agoIf only SableCC could compile its Java 1.7 grammar without blowing up in memory usage, I would love it even more. As it is, I used it in my research when I needed a parser. Can't recommend it enough!