Week 2
Week 2 I was tasked to actually make the scanner, so I took the scanner that we did in class, copy and pasted to another file and started to look at the text and Identify the super fiscal things of the code. The keywords, the letters used, the punctuation, numbers, etc. I'm making the scanner print out numbers for what it sees so for">" it might print "4" so I know it recognized it as what I want it to. Learning from my first scanner and make sure that it takes spaces, tabs, comments, and doesn't bug out. It also takes anything unknown and prints it so I know it doesn't recognize it, until its all numbers and it makes the pattern that I want. The next step will be to make the grammar and create a parser for the language. I've made some progress on the scanner and trying to debug because I'm having trouble running the scanner.
rnum { printf("1: %s\n", yytext) ;}
str { printf("3: %s\n", yytext); }
[-+]?[0-9]*\.[0-9]+ {printf("18: %s\n", yytext) ;}
[0-9]+ {printf("25: %s\n", yytext) ;}
Some of the code above. The code above is just some of the regular expressions. I want the code to find the keyword and print a number and the keyword, but its having trouble. Okay after some debugging I got it to work using the same main as our class activity.
rnum return(REAL);
str return(STRING);
[-+]?[0-9]*\.[0-9]+ return(REAL_CONST);
[0-9]+ return(INT_CONST);
[A-Za-z]+ return(ID);
That's what it looks like now. I took the token that was used for my class assignment and applied it to my own code so it makes sense. So, for week 3 I will try taking the next steps and show my Professor to see what he thinks.
This is really cool, but a bit short and I formal. I need a little more detail and a visual of some sort would be great.
ReplyDelete