Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 . * parser . h * c #ifndef PARSER _ H #define PARSER _ H void program ( ) ; void statement ( )
parserh
c
#ifndef PARSERH
#define PARSERH
void program;
void statement;
void forStatement;
void ifStatement;
void whileStatement;
void doWhileStatement;
void expression;
void condition;
void matchint expectedToken;
#endif PARSERH
parserc
c
#include
#include
#include "token.h
#include "parser.h
void program
getChar;
lex;
while nextToken EOFTOKEN
statement;
void statement
switch nextToken
case FORCODE: forStatement; break;
case IFCODE: ifStatement; break;
case WHILECODE: whileStatement; break;
case DOCODE: doWhileStatement; break;
default: printfSyntax error: invalid statement
; exit;
void forStatement
matchFORCODE;
matchLEFTPAREN;
expression;
matchSEMICOLON;
condition;
matchSEMICOLON;
expression;
matchRIGHTPAREN;
matchLEFTBRACE;
while nextToken RIGHTBRACE statement;
matchRIGHTBRACE;
void ifStatement
matchIFCODE;
matchLEFTPAREN;
condition;
matchRIGHTPAREN;
matchLEFTBRACE;
while nextToken RIGHTBRACE statement;
matchRIGHTBRACE;
if nextToken ELSECODE
matchELSECODE;
matchLEFTBRACE;
while nextToken RIGHTBRACE statement;
matchRIGHTBRACE;
void whileStatement
matchWHILECODE;
matchLEFTPAREN;
condition;
matchRIGHTPAREN;
matchLEFTBRACE;
while nextToken RIGHTBRACE statement;
matchRIGHTBRACE;
void doWhileStatement
matchDOCODE;
matchLEFTBRACE;
while nextToken RIGHTBRACE statement;
matchRIGHTBRACE;
matchWHILECODE;
matchLEFTPAREN;
condition;
matchRIGHTPAREN;
matchSEMICOLON;
void expression
lex;
void condition
lex;
void matchint expectedToken
if nextToken expectedToken
lex;
else
printfSyntax error: expected token d
expectedToken;
exit;
int main
if infp fopenfrontinr NULL
printfERROR cannot open front.in
;
return ;
else
program;
printfParsing completed successfully.
;
fcloseinfp;
return ;
tokenh
c
#ifndef TOKENH
#define TOKENH
#include
Token definitions
enum
EOFTOKEN, how can I run these files in ubuntu in the same director
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started