cc lab 9.docx - Task 1#include <iostream>#include <fstream>#include <string> using namespace std int p = 0 char c fstream myfile typedef enum IF = 1

cc lab 9.docx - Task 1#include <iostream>#include...

This preview shows page 1 - 5 out of 20 pages.

Task 1 :#include<iostream>#include<fstream>#include<string>usingnamespacestd;intp = 0;charc;fstreammyfile;typedefenum{IF= 1, ELSE, WHILE, DO, FOR, LPRN, RPRN, OPR, UID, FLOAT, STRING_VALUE, EMPTY,MUL, MULEQ, DIV, DIVEQ, MOD, LCRBR, SPACE, RCRBR, ERROR, BEGIN, NOT, NOTEQUAL, END, LSQRBR, RSQRBR, PLUSPLUS, NEWLINE, TAB, MINUSMINUS, MINUS, MINUSEQ, PLUS, PLUSEQ, EQEQ, EQUAL, MULTILINECOMMENT, COMMENT, VOID, MAIN,SEMICLN, CLN, COMMA, LESS, LESSEQ, GREATER, GREATEREQ, INT, STRING, CHAR, DOUBLE, DIG, AND, BITAND, OR, BITOR, BITXOR, LEFTSHIFT, RIGHTSHIFT}tokentype;structtoken{tokentypetkn;stringentryno;intnum;stringvariable;};tokenmylex(charc){tokent;if(c== ' '){t.tkn = SPACE; t.entryno = "SPACE"; returnt;}elseif(c== '\t'){t.tkn = TAB; t.entryno = "TAB"; returnt;}elseif(c== '\n'){t.tkn = NEWLINE; t.entryno = "NEWLINE"; returnt;}elseif(c== ','){t.tkn = COMMA; t.entryno = "COMMA"; returnt;}elseif(c== ';'){t.tkn = SEMICLN; t.entryno = "SEMICLN"; returnt;}elseif(c== '('){t.tkn = LPRN; t.entryno = "LPRN"; returnt;}elseif(c== ')'){t.tkn = RPRN; t.entryno = "RPRN"; returnt;}elseif(c== '{'){t.tkn = LCRBR; t.entryno = "LCRBR"; returnt;
Background image
}elseif(c== '}'){t.tkn = RCRBR; t.entryno = "RCRBR"; returnt;}elseif(c== '['){t.tkn = LSQRBR; t.entryno = "LSQRBR"; returnt;}elseif(c== ']'){t.tkn = RSQRBR; t.entryno = "RSQRBR"; returnt;}elseif(c== '+'){t.tkn = PLUS; t.entryno = "PLUS"; myfile.get(c);if(c== '+'){t.tkn = PLUSPLUS; t.entryno = "PLUSPLUS"; returnt;}elseif(c== '='){t.tkn = PLUSEQ; t.entryno = "PLUSEQ"; returnt;}else{myfile.unget(); returnt;}}elseif(c== '-'){myfile.get(c);if(c== '-'){t.tkn = MINUSMINUS;t.entryno = "MINUSMINUS"; returnt;}elseif(c== '='){t.tkn = MINUSEQ;t.entryno = "MINUSEQ";returnt;}else{myfile.unget();t.tkn = MINUS; t.entryno = "MINUS"; returnt;}}elseif(c== '*'){t.tkn = MUL; t.entryno = "MUL";myfile.get(c);if(c== '='){t.tkn = MULEQ;t.entryno = "MULEQ"; returnt;}else{myfile.unget();returnt;}}
Background image
elseif(c== '/'){t.tkn = DIV;t.entryno = "DIV";myfile.get(c);if(c== '='){t.tkn = DIVEQ;t.entryno = "DIVEQ";returnt;}elseif(c== '/'){while(c!= '\n'){if(myfile.eof()){break;}myfile.get(c);}myfile.unget();t.tkn = COMMENT; t.entryno = "COMENT"; returnt;}elseif(c== '*'){charcheck = '\0';while(check != '*'&& c!= '/'){if(myfile.eof()){break;}myfile.get(c);check = c;myfile.get(c);}t.tkn = MULTILINECOMMENT; t.entryno = "MULTILINECOMMENT";returnt;}else{myfile.unget();returnt;}}elseif(c== '%'){t.tkn = MOD;t.entryno = "MOD";returnt;}elseif(c== '='){t.tkn = EQUAL;t.entryno = "EQUAL";myfile.get(c);if(c== '='){t.tkn = EQEQ;t.entryno = "EQEQ";returnt;}else{myfile.unget();returnt;}}elseif(c== '!'){t.tkn = NOT; t.entryno = "NOT"; myfile.get(c);if(c== '=')
Background image
{t.tkn = NOTEQUAL; t.entryno = "NOTEQUAL"; returnt;}else{myfile.unget();returnt;}}elseif(c== '>'){t.tkn = GREATER; t.entryno = "GREATER";myfile.get(c);if(c== '='){t.tkn = GREATEREQ; t.entryno = "GREATEREQ"; returnt;}elseif(c== '>'){t.tkn = RIGHTSHIFT;t.entryno = "RIGHTSHIF"; returnt;}else{myfile.unget();returnt;}}elseif(c== '<'){t.tkn = LESS; t.entryno = "LESS"; myfile.get(c);if(c== '='){t.tkn = LESSEQ; t.entryno = "LESSEQ"; returnt;}elseif(c== '<'){t.tkn = LEFTSHIFT;t.entryno = "LEFTSHIFT";returnt;}else{myfile.unget();returnt;}}elseif(c== '&'){t.tkn = BITAND; t.entryno = "BITAND";myfile.get(c);if(c== '&'){t.tkn = AND; t.entryno = "AND";returnt;}else{myfile.unget();returnt;}}elseif(c== '|'){t.tkn = BITOR;t.entryno = "BITOR"; myfile.get(c);if(c== '|'){t.tkn = OR;t.entryno = "OR";
Background image
Image of page 5

You've reached the end of your free preview.

Want to read all 20 pages?

  • Fall '18
  • Zia Ul Rehman
  • ASCII, Void type, Carriage return, char c, string s

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture