https://faculty-web.msoe.edu/hasker/
Statement -> Assignment Statement -> 'if' Variable 'then' Statement 'else' Statement Assignment -> Variable '=' number Variable -> identifierwhere
identifier
is a sequence of
letters, number
is a sequence of digits
print
to display a value
Expression -> Term Expression -> Term '+' Expression Term -> Factor Term -> Factor '*' Term Factor -> '(' Expression ')' Factor -> constantwhere
constant
is a sequence of digits
void parse_expression() { void parse_factor() { parse_term(); if ( next_token() == '(' ) { if ( next_token() == '+' ) { parse_expression(); parse_expression(); if ( next_token() != ')' ) } fail(); } } else parse_constant(); void parse_term() { } parse_factor(); if ( next_token() == '*' ) { void parse_constant() { parse_term(); if ( ! isdigit(next_character()) ) fail(); } while ( isdigit(next_character()) ) } advance(); }
simple-expr-recognizer.cpp
a <= b
and a == b