Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 838 Bytes

README.md

File metadata and controls

38 lines (25 loc) · 838 Bytes

Top-down operator precedence parsing

Learning about Pratt parsing. (A similar, if not the same, technique is used to parse Mercury terms, and is presumably common to Prolog systems.)

The toy grammar implemented is:

e --> NAME
    ; INTEGER
    ; name = e
    ; e ? e : e
    ; prefixop e
    ; e postfixop
    ; e infixop e
    ; e ( args )
    ; ( e )

args --> zero or more comma-separated e

prefixop --> + ; - ; !

postfixop --> !

infixop --> + ; - ; * ; / ; ^ ; < ; >

where < and > are non-associative.

This is a better introduction than most: Pratt Parsers: Expression Parsing Made Easy

Author

Peter Wang [email protected]