From b62ef43f077b95c44a67ce0f0412bc452e29c7ec Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 11 Jan 2016 02:03:03 -0800 Subject: [PATCH] Add basic BNF grammar --- src/parser.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 1fed2c7..b68436f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -42,6 +42,19 @@ impl ParseError { } } +/* Grammar + program := (statement delimiter ?)* + delimiter := Newline | Semicolon + statement := declaration | expression + declaraion := Fn prototype expression + prototype := identifier LParen (Ident Comma?)* RParen + expression := primary_expression (op primary_expression)* + primary_expression := Identifier | Number | call_expr | paren_expr + paren_expr := LParen expression RParen + call_expr := identifier LParen (expression Comma ?)* RParen + op := '+', '-', etc. + */ + pub fn parse(tokens: &[Token], parsed_tree: &[ASTNode]) -> ParseResult { let rest = tokens.to_vec().reverse();