Grammatical improvements (elimination of left recursion)

Source: Internet
Author: User

In the last grammar there is a case of left recursion, which will affect the future use of the syntax analysis, so the need to eliminate left recursion, so that the use of grammatical analysis.

< programs >→< external declarations > < programs > '

< programs > ' →< programs > | Ε

< external declarations >→< function Definitions > | < definition >

< function definition >→< function declaration > < function body >

< function declaration >→< function return type > < function header >

< function return type >→< return type > | < return type > < pointer >

< function head >→ (< parameters >) | ( )

< function Body >→{< declaration statement > < executable statement part >}

< return type >→void | int | char | float | Double

< hands >→* | * < hands >

< parameters >→< Identifier types > < identifiers > | < identifier types > < identifiers >, < parameters >

< identifier type >→int | char | Double | float | < marker type > < pointer >

< identifiers (variables) >→< Letters > | _ | < identifiers > < numbers > | < identifiers > < letters >

< identifiers (variables) >→< Letters > | _ | < identifiers (variables) > '

< identifiers (variables) > ' →< numbers > | < letters >

< Letter >→a | B | C |......| x | y | Z

< Digital >→0 | 1|......| 8 | 9

< declaration statements >→< Identifier types > < identifiers >; | < identifier type > < identifier >; < declaration statements >

< executable statement parts >→< Statements > | < executable statement Parts > < statements >

< statements >→< Expression Statements > | < conditional statements > | < looping statements > | < jump statements >

< loop statement >→<while (expression statement) {executable Statement part}> | <for (expression; expression; expression) {executable Statement part}> | do{executable Statement Part}while (expression statement);

< conditional statements >→< IF statements > | <if-else Statement > | <switch Statement >

< if statement >→<if (expression statement) {executable statement part}>

<if-else Statement >→<if (expression statement) {executable statement part} else {executable statement part}>

<switch statement >→<switch (variable) {SWITCH statement block}>

<switch statement block >→< case constant: Executable Statement part > | < default: executable statement part > | < Case constants: Executable statement section > <switch statement block >

< constants >→< numbers > | < go 0 numbers > < constants >

< go 0 Digital >→1 | 2 | 3 |......| 8 | 9

< jump statement >→continue; | break; | return; | return expression; |return

< expression statements >→< Assignment Expressions > | < logical Expressions > | < arithmetic expression e>

< Assignment expressions >→< variables > = < arithmetic expressions >

< logical Expressions >→ (< expressions > | < numbers >) < logical operators > (< expressions > | < numbers >)

E→t|te '

E ' → (+t|-t) e ' |ε

T→f| FT '

T ' → (*f|/F) T ' |ε

F→PF '

F ' → (↑p |ε) F '

P (E) | < Constants > | < identifiers >

< logical operators >→> | < |! = | <= | >= | = = | ? | : | ! | || | &&

Grammatical improvements (elimination of left recursion)

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.