Operator precedence lastvt Calculation

Source: Internet
Author: User

Use recursive methods to calculate the lastvt set

// 0505 lastvt. cpp: defines the entry point for the console application <SPAN class = 'wp _ keywordlink'> Program </span>. <Br/> // </P> <p> # include "stdafx. H "<br/> # include <stdio. h> <br/> # include <iostream> <br/> using namespace STD; </P> <p> # define length 5 // length of the generative formula <br/> # define count 7 // Number of generative formulas </P> <p> // generation formula <br/>/* <br/> char product [] [length] = {<br/> {'s ', 'A'}, <br/> {'s ',' ^ '}, <br/> {'s', '(','t ',') '}, <br/> {'T', 't',', ', 's'}, <br/> {'T','s '}, <br/>}; // textbook p122 1st question <br/> */<br/> char product [] [length] ={< br/> {'s ', 'V'}, <br/> {'V ', 'T'}, <br/> {'V', 'V', 'I', 't'}, <br/> {'T ', 'F'}, <br/> {'T', 't', '+', 'F'}, <br/> {'F ',')', 'V', '*'}, <br/> {'F', '('}, <br/> }; // textbook p122 3rd question </P> <p> void outputproduct () // print the formula <br/>{< br/> int I = 0, j = 0; <br/> while (product [I] [0]! = NULL) // the left side of the generative formula is not blank <br/>{< br/> printf ("/n % C->", product [I] [0]); // print non-terminator <br/> j = 1; <br/> while (product [I] [J]! = NULL) <br/>{< br/> printf ("% C", product [I] [J]); // print the terminator <br/> J ++; <br/>}< br/> I ++; // The Next Generation formula <br/>}</P> <p> char lastterm (char * s) // The Last Terminator. If no, return a non-terminator <br/>{< br/> int I = 1; // starts from the second, because the storage is all generate <br/> char last = s [I]; // The Last Terminator, the initial value is the first symbol on the right of the generative formula <br/> while (s [I]! = NULL) <br/>{< br/> If (s [I] <'A' | s [I]> 'Z ') // is the terminator <br/>{< br/> last = s [I]; // remember <br/>}< br/> I ++; <br/>}< br/> return last; // return the first symbol on the right of the generative formula <br/>}</P> <p> void lastvt (char S) // calculate the lastvt set of a single non-Terminator and print it directly <br/>{< br/> for (INT I = 0; I <count; I ++) <br/> {<br/> If (product [I] [0] = s) <br/>{< br/> while (product [I] [0] = s) <br/>{< br/> If (lastterm (product [I]) <'A' | lastterm (product [I])> 'Z') // Terminator <br/>{< br/> printf ("% C ", lastterm (product [I]); <br/>}< br/> else <br/>{< br/> lastvt (lastterm (product [I]); <br/>}< br/> I ++; // next generation formula <br/>}</P> <p> void outputlastvt () // print the firstvt set of all non-terminologies <br/>{< br/> for (INT I = 0; I <count; I ++) <br/>{< br/> printf ("/nlastvt (% C) =", product [I] [0]); <br/> while (product [I] [0] = product [I + 1] [0]) <br/>{< br/> I ++; <br/>}< br/> lastvt (product [I] [0]); <br/>}< br/> int _ tmain (INT argc, _ tchar * argv []) <br/>{< br/> outputproduct (); <br/> outputlastvt (); </P> <p> printf ("/N "); <br/> system ("pause"); <br/> return 0; <br/>}

L

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.