For a personal project to get me ready for an internship, I have decided to try and learn more about grammars and parsers. I wanted to make a simple compiler, and settled on a grammar that looks like this. Terminals are lowercase.
P -> S P | epsilon
S -> id assign E semi | print id semi
E -> T E'
E'-> + T E' | - T E' | epsilon
T -> F T'
T' -> * F T' | / F T' | epsilon
F -> X F'
F' -> **X F' | epsilon
X -> (E) | identifier | number
The gramamr would allow for code such as this. Operations would be assign
statements(=)
addition(-)
multiplication(*)
division(/)
subtraction(-)
exponentiation(**)
statement sequence
and a print statement(print). Also parantheses would be included.
xabc = 3.141592 ;
y = -2.0 ;
z = xabc * y - 1 ;
print z ;
I was turned on to a program from codeproject.com called Tiny Parser Generator. Here is the link. https://www.codeproject.com/Articles/28294/a-Tiny-Parser-Generator
The simple example given there that allows for the basic mathematical functions on integers I understand. I was just hoping someone could give me some insight in using this generator in trying to transform my grammar into a grammar that would work with the generator, specifically working with variables, the assign statements (i.e. =), and allowing for multiple lines of code to be written. Any help would be appreciated, thanks.
Edit- Thanks for the comments. I realize the confusion created over how I worded my question. The first task I would like to do is to add to the simple expression 2 grammar given by the website tool I linked, the ability to have variables and assignment statements, such as x = 5;