Define use of macOS's gcc malloc or Windows msvc malloc

This commit is contained in:
Victor Fernandes 2017-03-16 16:37:41 -04:00
parent b78f4a831d
commit ef426610eb
2 changed files with 70 additions and 60 deletions

View File

@ -13,13 +13,22 @@
#ifndef BUFFER_H_ #ifndef BUFFER_H_
#define BUFFER_H_ #define BUFFER_H_
#define MACOS_DEP
/*#pragma warning(1:4001) *//*to enforce C89 type comments - to make //comments an warning */ /*#pragma warning(1:4001) *//*to enforce C89 type comments - to make //comments an warning */
/*#pragma warning(error:4001)*//* to enforce C89 comments - to make // comments an error */ /*#pragma warning(error:4001)*//* to enforce C89 comments - to make // comments an error */
/* standard header files */ /* standard header files */
#include <stdio.h> /* standard input/output */ #include <stdio.h> /* standard input/output */
#include <malloc.h> /* for dynamic memory allocation.*/
#ifdef MACOS_DEP
#include <mm_malloc.h> /* for dynamic memory allocation.*/
#endif
#ifndef MACOS_DEP
#include <malloc.h>
#endif
#include <limits.h> /* implementation-defined data type ranges and limits */ #include <limits.h> /* implementation-defined data type ranges and limits */
/* constant definitions */ /* constant definitions */

View File

@ -269,15 +269,15 @@ Token malar_next_token(Buffer * sc_buf)
/* special cases or token driven processing */ /* special cases or token driven processing */
//
//WRITE YOUR CODE FOR PROCESSING THE SPECIAL CASES HERE. // WRITE YOUR CODE FOR PROCESSING THE SPECIAL CASES HERE.
//COMMENTS AND STRING LITERALS ARE ALSO PROCESSED HERE. // COMMENTS AND STRING LITERALS ARE ALSO PROCESSED HERE.
//
//WHAT FOLLOWS IS A PSEUDO CODE. YOU CAN USE switch STATEMENT // WHAT FOLLOWS IS A PSEUDO CODE. YOU CAN USE switch STATEMENT
//INSTEAD OF if-else TO PROCESS THE SPECIAL CASES // INSTEAD OF if-else TO PROCESS THE SPECIAL CASES
//DO NOT FORGET TO COUNT THE PROGRAM LINES // DO NOT FORGET TO COUNT THE PROGRAM LINES
//
//
// IF (c == SOME CHARACTER) // IF (c == SOME CHARACTER)
// ... // ...
// SKIP CHARACTER (FOR EXAMPLE SPACE) // SKIP CHARACTER (FOR EXAMPLE SPACE)
@ -289,7 +289,7 @@ Token malar_next_token(Buffer * sc_buf)
// if (c == '{'){ t.code = RBR_T; /*no attribute */ return t; // if (c == '{'){ t.code = RBR_T; /*no attribute */ return t;
// if (c == '+'){ t.code = ART_OP_T; t.attribute.arr_op = PLUS */ return t; // if (c == '+'){ t.code = ART_OP_T; t.attribute.arr_op = PLUS */ return t;
// ... // ...
//
// IF (c == '.') TRY TO PROCESS .AND. or .OR. // IF (c == '.') TRY TO PROCESS .AND. or .OR.
// IF SOMETHING ELSE FOLLOWS . OR THE LAST . IS MISSING // IF SOMETHING ELSE FOLLOWS . OR THE LAST . IS MISSING
// RETURN AN ERROR TOKEN // RETURN AN ERROR TOKEN
@ -306,43 +306,43 @@ Token malar_next_token(Buffer * sc_buf)
// (the attribute of the string token is the offset from // (the attribute of the string token is the offset from
// the beginning of the str_LTBL char buffer to the beginning // the beginning of the str_LTBL char buffer to the beginning
// of the string (TEXT in the example)) // of the string (TEXT in the example))
//
// return t; // return t;
// ELSE // ELSE
// THE STRING LITERAL IS ILLEGAL // THE STRING LITERAL IS ILLEGAL
// SET ERROR TOKEN FOR ILLEGAL STRING (see assignment) // SET ERROR TOKEN FOR ILLEGAL STRING (see assignment)
// DO NOT STORE THE ILLEGAL STRINg IN THE str_LTBL // DO NOT STORE THE ILLEGAL STRINg IN THE str_LTBL
//
// return t; // return t;
//
// IF(c == ANOTHER CHARACTER) // IF(c == ANOTHER CHARACTER)
// SET TOKEN // SET TOKEN
// return t; // return t;
/* Process state transition table */ // /* Process state transition table */
//IF (c is a digit OR c is a letter){ // IF (c is a digit OR c is a letter){
//
//SET THE MARK AT THE BEGINING OF THE LEXEME // SET THE MARK AT THE BEGINING OF THE LEXEME
//b_setmark(sc_buf,forward); // b_setmark(sc_buf,forward);
// .... // ....
//CODE YOUR FINATE STATE MACHINE HERE (FSM or DFA) // CODE YOUR FINATE STATE MACHINE HERE (FSM or DFA)
//IT IMPLEMENTS THE FOLLOWING ALGORITHM: // IT IMPLEMENTS THE FOLLOWING ALGORITHM:
//
//FSM0. Begin with state = 0 and the input character c // FSM0. Begin with state = 0 and the input character c
//FSM1. Get the next state from the transition table calling // FSM1. Get the next state from the transition table calling
// state = get_next_state(state, c, &accept); // state = get_next_state(state, c, &accept);
//FSM2. Get the next character // FSM2. Get the next character
//FSM3. If the state is not accepting (accept == NOAS), go to step FSM1 // FSM3. If the state is not accepting (accept == NOAS), go to step FSM1
// If the step is accepting, token is found, leave the machine and // If the step is accepting, token is found, leave the machine and
// call an accepting function as described below. // call an accepting function as described below.
//
//
//RETRACT getc_offset IF THE FINAL STATE IS A RETRACTING FINAL STATE // RETRACT getc_offset IF THE FINAL STATE IS A RETRACTING FINAL STATE
//GET THE BEGINNING AND THE END OF THE LEXEME // GET THE BEGINNING AND THE END OF THE LEXEME
//lexstart = b_getmark(sc_buf); // lexstart = b_getmark(sc_buf);
//SET lexend TO getc_offset USING AN APPROPRIATE BUFFER FUNCTION // SET lexend TO getc_offset USING AN APPROPRIATE BUFFER FUNCTION
//CREATE A TEMPORRARY LEXEME BUFFER HERE; // CREATE A TEMPORRARY LEXEME BUFFER HERE;
//lex_buf = b_create(...); // lex_buf = b_create(...);
// . RETRACT getc_offset to the MARK SET PREVIOUSLY AT THE BEGINNING OF THE LEXEME AND // . RETRACT getc_offset to the MARK SET PREVIOUSLY AT THE BEGINNING OF THE LEXEME AND
// . USING b_getc() COPY THE LEXEME BETWEEN lexstart AND lexend FROM THE INPUT BUFFER INTO lex_buf USING b_addc(...), // . USING b_getc() COPY THE LEXEME BETWEEN lexstart AND lexend FROM THE INPUT BUFFER INTO lex_buf USING b_addc(...),
// . WHEN VID (KEYWORDS INCLUDED), FPL OR IL IS RECOGNIZED // . WHEN VID (KEYWORDS INCLUDED), FPL OR IL IS RECOGNIZED
@ -354,7 +354,7 @@ Token malar_next_token(Buffer * sc_buf)
// .... // ....
// b_free(lex_buf); // b_free(lex_buf);
// return t; // return t;
//
// CHECK OTHER CHARS HERE if NEEDED, SET A TOKEN AND RETURN IT. // CHECK OTHER CHARS HERE if NEEDED, SET A TOKEN AND RETURN IT.
// FOR ILLEGAL CHARACTERS SET ERROR TOKEN. // FOR ILLEGAL CHARACTERS SET ERROR TOKEN.
// THE ILLEGAL CHAR IS THE ATTRIBUTE OF THE ERROR TOKEN // THE ILLEGAL CHAR IS THE ATTRIBUTE OF THE ERROR TOKEN
@ -362,6 +362,7 @@ Token malar_next_token(Buffer * sc_buf)
// A NON-NEGATIVE NUMBER INTO THE GLOBAL VARIABLE scerrnum // A NON-NEGATIVE NUMBER INTO THE GLOBAL VARIABLE scerrnum
// AND RETURN AN ERROR TOKEN. THE ERROR TOKEN ATTRIBUTE MUST // AND RETURN AN ERROR TOKEN. THE ERROR TOKEN ATTRIBUTE MUST
// BE THE STRING "RUN TIME ERROR: " // BE THE STRING "RUN TIME ERROR: "
}//end while(1) }//end while(1)
} }