Annulleret

recursive descent parser(repost)

<elist>-> <e><elist_tail>

<elist_tail>-> , <elist>

<elist_tail>->

<e>-><n><etail>

<etail>-> ^ <e>

<etail>->

<n>-><d><ntail>

<ntail>-> <n>

<ntail>->

<d>-> 0 |1 | 2| 3| 4| 5| 6| 7| 8| 9

by using above grammer implement recursive descent parser

the grammer generates statements of form 2^2^3,15,20^2 for which parser outputs 256 15 400

this is example which explains basic idea of rdp

note:?

1) keep all variables declared globally as they are except ? N_value

2) declare N_value locally to procedure E

3) make N_value a pass by value parameter to procedure ETAIL

4) make N_value pass by reference parameter to both procedure N and NTAIL

## Deliverables

procedure RDPARSER; while NOT EOF do SUCCEEDED = TRUE; GET_INP_LINE; //reads in the next input line GET_NEXT_SYMBOL; //returns the next input symbol ELIST; if SUCCEEDEDthen SUCCESS_MESSAGE;else FAILURE_MESSAGE enifendwhileend RDPARSER

Code:

procedure ELIST;E;if SUCCEEDED then ELIST_TAIL endifend ELIST;

Code:

procedure ELIST_TAIL;if EOLthen print E_Valueelse if next_inp_symbol = ","then print E_Value;GET_NEXT_SYMBOL;ELIST;else SUCCEEDED = FALSE endifendifend ELIST_TAIL;

Code:

procedure E;N_value = 0;N;if SUCCEEDEDthen ETAIL endifend E;

Code:

procedure ETAILif(NOT((next_inp_symbol = ",") OR EOL))then if next_inp_symbol = '^'then GET_NEXT_SYMBOL;E;E_value = N_value ** E_value;else SUCCEEDED = FALSE endifelse E_value = N_value enidfend ETAIL;

Code:

procedure N;D;if SUCCEEDEDthen N_value = N_value * 10 + D_value;NTAIL endifend N;

Code:

procedure NTAIL;if(NOT((next_inp_symbol = '^' | ',') OR EOL))then N endifend NTAIL;

Code:

procedure D;if next_inp_symbol is a digitthen compute D_value;GET_NEXT_SYMBOLelse SUCCEEDED = FALSE endifend D;

Evner: Ingeniørarbejde, Java, MySQL, PHP, Projekt Ledelse, Software Arkitektur, Software Testning

Se mere: recursive, eof, print repost, recursive php, parser code, recursive descent parser example, recursive descent, java parser, implement rdp, 2010 procedure, rdp java, java code recursive descent parser, input descent parser java, descent recursive parser code java, recursive descent parser code java, java rdp, recursive descent parser using java, recursive descent parser java example, recursive descent java, recursive descent parser example java

Om arbejdsgiveren:
( 4 bedømmelser ) United States

Projekt ID: #3315703