Struct rcalc::Parser [] [src]

pub struct Parser<'a> { /* fields omitted */ }

A parser for a mathematical expression.

The Parser builds an Abstract Syntax Tree (effectively one large ASTNode) by processing a program's expressive tokens (in the case, via the Lexer). Unlike the Lexer, the Parser does not programatically build one node of the AST at a time; rather, a single request to parse a program will retrun the entire tree of the program. Like the Lexer, this tree is useless unless further processed; for instance, by a traverser (the Interpreter).

We expect the Parser to be agnostic to the significance of each Token in the program, instead concerned only with the relationships between Tokens. As such, the Parser is built to refrain from analyzing anything but the positions of tokens in a program.

Building an AST with the Parser requires only a Lexer.

let lexer = Lexer::from("1 + 3 - 2");
let mut parser = Parser::from(lexer);
let tree: ASTNode = parser.parse().unwrap();

Methods

impl<'a> Parser<'a>
[src]

[src]

Creates a Parser from a Lexer.

[src]

Generates an AST by parsing the Tokens of a program, given by a Lexer.