%option noyywrap %{ #include char szNimed[50][10],t; int iCurIdx = 0,C,k,on; enum eTyyp { etpERROR = 0, etpOmist = 1, etpVrdEq = 2, etpVrdL = 3, etpVrdG = 4, etpPlus = 5, etpMinus = 6, etpDiv = 7, etpMul = 8, etpBrL = 9, etpBrR = 10, etpIf = 11, etpThen = 12, etpSemi = 13, etpT_arv = 14, etpR_arv = 15, etpIdent = 16 }; struct SLekseem { int iRida; int iVeerg; enum eTyyp etpTyyp; int I_value; float R_value; int iIndex; }; struct SLekseem slxResult; char *szLekseemid[17] = {"VIGA", "Omistusmark", "Vordusmark", "Vaiksem-mark", "Suurem-mark", "Pluss", "Miinus", "Jagamismark", "Korrutusmark", "Vasak-sulg", "Parem-sulg", "IF", "THEN", "Semikoolon", "Taisarv", "Reaalarv", "Identifikaator"}; void valjund(struct SLekseem slxLekseem) { printf("Rida: %d Veerg: %d Tyyp: %s ", slxLekseem.iRida, slxLekseem.iVeerg, szLekseemid[(int)slxLekseem.etpTyyp]); if ((int)slxLekseem.etpTyyp == 14) printf("Väärtus: %d ", slxLekseem.I_value); if ((int)slxLekseem.etpTyyp == 15) printf("Väärtus: %g ", slxLekseem.R_value); if ((int)slxLekseem.etpTyyp == 16) printf("Index: %d ", slxLekseem.iIndex); printf("\n"); return; } %} NUMBER [0-9] TAHT [A-Za-z] OMMARK ":=" VRDL_EQ "=" VRDL_L "<" VRDL_G ">" PLUS "+" MINUS "-" DIVIDE "/" MUL "*" BRACE_L "(" BRACE_R ")" IF "if" THEN "then" SEMICOL ";" TAH_NUM {TAHT}|{NUMBER} IDENT [A-Za-hj-z]({TAH_NUM}*) T_ARV {NUMBER}+ R_ARV ({T_ARV}"."({NUMBER}*))|(({NUMBER}*)"."{T_ARV}) ARV {T_ARV}|{R_ARV} CONST {T_ARV}|{R_ARV} OMIST {IDENT}{OMMARK}{AVALDIS} TERM {IDENT}|{CONST} VRDL_OP {VRDL_EQ}|{VRDL_L}|{VRDL_G} AV_OP {PLUS}|{MINUS}|{DIVIDE}|{MUL} AVALDIS {TERM}|{TERM}{AV_OP}{AVALDIS}|("("{AVALDIS}")") TING {TERM}{VRDL_OP}{TERM} TINGLAU {IF}{TING}{THEN}{KASK} KASK {OMIST}|{TINGLAU} PROGE {KASK}|({KASK}{SEMICOL}{PROGE}) %% " " ++slxResult.iVeerg; \t ++slxResult.iVeerg; \n ++slxResult.iRida; slxResult.iVeerg = 1; {OMMARK} slxResult.etpTyyp = etpOmist; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {VRDL_EQ} slxResult.etpTyyp = etpVrdEq; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {VRDL_L} slxResult.etpTyyp = etpVrdL; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {VRDL_G} slxResult.etpTyyp = etpVrdG; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {PLUS} slxResult.etpTyyp = etpPlus; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {MINUS} slxResult.etpTyyp = etpMinus; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {DIVIDE} slxResult.etpTyyp = etpDiv; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {MUL} slxResult.etpTyyp = etpMul; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {BRACE_L} slxResult.etpTyyp = etpBrL; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {BRACE_R} slxResult.etpTyyp = etpBrR; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {IF} slxResult.etpTyyp = etpIf; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {THEN} slxResult.etpTyyp = etpThen; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {SEMICOL} slxResult.etpTyyp = etpSemi; slxResult.iIndex = 0; valjund(slxResult); slxResult.iVeerg += yyleng; {T_ARV} slxResult.etpTyyp = etpT_arv; slxResult.I_value = atoi(yytext); valjund(slxResult); slxResult.iVeerg += yyleng; {R_ARV} slxResult.etpTyyp = etpR_arv; slxResult.R_value = atof(yytext); valjund(slxResult); slxResult.iVeerg += yyleng; {IDENT} { on=0; for (C=0;C