d-u-d-e / c-compiler

GNU General Public License v3.0
3 stars 0 forks source link

Implement basic lexer #6

Closed albertoursino closed 1 week ago

albertoursino commented 2 weeks ago

Introduction 🤗

I have implemented the lexer following pages 8-9-10 of the book.

The lexer breaks up the source code into a list of tokens. Tokens are the smallest syntactic units of a program; they include delimiters, arithmetic symbols, keywords, and identifiers. If a program is like a book, tokens are like individual words.

Implementation Details 📝

Testing 🔎

Tests from the test suit ✅

c-compiler$ ./writing-a-c-compiler-tests/test_compiler compiler/compiler_driver.py --chapter 1 --stage lex
----------------------------------------------------------------------
Ran 24 tests in 3.964s

OK

Custom tests (https://github.com/d-u-d-e/c-compiler/issues/5) ✅

c-compiler$ python3 tests/lexer/test_lexer.py 
......
----------------------------------------------------------------------
Ran 6 tests in 0.001s

OK
albertoursino commented 2 weeks ago

This PR contains commits that should not be here. I'm working on it...

d-u-d-e commented 1 week ago

Can we get rid of __init__.py inside the tests/lexer folder?

d-u-d-e commented 1 week ago

I get the following error when I try to run the lexer tests from the author's test suite: ModuleNotFoundError: No module named 'compiler'. Does that happen to you? That also happens if you run python compiler/compiler_driver.py from the project directory.

Fabio-Marangoni commented 1 week ago

I get the following error when I try to run the lexer tests from the author's test suite: ModuleNotFoundError: No module named 'compiler'. Does that happen to you? That also happens if you run python compiler/compiler_driver.py from the project directory.

@d-u-d-e It works fine for me, in both cases.

albertoursino commented 1 week ago

Make sure to do poetry install. I fixed this issue in https://github.com/d-u-d-e/c-compiler/pull/6/commits/28857cdb2f7cca7066b1b1c459eca5058ab9eced.