Question: Programming Languages - Grammar Write your own grammar for a programming language (The set of rules that tell you whether a sentence is correctly structured
Programming Languages - Grammar
Write your own grammar for a programming language (The set of rules that tell you whether a sentence is correctly structured is called a grammar). You will need to create a context-free grammar for your language. This grammar will need to be able to be recognized via recursive descent parsing. A recognizer is a program which says whether the expressions (sentences) in your source code are syntactically legal. A recursive descent parser is composed of a set of parsing functions, each of which derives from a rule in the grammar. Not all grammars are suitable for recursive descent parsing. Anything that is your own grammar that will work as a programming language is acceptable for an answer to this question as long as it is complete.
An Example using plain English:
sentence : nounPhrase verbPhrase PERIOD
nounPhrase : ARTICLE Adjective NOUN
verbPhrase : VERB nounPhrase
then with further modification the language can use adjectives and finally be:
sentence : nounPhrase verbPhrase PERIOD
nounPhrase : optArticle optAdjList NOUN
verbPhrase : VERB nounPhrase
optArticle : ARTICLE | *empty*
optAdjList : adjList | *empty*
adjList : ADJECTIVE | ADJECTIVE adjLis
KUDOS the person that can do this correctly and help me with this.
Step by Step Solution
There are 3 Steps involved in it
To create a contextfree grammar for a simple programming language that can be parsed using recursive descent parsing we need to develop a set of produ... View full answer
Get step-by-step solutions from verified subject matter experts
