Move grammar to top of file

This commit is contained in:
greg 2016-01-12 03:29:28 -08:00
parent 935185ed92
commit db1e188fdb

View File

@ -1,6 +1,21 @@
use tokenizer::Token; use tokenizer::Token;
use tokenizer::Kw; use tokenizer::Kw;
/* Grammar
program := (statement delimiter ?)*
delimiter := Newline | Semicolon
statement := declaration | expression
declaraion := Fn prototype (statement)* End
prototype := identifier LParen identlist RParen
identlist := Ident (Comma Ident)* | e
expression := primary_expression (op primary_expression)*
primary_expression := Variable | Number | String | call_expr | paren_expr
paren_expr := LParen expression RParen
call_expr := identifier LParen identlist RParen
op := '+', '-', etc.
*/
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ASTNode { pub enum ASTNode {
ExprNode(Expression), ExprNode(Expression),
@ -44,21 +59,6 @@ impl ParseError {
} }
} }
/* Grammar
program := (statement delimiter ?)*
delimiter := Newline | Semicolon
statement := declaration | expression
declaraion := Fn prototype (statement)* End
prototype := identifier LParen identlist RParen
identlist := Ident (Comma Ident)* | e
expression := primary_expression (op primary_expression)*
primary_expression := Variable | Number | String | call_expr | paren_expr
paren_expr := LParen expression RParen
call_expr := identifier LParen identlist RParen
op := '+', '-', etc.
*/
struct Parser { struct Parser {
tokens: Vec<Token>, tokens: Vec<Token>,
} }