Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I understand tokenizing. I can get the lex to read the file, split the tokens, and display it in the console. What is the process after this? How do I retrieve the tokenized information or pass it to the parser, and connect with the treenode? The code I have prints the whole buffer that is read, and then breaks each into tokens, and labels them, according.

1)At this point do I try to pull the defines from preprocessor and lex again? Which would be in the lex.h file, or in a def file like Dr.Dobbs?

2)Do I call the token.h and treenode.h and start trying to match them?

3)Do I make the symbol table at this point?

There has to be some kind soul that will help me connect the dots. Lol.

What I have tried:

.
Posted
Updated 1-Aug-18 16:28pm
v22
Comments
Patrice T 29-Jun-18 19:59pm    
This code is not C.
Rick York 29-Jun-18 20:08pm    
I believe he wants to write a parser in C.
Mohibur Rashid 1-Aug-18 20:58pm    
c does not have bool variable type
RavenLee 1-Aug-18 21:04pm    
What do you mean? The code seems to work fine without errors.

Mohibur Rashid 1-Aug-18 21:07pm    
What's your file name? with extension please. Anyway, a quick test for you
mohibur.rashid@pcname /cygdrive/c/Users/mohibur.rashid
$ echo -e '#include <stdio.h>\n int main() {\n\tbool b;\n\tb=true;\n\tprintf("%d\\n", b);\n\treturn 0;\n}' > x.c

mohibur.rashid@pcname /cygdrive/c/Users/mohibur.rashid
$ gcc x.c
x.c: In function ‘main’:
x.c:3:2: error: unknown type name ‘bool’
  bool b;
  ^~~~
x.c:4:4: error: ‘true’ undeclared (first use in this function)
  b=true;
    ^~~~
x.c:4:4: note: each undeclared identifier is reported only once for each function it appears in


You can use the function strtok for parsing in C.
 
Share this answer
 
Comments
KarstenK 29-Jul-18 4:56am    
you should read the documentation for details of the use of strtok. You can recall strtok with the last result to get the next token. Usually in a while loop...
RavenLee 29-Jul-18 5:56am    
I have that part down. The console results get the substrings and tells me if is delim, sep, keyword. Etc. How do I use that info, is this where I would call parsing? What is the process for getting the tree and start checking these tokens against that tree?
The name for those programs is 'compiler'.
Writing a compiler is not for beginners, it is advanced topic.
if you want to learn about compilers, I recommend the dragon book:
Dragon Book - Wikipedia[^]
Compilers: Principles, Techniques, and Tools - Wikipedia[^]
 
Share this answer
 
Comments
RavenLee 29-Jul-18 17:21pm    
Come on bro, I will do the work myself, I am just having problems understanding the connections. Not asking for code just the steps, and the understanding of the linking. I have a few books on compiling already but they really dont pinpoint the connection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900