简体   繁体   中英

Context free grammar modification for simple arithmetic Expression

given a CFG

E->TE'
E'->+TE'|-TE'|null
T->FT'
T'->*FT'|/FT'|null
F->(E)|number

how to implement this CFG in C Program so that it take multiple digit input in expression.for Example - i want to give 320/40-12*2+1*32 as input in the above CFG converted code.

Thanks

Add the rules:

number -> digit | digit number
digit -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Now write a parser in C. Since this is a trivial LL(1) grammar, the easiest way to do that is with recursive descent -- write a function for each non-terminal in the grammar that recognizes that non-terminal on your input and consumes it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM