calculator grammar

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 7 Exercise 8
Using std_lib_facilities.h by Bjarne Stroustrup.

//	Philipp Siedler
//	Bjarne Stroustrup's PP
//	Chapter 7 Exercise 8

/*
	Simple calculator

	Revision history:
		
		Revised by Philipp Siedler May 2017
		Revised by Bjarne Stroustrup November 2013
		Revised by Bjarne Stroustrup May 2007
		Revised by Bjarne Stroustrup August 2006
		Revised by Bjarne Stroustrup August 2004
		Originally written by Bjarne Stroustrup
			(bs@cs.tamu.edu) Spring 2004

	This program implements a basic expression calculator.
	Input from cin; output to cout;
	The grammar for input is:
	
	Calculation:
		Statement
		Print
		Quit
		Help
		Calculation Statement

	Statement:
		Declaration
		Expression
	
	Declaration:
		"let" Name "=" Expression
		"const" name "=" Expression

	Name:
		letter
		letter Sequence
		Sequence:
		letter
		digit
		"_"
		letter Sequence
		digit Sequence
		"_" Sequence

	Print:
		";" or '\n'
	
	Quit:
		"quit"
	
	Help
		"help" or "Help"

	Expression:
		Term
		Expression + Term
		Expression - Term

	Term:
		Primary
		Term * Primary
		Term / Primary
		Term % Primary

	Primary:
		Number
		"(" Expression ")"
		"-" Primary
		"+" Primary
		"sqrt(" Expression ")"
		"pow(" Expression "," Integer ")"
		Name
		Name "=" Expression
	
	Number:
		floating-point-literal

	Input comes from cin through the Token_stream called ts.
*/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.