Project on Grammars

profilegina123

 

Objective:To acquire a comprehensive understanding of the application of grammars and formal language theory to computing languages.
Given:

Consider the following set of productions:

P01:FNFN–HEAD   FN–BODY
P02:FN–HEADTYPE   id   (  PARAM–LIST   )
P03:TYPEchar
P04:TYPEint
P05:TYPEreal
P06:PARAM–LISTTYPE   id
P07:PARAM–LISTPARAM–LIST   ,   TYPE   id
P08:FN–BODY{   VAR–DECL   STMT   return   (   EXPRESN   )   ;   }
P09:VAR–DECLλ
P10:VAR–DECLTYPE   ID–LIST   ;
P11:VAR–DECLVAR–DECL   TYPE   ID–LIST   ;
P12:ID–LISTid
P13:ID–LISTID–LIST   ,  id
P14:STMTλ
P15:STMTSIMPLE–STMT
P16:STMTSELECT–STMT
P17:STMTREPEAT–STMT
P18:STMTSEQUENCE–STMT
P19:SIMPLE–STMTASSIGN–STMT
P20:SIMPLE–STMTFN–CALL–STMT
P21:ASSIGN–STMTvar   =   EXPRESN   ;
P22:EXPRESNARITH–EXP
P23:EXPRESNBOOL–EXP
P24:ARITH–EXPTERM
P25:ARITH–EXPARITH–EXP   ADD–OP   TERM
P26:ADD–OP+
P27:ADD–OP
P28:TERMFAC
P29:TERMTERM   MUL–OP   FAC
P30:MUL–OP*
P31:MUL–OP/
P32:FAC(   ARITH–EXP   )
P33:FACOPD
P34:OPDvar
P35:OPDconst
P36:BOOL–EXPRELN–EXP
P37:BOOL–EXPLOGIC–EXP
P38:RELN–EXPOPD   RELN–OPR   OPD
P39:RELN–OPR==
P40:RELN–OPR!=
P41:RELN–OPR<
P42:RELN–OPR<=
P43:RELN–OPR>
P44:RELN–OPR>=
P45:LOGIC–EXPOPD   LOGIC–OPR   OPD
P46:LOGIC–EXPLOGIC–OPR   OPD
P47:LOGIC–OPRand
P48:LOGIC–OPRor
P49:LOGIC–OPRnot
P50:FN–CALL–STMTid   (  ARG–LIST   )   ;
P51:ARG–LISTλ
P52:ARG–LISTid
P53:ARG–LISTARG–LIST   ,   id
P54:SELECT–STMTif   CONDITION   STMT   else   STMT
P55:CONDITION(   BOOL–EXP   )
P56:REPEAT–STMTDO–STMT
P57:REPEAT–STMTWHILE–STMT
P58:DO–STMTdo   {   STMT   }   while   CONDITION   ;
P59:WHILE–STMTwhile   CONDITION   do   {   STMT   }   ;
P60:SEQUENCE–STMTSTMT   STMT
Instructions:
    1. (30 points)   Rewrite the set of productions above in Extended Backus-Naur Form (EBNF).


    1. (35 points)   Using a Push Down Automaton (PDA), determine if the following function is valid code according to the given set of productions.


int Max ( int x, int y ) 
    { 
        int z ; 

        if ( x >y ) 
            z = x ; 
        else 
            z = y ; 

        return ( z ) ; 
    }

    1. (35 points)   Validate your answer in (2) by illustrating it with a derivation tree
Deliverable:

Submit a paper Times New Roman font, 12 pt., double-space lines).   The project must contain an introduction which includes the purpose of the project.  

 

 

 

 

I attached the answers to 1 and 2 just look to make sure correct and write a paper. 

  • 10 years ago
  • 50
Answer(0)
Bids(0)