Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The goal of this assignment is to create a C program which: -takes a text file as input -tokenizes the given input -Parses the tokenized

The goal of this assignment is to create a C program which:

-takes a text file as input

-tokenizes the given input

-Parses the tokenized input to determine if it is grammatically valid

Parser.c is not provided and needs to be created. Parser.c will implement a recursive decent parser based upon a provided EBNF grammar. It will do so using a function defined as follows:

_Bool parser(struct lexics *someLexics, int numberOfLexics);

Which takes an array of type lexics and an int pointer representing the number of tokens in the given lexics array. The parser method must take the given array of lexics structs and determine if it is legal in the language defined by the given grammar. The purpose of our parser is to apply the grammar rules and report any syntax errors. If no syntax errors are identified, parser returns TRUE, otherwise it returns FALSE.

Parser.c must be a recursive decent predictive parser which utilizes single-symbol lookahead. Parsers which utilize multi-symbol lookahead will not be accepted. If given a grammatically valid input, every token given must be parsed. If a syntax error is found, parsing does not need to continue. Parsers which do not consume every given token for a grammatically valid input will not be accepted.

Provided EBNF grammar:

function --> header body

header --> VARTYPE IDENTIFIER LEFT_PARENTHESIS [arg-decl] RIGHT_PARENTHESIS

arg-decl --> VARTYPE IDENTIFIER {COMMA VARTYPE IDENTIFIER}

body --> LEFT_BRACKET [statement-list] RIGHT_BRACKET

statement-list --> statement {statement}

statement --> while-loop | return | assignment | body

while-loop --> WHILE_KEYWORD LEFT_PARENTHESIS expression RIGHT_PARENTHESIS statement

return --> RETURN_KEYWORD expression EOL

assignment --> IDENTIFIER EQUAL expression EOL

expression --> term {BINOP term} | LEFT_PARENTHESIS expression RIGHT_PARENTHESIS

term --> IDENTIFIER | NUMBER

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions

Question

What is the specific purpose of an acceptable use policy?

Answered: 1 week ago