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

How to get variables from the c code in parser back to lexer file? #35

Open
JeffreyWong20 opened this issue Mar 28, 2022 · 3 comments
Open

Comments

@JeffreyWong20
Copy link

JeffreyWong20 commented Mar 28, 2022

We are currently working on typedef but we don't know what to do in term of getting back variables from C++ files which would be called at parser back to lexer. From what we knew, to let lexer recognizes some typedef types and return a type token, it needs to know the name of that correspond type first, differentiating them from normal identifier.

@johnwickerson
Copy link
Contributor

Yes this is the "lexer hack". I suggest you have the parser maintain a list of identifiers that have been typedef'd. E.g. when it encounters typedef int foo, it adds foo to that list. The lexer also has access to that list, and each time it lexes something that looks like an identifier, it sees if it appears in that list. If it does, then it lexes it as a typeident, and if it doesn't, it lexes it as a varident. (Or whatever names you want to use.)

@JeffreyWong20
Copy link
Author

JeffreyWong20 commented Mar 28, 2022

sorry, but we don't really know how to provided "symbol table access from parser to lexer". Besides the yyparse() function between parser and lexer are there any other ways they could be linked together? We tried searching online but nothing comes handy. Are there any resources which elaborates on that ? thank you.

@johnwickerson
Copy link
Contributor

perhaps you can find a way to make that symbol table "global", so that it is accessible from all parts of your program.

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

No branches or pull requests

2 participants