// Code derived from Stroustrup's PPP2 book// § 6.4 Grammars// -and beginning on p 189//------------------------------------------------------------------------------// via pp 189, 190/* Question: Is 2 an expression? A simple expression grammar Parsing the number 2 (read from bottom up):Expression: (which is an) Expression Term ^ Expression "+" Term // addition | Expression "–" Term // subtraction | |Term: (which is a) Term Primary ^ Term "*" Primary // multiplication | Term "/" Primary // division | Term "%" Primary // remainder (modulo) | |Primary: (which is a) Primary Number ^ "(" Expression ")" // grouping | |Number: (which is a) Number floating-point-literal ^ | (is a) floating-point-literal ^ | 2 So yes, 2 is an expression.*///------------------------------------------------------------------------------#include<iostream>usingstd::cout;// a simple user-defined typeclassToken{public:Token(charch):kind{ch}{}Token(charch,doubleval):kind{ch},value{val}{}charkind='0';doublevalue=0.0;};//------------------------------------------------------------------------------doubleexpression(doubled);// addition, subtractiondoubleterm(doubled);// multiplication, division, remainder (modulo)doubleprimary(doubled);// groupingdoublenumber(doubled);// floating-point literals//------------------------------------------------------------------------------// Note: this is a greatly-simplified (and contrived) example, using rudimentary// function stubs just to demonstrate the grammar call-chain involved in parsing// the number 2.intmain(){cout<<expression(2)<<'\n';// this will call all the grammar functions}doubleexpression(doubled){doubleleft=term(d);// read and evaluate a Termreturnleft;}doubleterm(doubled){doubleleft=primary(d);// read and evaluate a Primaryreturnleft;}doubleprimary(doubled){doubleleft=number(d);// read and evaluate a Numberreturnleft;}doublenumber(doubled){Tokent=Token{'8',d};// just a stub for the get_token() function f. p 188returnt.value;}