Define use of macOS's gcc malloc or Windows msvc malloc
This commit is contained in:
parent
b78f4a831d
commit
ef426610eb
11
buffer.h
11
buffer.h
|
@ -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 */
|
||||||
|
|
121
scanner.c
121
scanner.c
|
@ -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,62 +306,63 @@ 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;
|
|
||||||
//
|
|
||||||
// IF(c == ANOTHER CHARACTER)
|
|
||||||
// SET TOKEN
|
|
||||||
// return t;
|
|
||||||
/* Process state transition table */
|
|
||||||
|
|
||||||
//IF (c is a digit OR c is a letter){
|
// return t;
|
||||||
//
|
|
||||||
//SET THE MARK AT THE BEGINING OF THE LEXEME
|
// IF(c == ANOTHER CHARACTER)
|
||||||
//b_setmark(sc_buf,forward);
|
// SET TOKEN
|
||||||
// ....
|
// return t;
|
||||||
//CODE YOUR FINATE STATE MACHINE HERE (FSM or DFA)
|
// /* Process state transition table */
|
||||||
//IT IMPLEMENTS THE FOLLOWING ALGORITHM:
|
|
||||||
//
|
// IF (c is a digit OR c is a letter){
|
||||||
//FSM0. Begin with state = 0 and the input character c
|
|
||||||
//FSM1. Get the next state from the transition table calling
|
// SET THE MARK AT THE BEGINING OF THE LEXEME
|
||||||
// state = get_next_state(state, c, &accept);
|
// b_setmark(sc_buf,forward);
|
||||||
//FSM2. Get the next character
|
// ....
|
||||||
//FSM3. If the state is not accepting (accept == NOAS), go to step FSM1
|
// CODE YOUR FINATE STATE MACHINE HERE (FSM or DFA)
|
||||||
// If the step is accepting, token is found, leave the machine and
|
// IT IMPLEMENTS THE FOLLOWING ALGORITHM:
|
||||||
// call an accepting function as described below.
|
|
||||||
//
|
// FSM0. Begin with state = 0 and the input character c
|
||||||
//
|
// FSM1. Get the next state from the transition table calling
|
||||||
//RETRACT getc_offset IF THE FINAL STATE IS A RETRACTING FINAL STATE
|
// state = get_next_state(state, c, &accept);
|
||||||
//GET THE BEGINNING AND THE END OF THE LEXEME
|
// FSM2. Get the next character
|
||||||
//lexstart = b_getmark(sc_buf);
|
// FSM3. If the state is not accepting (accept == NOAS), go to step FSM1
|
||||||
//SET lexend TO getc_offset USING AN APPROPRIATE BUFFER FUNCTION
|
// If the step is accepting, token is found, leave the machine and
|
||||||
//CREATE A TEMPORRARY LEXEME BUFFER HERE;
|
// call an accepting function as described below.
|
||||||
//lex_buf = b_create(...);
|
|
||||||
// . 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(...),
|
// RETRACT getc_offset IF THE FINAL STATE IS A RETRACTING FINAL STATE
|
||||||
// . WHEN VID (KEYWORDS INCLUDED), FPL OR IL IS RECOGNIZED
|
// GET THE BEGINNING AND THE END OF THE LEXEME
|
||||||
// . YOU MUST CALL THE ACCEPTING FUNCTION USING THE ARRAY aa_table ,WHICH
|
// lexstart = b_getmark(sc_buf);
|
||||||
// . CONTAINS POINTERS TO FUNCTIONS. THE ARRAY INDEX OF THE FUNCTION TO BE
|
// SET lexend TO getc_offset USING AN APPROPRIATE BUFFER FUNCTION
|
||||||
// . CALLED IS STORED IN THE VARIABLE state.
|
// CREATE A TEMPORRARY LEXEME BUFFER HERE;
|
||||||
// . YOU ARE NOT ALLOWED TO CALL ANY OF THE ACCEPTING FUNCTIONS BY NAME.
|
// lex_buf = b_create(...);
|
||||||
// . THE ARGUMENT TO THE FUNCTION IS THE STRING STORED IN lex_buf.
|
// . 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(...),
|
||||||
// b_free(lex_buf);
|
// . WHEN VID (KEYWORDS INCLUDED), FPL OR IL IS RECOGNIZED
|
||||||
// return t;
|
// . YOU MUST CALL THE ACCEPTING FUNCTION USING THE ARRAY aa_table ,WHICH
|
||||||
//
|
// . CONTAINS POINTERS TO FUNCTIONS. THE ARRAY INDEX OF THE FUNCTION TO BE
|
||||||
// CHECK OTHER CHARS HERE if NEEDED, SET A TOKEN AND RETURN IT.
|
// . CALLED IS STORED IN THE VARIABLE state.
|
||||||
// FOR ILLEGAL CHARACTERS SET ERROR TOKEN.
|
// . YOU ARE NOT ALLOWED TO CALL ANY OF THE ACCEPTING FUNCTIONS BY NAME.
|
||||||
// THE ILLEGAL CHAR IS THE ATTRIBUTE OF THE ERROR TOKEN
|
// . THE ARGUMENT TO THE FUNCTION IS THE STRING STORED IN lex_buf.
|
||||||
// IN A CASE OF RUNTIME ERROR, THE FUNCTION MUST STORE
|
// ....
|
||||||
// A NON-NEGATIVE NUMBER INTO THE GLOBAL VARIABLE scerrnum
|
// b_free(lex_buf);
|
||||||
// AND RETURN AN ERROR TOKEN. THE ERROR TOKEN ATTRIBUTE MUST
|
// return t;
|
||||||
// BE THE STRING "RUN TIME ERROR: "
|
|
||||||
|
// CHECK OTHER CHARS HERE if NEEDED, SET A TOKEN AND RETURN IT.
|
||||||
|
// FOR ILLEGAL CHARACTERS SET ERROR TOKEN.
|
||||||
|
// THE ILLEGAL CHAR IS THE ATTRIBUTE OF THE ERROR TOKEN
|
||||||
|
// IN A CASE OF RUNTIME ERROR, THE FUNCTION MUST STORE
|
||||||
|
// A NON-NEGATIVE NUMBER INTO THE GLOBAL VARIABLE scerrnum
|
||||||
|
// AND RETURN AN ERROR TOKEN. THE ERROR TOKEN ATTRIBUTE MUST
|
||||||
|
// BE THE STRING "RUN TIME ERROR: "
|
||||||
|
|
||||||
}//end while(1)
|
}//end while(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue