Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 845 Bytes

Grammar.md

File metadata and controls

20 lines (17 loc) · 845 Bytes

Klox Grammar

This contains the representation of the syntax grammar which is updated through the book and the questions so thought I would keep it in a small group.

Some of the grammar is used to create error productions.

expression     -> comma;
comma          -> ternary ("," ternary)*
ternary        -> equality ("?" equality ":" (equality | ternary))*
equality       -> comparison ( ( "!=" | "==" ) comparison )* ;
comparison     -> addition ( ( ">" | ">=" | "<" | "<=" ) addition )* ;
addition       -> multiplication ( ( "-" | "+" ) multiplication )* ;
multiplication -> unary ( ( "/" | "*" ) unary )* ;
unary          -> ( "!" | "-" | "+" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "*" | "/" ) unary
               | primary ;
primary        -> NUMBER | STRING | "false" | "true" | "nil"
               | "(" expression ")" ;