So here is the story.
I was in college and the master asked me to write a programming language, so I tried my best and created a soooo simple language and wrote down the grammar as a readable and understandable picture.
Note: If you want, you can see this step by step how to use in presentation.odp file too.
- First we have to convert the written code to a
full C Language file.
To do this, go in My Grammar folder and open up your terminal in that directory and write down:lex flex.l
- After this you should see a new file with this name:
lex.yy.c
That’s what we need.
- We have to convert the written code to a full C Language file.
To do this, go in My Grammar folder and open up your terminal in that directory again(or use the previous opened terminal...) and write down:yacc conf.y -d
- After this you should see two new files with these names:
y.tab.c
andy.tab.h
- Again in My Grammar folder, in your terminal write down:
gcc lex.yy.c y.tab.c
- After this line, gcc compiles the (
lex.yy.c
andy.yab.c
andy.tab.h
) together and creates an executable file that is your compiler, named:a.out
Because the output is an executable file, you can simply write ./a.out
and run the compiler and write code as Grammar says and see the output.
And at the end, if you want to see the grammar of the language, you can see it here.
I was trying to create some little more complex programming language based on C Language buy I wasn't so successful in it and it was so much more complex than I expected.
But i tried my best and if anyone can fix it to solve the conflicts, send me the solution in a pull request.
And here you can see the grammar of the language that I was trying to generate and in a single look you can say that it was big shot...
I'm not a guy to say where to start exactly, but I do can help a little.
- If you are completely unfamiliar with Grammar, sure the first step for you is to start learning how to write grammar and solve conflicts in grammar (I'm not really good at this too obviously).
- You have to know what lexers and parsers are and how they work together, so try to learn their concepts and understand which grammar is used in lexers (Regular grammars) and which in parsers (Context-free grammars).
- Know the language that you want to go with it. (I chose C Language, you can use whatever you like - I heard you can use python as a lexer and parser generator)
- Go for it.
If you chose your target language to be C, make sure to checkout this repository.
https://github.com/DoctorWkt/acwj
This guy made a huge favor to us.
Hope you all have a nice day. 😊