Generating a parser for a customized (imaginary) programming language, I have made a grammar for that customized programming language and checked that with right and wrong input code.
Terminal and non-terminal symbols are the lexical parts used in deciding the creation rules setting up a customary programming language. Terminal symbols are simple symbols described by an ordinary programming language. Grammar is not just used to portray the formulation of a programming language, it is furthermore used to compiler forming.
Description:
-
Semicolon is mandatory to indicate the end of a line. Every expression should be in a particular block. Each block starts with opening curly-brace and ends with closing curly-brace.
-
The Operators are:
-
binary operator: =, +, -, *, /, +=, -=, *=, /=, %=
-
logical operator: &&,||,!, AND, OR, NOT
-
relational operator: ==, !=, <, >, <=, >=
-
increment operator: ++
-
decrement operator: --
-
-
Language begins with one or more header files with keyword include. There are at least one or more header files can be exist.
-
Many or no macros can exist in the program. If macros exist, it will begins with keyword define
-
Program execution starts in the main function.
-
We have various types of type specifiers in this language:
- Integer, Float, Double, bool, String
-
Without specifying type, User are also allowed to declare constant & variable. But before declaring a constant, user need to write the keyword constant.
-
User can take input as given below.
-
Using print command, user can print.
-
Function can be called also according to below syntax.
-
We can also add additional functions. Function parameters are optional to use. Function can be called recursively.
-
User can write conditional statement with if, else if & else. There could be multiple else if and an optional else.
-
User can run two types of loop, for and while with break and continue statement.