ltcmelo / psychec

A compiler frontend for the C programming language
BSD 3-Clause "New" or "Revised" License
536 stars 39 forks source link

Implement syntactic support for GNU's imaginary constants #99

Closed ludanpr closed 2 years ago

ludanpr commented 2 years ago

Implement support for imaginary constants, mentioned at PR #86 . I'm opening it as a draft for you to take a look. In particular, the changes to Lexer::lexIntegerOrFloatingConstant and the (possible) additional Lexer::DiagnosticsReporter::

ltcmelo commented 2 years ago

Looks on the right track to me @ludanpr .

ludanpr commented 2 years ago

Got it @ltcmelo , thanks for the feedback. I'm gonna work on them.

ludanpr commented 2 years ago

While working on this PR, I stumbled across on what appears to be a small bug. With the (additional) test case:

void ParserTest::case1093()
{
    parseExpression(".1f",
                    Expectation().AST( { FloatingConstantExpression }));
}

it fails:

    -------------------------------------------------
    PARSER-case1093... mismatch in ERROR count
!   FAIL
        Expected: 0
        Actual  : 1
        /home/luan/Documentos/psychec/C/tests/Test.cpp:97

    -------------------------------------------------

on

Author: Leandro T. C. Melo <ltcmelo@gmail.com>
Date:   Fri May 20 20:24:52 2022 -0300

    (initial) type binding and tests (#102)

which was tracked to:

https://github.com/ltcmelo/psychec/blob/b3cf4245dc78d0940e4f2a77f5d1fcd755d1b404/C/parser/Lexer.cpp#L916-L927

ltcmelo commented 2 years ago

@ludanpr thanks for the but discovery/report!

I just pushed a fix to it.

It could be that my fix requires you to do some adjustments in your PR, sorry for that. But it could also be that my fix gives you additional insight on my previous comments about avoiding the lexer to "look backwards".

ludanpr commented 2 years ago

I was indeed taking the approach you suggested. Thank you :+1:

ltcmelo commented 2 years ago

Thanks @ludanpr for the good work 🙂

I just merged the PR (I will just make a minor adjustment a method of lexer later).