efecan.zone

✧ ☕🔍 Cezve Lexer & Parser — Tokenize • Sip Coffee • Parse • Repeat! 🚀 right here ➜ github.com/efecan0/cezve 👈 ✧

Cezve

How to compile Project?

Data type size comparison table

This is my main function, you should write ‘node . compile’ and path of source code example ( node . compile test/test.cezve ). As you can see first lexer will start, it will read source code and identify type of input then parser will start and check the grammer is true or not. DoubleClick ‘cezve.bat’ to run tests.

Tokens

Data type size comparison table

I have 15 token type in my programming language. Constants is the base of my identify the token.

Lexer

Data type size comparison table

Lexer class object has 3 properties and 5 methods. Data property for input, currentChar for which char is this now, for position which index are we in. nextToken method for get next token. Start method is will read the all input and identify then, end of the start method, I added to EOF type which means (End Of File).

Data type size comparison table

Make number method first identify the number with our constants, after that we read the input and check the number is float or integer. İf you write ‘345abc’ something like that, lexer will warn you.

Data type size comparison table

Make string method first check has ‘apostrophe’, if has make string method will run and get the all characters in between apostrophes

Data type size comparison table

If lexer read a input begins with character, Make detect method will run and it’ll check the type of characters, is it arithmetic expression, or assign operation or identifier.

Parser

Data type size comparison table

Parser class object get the tokens, which we had value after lexer. Next method for get next token, parse method for begining of my grammer if first token includes (int, float or string) assign method will run else expression will run.

Data type size comparison table
Data type size comparison table

Grammer

Data type size comparison table

STATE DIAGRAM FOR RECOGNIZE TOKENS

Data type size comparison table

Test

Data type size comparison table
Data type size comparison table
Data type size comparison table

project link: github