Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About LittleC #12

Open
pacosecu opened this issue Jan 4, 2024 · 2 comments
Open

About LittleC #12

pacosecu opened this issue Jan 4, 2024 · 2 comments
Labels

Comments

@pacosecu
Copy link

pacosecu commented Jan 4, 2024

Hello: Do you know how to add pointer support in LittleC?
Thanks in advance,
paco

@pmachapman
Copy link
Owner

The advice given in the textbook (4th ed.) on page 786 is:

Supporting pointers is no more difficult than supporting any other data type. However, you will need to add support for the pointer operators to the expression parser.

Add a pointer type to var_type and go from there.

@pacosecu
Copy link
Author

Hello. Thanks for answering.
I think that in parser.c you need to add or modify a production rule, taking into account the precedence of the * and & pointer operators

Page 58 C The Complete Reference 4th Edition
Precedence Summary
Table 2-8 lists the precedence of all operators defined by C. Note that all operators, except the unary operators and ?, associate from left to right. The unary operators (*, &, –) and ? associate from right
to left.

Expressions
Operators, constants, functions, and variables are the constituents of expressions. An expression in C is any valid combination of these elements. Because most expressions tend to follow the general
rules of algebra, they are often taken for granted. However, a few aspects of expressions relate specifically to C.

Highest ( ) [ ] –>.
! ~++ –– – (type) * & sizeof
*/%


  • << >>
    < <= > >=
    == !=
    &
    ^
    |
    &&
    | |
    ?:
    = += –= *= /= etc.
    Lowest,
    Table 2 -8. Precedence of C Operators

I believe that as seen in the Operator Precedence table, the * operator and the & operator have the same level of precedence as the NOT (!) and unary minus (-) operator.

I have added support to Littlec for NOT(!) , AND(&&), OR(||).
I think support for the *, & pointer operators could be done in the same evalexp() as support for NOT(!) and unary minus (-)

But I do not know where to start...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants