microScheme
Functions | Variables
parse.cpp File Reference
#include "parse.hpp"

Functions

bool iswhitespace (char ch)
 Check whether the character is whitespace. More...
 
bool is_legalnumeric (string str)
 Check whether numericstr is an legal numericstr string. More...
 
bool is_legaloperator (string str)
 Check whether str is a legal operator. More...
 
void readsinglesymbol (string &substring, string &sexpr)
 
void clearwhitespace (string &sexpr)
 Clear the whitespace at the begining and end of string sexpr. More...
 
bool is_legalexpr (string sexpr)
 Check whether the s-expression legal. More...
 
Cell * makecell (string str)
 Make the cell. More...
 
Cell * separate_parse (string &instr)
 Separately parse the sexpr and build the tree. More...
 
Cell * parse (string sexpr)
 Recursively parse sexpr and build the parse tree. More...
 

Variables

bool inparsecar
 

Detailed Description

Implementation of a parser that analyzes a string containing an s-expression, and determines its tree structure.

Function Documentation

void clearwhitespace ( string &  sexpr)

Clear the whitespace at the begining and end of string sexpr.

Parameters
sexprThe string.

References iswhitespace().

Referenced by is_legalexpr(), parse(), and separate_parse().

bool is_legalexpr ( string  sexpr)

Check whether the s-expression legal.

References clearwhitespace(), is_legalnumeric(), and is_legaloperator().

Referenced by parse().

bool is_legalnumeric ( string  str)

Check whether numericstr is an legal numericstr string.

Parameters
strThe string to be checked
Returns
ture if numericstr is an legal numericstr string, false otherwise

Referenced by is_legalexpr(), and makecell().

bool is_legaloperator ( string  str)

Check whether str is a legal operator.

Referenced by is_legalexpr(), and makecell().

bool iswhitespace ( char  ch)

Check whether the character is whitespace.

Returns
True if it is character, false else.
Parameters
chThe character to check.

Referenced by clearwhitespace(), readfile(), readsinglesymbol(), and separate_parse().

Cell* makecell ( string  str)

Make the cell.

Parameters
strThe string to represent the symbol, int or double.

References is_legalnumeric(), is_legaloperator(), make_double(), make_int(), and make_symbol().

Referenced by parse().

Cell* parse ( string  sexpr)

Recursively parse sexpr and build the parse tree.

Parameters
sexprThe s-expression stored in a string variable (note that this version of parse has side effects: it may alter the contents of sexpr).
Returns
A pointer to the conspair cell at the root of the parse tree.

References clearwhitespace(), is_legalexpr(), makecell(), and separate_parse().

Referenced by parse_eval_print(), and separate_parse().

void readsinglesymbol ( string &  substring,
string &  sexpr 
)

References iswhitespace().

Referenced by separate_parse().

Cell * separate_parse ( string &  instr)

Separately parse the sexpr and build the tree.

Parameters
instrThe string which consists of s-expressions.
Returns
A pointer to the conspair cell at the root of the parse tree.

References car(), cdr(), clearwhitespace(), cons(), inparsecar, iswhitespace(), parse(), and readsinglesymbol().

Referenced by parse().

Variable Documentation

bool inparsecar

Referenced by separate_parse().