lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


whisper@oz.net wrote:

Klaas-Jan Stol wrote:

Hi,

for sake of completeness, I just updated the Lua wiki with a link to a Lua 5 grammar for Bison (or Yacc). I'm using this grammar in my attempt to write a Lua compiler targeting Parrot, the new virtual machine for Perl6. I'm pretty sure it's complete. Lua has 1 ambiguity, as described in the reference manual, this same ambiguity is also present in this grammar file. In this file, it is present as a shift/reduce conflict, resolved by default by a "shift". Adding a semicolon will result in a "reduce". (this is pretty much the same behaviour as in original Lua, I think).

kind regards,

klaas-jan stol

If you want a fast Lua parser (compared to a Yacc-ish one), consider PCCTS. It integrates the Bison/Flex syntaxing too. PCCTS can build a parser that's comperable in performance to a hand coded top down recursive parser.

In contrast to Yacc solutions, it does require a LR parser, not an LALR like Yacc. In LR grammars, the repetitions are on the left, not the right, ie: expressions, expression, not expression, expressions. (Just an abstract example because I'm too lazy to go find a real one... ;-) )

PCCTS is free and open source. Builds on standard C. http://www.polhode.com/pccts.html

Very highly recommended!

Dave LeBlanc
Seattle, WA USA

Hi dave,
I missed this email, hence my late reaction. Thanks for your tip. The speed of the compiler doesn't seem to be a big problem at this moment (the generated code is :-) But, I'll profile it, and check if the parser is a bottleneck. But, because my goal is to write a compiler, not an interpreter, it's not a really big issue. (the goal is to get lua running on parrot)

(btw, I thought repetition on the left are for LL parsers, not LR...have to check my compiler books...)

thanks for your tip
klaas-jan