diff --git a/scanner.c b/scanner.c index ad347f0..64f5369 100755 --- a/scanner.c +++ b/scanner.c @@ -4,12 +4,10 @@ * as required for CST8152, Assignment #2 * scanner_init() must be called before using the scanner. * The file is incomplete; + * Author: Victor Fernandes, 040772243 * Provided by: Svillen Ranev * Version: 1.17.1 * Date: 30 January 2017 - ******************************************************************* - * REPLACE THIS HEADER WITH YOUR HEADER - ******************************************************************* */ /* The #define _CRT_SECURE_NO_WARNINGS should be used in MS Visual Studio projects @@ -85,15 +83,51 @@ which is being processed by the scanner. */ - DECLARE YOUR VARIABLES HERE IF NEEDED + //DECLARE YOUR VARIABLES HERE IF NEEDED while (1){ /* endless loop broken by token returns it will generate a warning */ - GET THE NEXT SYMBOL FROM THE INPUT BUFFER + //GET THE NEXT SYMBOL FROM THE INPUT BUFFER c = b_getc(sc_buf); - + switch (c) { + case 255: t.code = SEOF_T; return t; /* EOF */ + case '\0': t.code = SEOF_T; return t; /* Source EOF */ + case '\n': line++; continue; /* Ignore new line, increment line count */ + case '\r': line++; continue; /* CR, increment line count*/ + case ' ': continue; /* Ignore white space */ + case ';': t.code = EOS_T; return t; /* End of statement */ + case ',': t.code = COM_T; return t; /* Comma */ + case '{': t.code = RBR_T; return t; /* Right brace */ + case '}': t.code = LBR_T; return t; /* Left brace */ + case '(': t.code = RPR_T; return t; /* Right parenthesis */ + case ')': t.code = LPR_T; return t; /* Left parenthesis */ + case '+': t.code = ART_OP_T; t.attribute.arr_op = PLUS; return t; /* Addition operator */ + case '-': t.code = ART_OP_T; t.attribute.arr_op = MINUS; return t; /* Substraction operator */ + case '*': t.code = ART_OP_T; t.attribute.arr_op = MULT; return t; /* Multiplication operator */ + case '/': t.code = ART_OP_T; t.attribute.arr_op = DIV; return t; /* Devision operator */ + case '>': t.code = REL_OP_T; t.attribute.rel_op = GT; return t; /* Greater-than relational operator */ + case '<': + if (c = b_getc(sc_buf) == '>') { + t.code = REL_OP_T; + t.attribute.rel_op = NE; /* Negation operator */ + return t; + } + else if (c == '<') { + t.code == SCC_OP_T; /* String concatenation operator */ + } + else { + t.code = REL_OP_T; + t.attribute.rel_op = LT; /* Less-than operator */ + } + b_retract(sc_buf); + c = b_getc(sc_buf); + return t; + case '.': + b_setmark(sc_buf, b_getcoffset(sc_buf) + default: /* TODO: Do alpha [a-zA-Z] stuff here*/ + } /* special cases or token driven processing */ diff --git a/table.h b/table.h index c0bf28d..a82d70f 100755 --- a/table.h +++ b/table.h @@ -1,6 +1,7 @@ /* Filename: table.h * Transition Table and function declarations necessary for the scanner implementation * as required for CST8152 - Assignment #2. + * Author: Victor Fernandes, 040772243 * Version: 1.17.1 * Date: 30 January 2017 * Provided by: Svillen Ranev @@ -105,10 +106,7 @@ Token aa_func03(char *lexeme); // VID SVID Token aa_func05(char *lexeme); // DIL Token aa_func08(char *lexeme); // FPL Token aa_func10(char *lexeme); // OIL -Token aa_func11(char *lexeme); // ES1 (Nothing here) -Token aa_func12(char *lexeme); // ES2 -Token aa_func13(char *lexeme); // ES3 - +Token aa_func11(char *lexeme); // ES //Replace XX with the number of the accepting state: 02, 03 and so on. /* defining a new type: pointer to function (of one char * argument) @@ -137,8 +135,8 @@ PTR_AAF aa_table[] = { /* State 9 */ NULL, /* State 10 */ aa_func10, /* State 11 */ aa_func11, - /* State 12 */ aa_func12, - /* State 13 */ aa_func13 + /* State 12 */ aa_func11, + /* State 13 */ aa_func11 //HERE YOU MUST PROVIDE AN INITIALIZATION FOR AN ARRAY OF POINTERS //TO ACCEPTING FUNCTIONS. THE ARRAY HAS THE SAME SIZE AS as_table[ ]. diff --git a/token.h b/token.h index 0980362..b663831 100755 --- a/token.h +++ b/token.h @@ -1,6 +1,7 @@ /* Filename: token.h * Token declarations necessary for the scanner implementation * CST8152, Assignment #2 + * Author: Victor Fernandes, 040772243 * Version: 1.17.1 * Date: 30 January 2017 * Provided by: Svillen Ranev