dabeaz / ply

Python Lex-Yacc
http://www.dabeaz.com/ply/index.html
2.79k stars 465 forks source link

Re examples/ansic #292

Closed jeffrey-cochran closed 7 months ago

jeffrey-cochran commented 1 year ago

I'm walking through the ansic example, and I was just curious if you could clarify what about it remains incomplete.

I was also intrigued by the way that the parser, which I see is closely following the C language reference, doesn't seem to require any sort of precedence tuple to handle unary operators like UMINUS. Is this because of the way PLY infers precedence of the rules from the order in which they appear in the file? <-- probably a dumb question, but I'm new to parsers <3

dabeaz commented 1 year ago

The ANSI C example is pretty much typed in directly from the C grammar found in the 2nd edition of the K&R book. There is no precedence table since the grammar is already written without ambiguity in math operations. I think there is one known shift-reduce conflict due to if-else handling.

By "incomplete", I mainly mean that the grammar was typed in and nothing else was done with it. Mainly it was used as a test to see how PLY would perform when presented with a large grammar for a real programming language. You would need to do a lot more work to turn it into a C compiler (for example, defining an AST, dealing with preprocessing, etc.).