From what I've gotten so far as to how the lex portion of a compiler works is this. Its not much at all but would this be what a simple scanner would look like? Anyone had experience with writing their own compiler? Please give me all the feedback that you may have, than tell me where to get a YACC for C++. thanks everyone.
Code:#include ##### using namespace std; void printToken( token from scan ) { switch (token from scan) { case (if its reserve word cout<<"reserve word:"<< reserved word<<endl; case (if special symbol cout<<"ID, name = "<< ID<< endl; case (if other cout<<"other"<< other<<endl; default: cout<<"unknown: \n", token; } } int main () { string resdwd[] = reserved word char spchar[] = special character char other[] = other Input request cout<< input file cin>> infile //file.txt Reads input files {read each set of character and place in what ever group: if character = "if, then, else, etc.." place in reserved word while charater = "+, . , =, etc.." place in special character else character + "other: place in other} printToken() to textfile name tokenfile.txt }



LinkBack URL
About LinkBacks


