tweaked the lexer to always have DEBUG of 0 and updated .tok file logic in runner
This commit is contained in:
11
Makefile
11
Makefile
@ -1,7 +1,7 @@
|
||||
CC := gcc
|
||||
FLEX := flex
|
||||
LEX := lexicalStructure.lex
|
||||
EXE := lexicalStructure
|
||||
EXE := runner
|
||||
CFLAGS := -std=c99 -Wall
|
||||
CPPFLAGS :=
|
||||
|
||||
@ -25,9 +25,16 @@ test:
|
||||
./$(EXE) ./tests/test_otherpunc.alpha
|
||||
./$(EXE) ./tests/test_simpleIntTest.alpha
|
||||
./$(EXE) ./tests/test_simpleLiterals.alpha
|
||||
|
||||
./$(EXE) -tok ./tests/test_comments.alpha
|
||||
./$(EXE) -tok ./tests/test_generalTokenTest.alpha
|
||||
./$(EXE) -tok ./tests/test_keywords.alpha
|
||||
./$(EXE) -tok ./tests/test_operators.alpha
|
||||
./$(EXE) -tok ./tests/test_otherpunc.alpha
|
||||
./$(EXE) -tok ./tests/test_simpleIntTest.alpha
|
||||
./$(EXE) -tok ./tests/test_simpleLiterals.alpha
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f lex.yy.c
|
||||
rm -f $(EXE)
|
||||
rm -f flex.h
|
||||
rm -f *.tok
|
||||
|
43
Makefile.save
Normal file
43
Makefile.save
Normal file
@ -0,0 +1,43 @@
|
||||
CC := gcc
|
||||
FLEX := flex
|
||||
LEX := lexicalStructure.lex
|
||||
EXE := runner
|
||||
CFLAGS := -std=c99 -Wall
|
||||
CPPFLAGS :=
|
||||
|
||||
runner: flex.o runner.o
|
||||
$(CC) -o runner runner.o flex.o
|
||||
|
||||
debug: CFLAGS += -DDEBUG=true
|
||||
debug: clean runner
|
||||
|
||||
runner.o: runner.c runner.h flex.h
|
||||
$(CC) $(CFLAGS) -o runner.o -c runner.c
|
||||
|
||||
flex.o: lex.yy.c typedefs.h
|
||||
$(CC) $(CFLAGS) -o flex.o -c lex.yy.c
|
||||
|
||||
lex.yy.c: lexicalStructure.lex
|
||||
$(FLEX) -o lex.yy.c $(LEX)
|
||||
|
||||
test:
|
||||
./$(EXE) ./tests/test_comments.alpha
|
||||
./$(EXE) ./tests/test_generalTokenTest.alpha
|
||||
./$(EXE) ./tests/test_keywords.alpha
|
||||
./$(EXE) ./tests/test_operators.alpha
|
||||
./$(EXE) ./tests/test_otherpunc.alpha
|
||||
./$(EXE) ./tests/test_simpleIntTest.alpha
|
||||
./$(EXE) ./tests/test_simpleLiterals.alpha
|
||||
./$(EXE) -tok ./tests/test_comments.alpha
|
||||
./$(EXE) -tok ./tests/test_generalTokenTest.alpha
|
||||
./$(EXE) -tok ./tests/test_keywords.alpha
|
||||
./$(EXE) -tok ./tests/test_operators.alpha
|
||||
./$(EXE) -tok ./tests/test_otherpunc.alpha
|
||||
./$(EXE) -tok ./tests/test_simpleIntTest.alpha
|
||||
./$(EXE) -tok ./tests/test_simpleLiterals.alpha
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f lex.yy.c
|
||||
rm -f $(EXE)
|
||||
rm -f flex.h
|
||||
rm -f *.tok
|
477
flex.h
Normal file
477
flex.h
Normal file
@ -0,0 +1,477 @@
|
||||
#ifndef yyHEADER_H
|
||||
#define yyHEADER_H 1
|
||||
#define yyIN_HEADER 1
|
||||
|
||||
#line 6 "flex.h"
|
||||
|
||||
#line 8 "flex.h"
|
||||
|
||||
#define YY_INT_ALIGNED short int
|
||||
|
||||
/* A lexical scanner generated by flex */
|
||||
|
||||
#define FLEX_SCANNER
|
||||
#define YY_FLEX_MAJOR_VERSION 2
|
||||
#define YY_FLEX_MINOR_VERSION 6
|
||||
#define YY_FLEX_SUBMINOR_VERSION 4
|
||||
#if YY_FLEX_SUBMINOR_VERSION > 0
|
||||
#define FLEX_BETA
|
||||
#endif
|
||||
|
||||
/* First, we deal with platform-specific or compiler-specific issues. */
|
||||
|
||||
/* begin standard C headers. */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* end standard C headers. */
|
||||
|
||||
/* flex integer type definitions */
|
||||
|
||||
#ifndef FLEXINT_H
|
||||
#define FLEXINT_H
|
||||
|
||||
/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
|
||||
|
||||
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||
|
||||
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
|
||||
* if you want the limit (max/min) macros for int types.
|
||||
*/
|
||||
#ifndef __STDC_LIMIT_MACROS
|
||||
#define __STDC_LIMIT_MACROS 1
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
typedef int8_t flex_int8_t;
|
||||
typedef uint8_t flex_uint8_t;
|
||||
typedef int16_t flex_int16_t;
|
||||
typedef uint16_t flex_uint16_t;
|
||||
typedef int32_t flex_int32_t;
|
||||
typedef uint32_t flex_uint32_t;
|
||||
#else
|
||||
typedef signed char flex_int8_t;
|
||||
typedef short int flex_int16_t;
|
||||
typedef int flex_int32_t;
|
||||
typedef unsigned char flex_uint8_t;
|
||||
typedef unsigned short int flex_uint16_t;
|
||||
typedef unsigned int flex_uint32_t;
|
||||
|
||||
/* Limits of integral types. */
|
||||
#ifndef INT8_MIN
|
||||
#define INT8_MIN (-128)
|
||||
#endif
|
||||
#ifndef INT16_MIN
|
||||
#define INT16_MIN (-32767-1)
|
||||
#endif
|
||||
#ifndef INT32_MIN
|
||||
#define INT32_MIN (-2147483647-1)
|
||||
#endif
|
||||
#ifndef INT8_MAX
|
||||
#define INT8_MAX (127)
|
||||
#endif
|
||||
#ifndef INT16_MAX
|
||||
#define INT16_MAX (32767)
|
||||
#endif
|
||||
#ifndef INT32_MAX
|
||||
#define INT32_MAX (2147483647)
|
||||
#endif
|
||||
#ifndef UINT8_MAX
|
||||
#define UINT8_MAX (255U)
|
||||
#endif
|
||||
#ifndef UINT16_MAX
|
||||
#define UINT16_MAX (65535U)
|
||||
#endif
|
||||
#ifndef UINT32_MAX
|
||||
#define UINT32_MAX (4294967295U)
|
||||
#endif
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX (~(size_t)0)
|
||||
#endif
|
||||
|
||||
#endif /* ! C99 */
|
||||
|
||||
#endif /* ! FLEXINT_H */
|
||||
|
||||
/* begin standard C++ headers. */
|
||||
|
||||
/* TODO: this is always defined, so inline it */
|
||||
#define yyconst const
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
#define yynoreturn __attribute__((__noreturn__))
|
||||
#else
|
||||
#define yynoreturn
|
||||
#endif
|
||||
|
||||
/* Size of default input buffer. */
|
||||
#ifndef YY_BUF_SIZE
|
||||
#ifdef __ia64__
|
||||
/* On IA-64, the buffer size is 16k, not 8k.
|
||||
* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
|
||||
* Ditto for the __ia64__ case accordingly.
|
||||
*/
|
||||
#define YY_BUF_SIZE 32768
|
||||
#else
|
||||
#define YY_BUF_SIZE 16384
|
||||
#endif /* __ia64__ */
|
||||
#endif
|
||||
|
||||
#ifndef YY_TYPEDEF_YY_BUFFER_STATE
|
||||
#define YY_TYPEDEF_YY_BUFFER_STATE
|
||||
typedef struct yy_buffer_state *YY_BUFFER_STATE;
|
||||
#endif
|
||||
|
||||
#ifndef YY_TYPEDEF_YY_SIZE_T
|
||||
#define YY_TYPEDEF_YY_SIZE_T
|
||||
typedef size_t yy_size_t;
|
||||
#endif
|
||||
|
||||
extern int yyleng;
|
||||
|
||||
extern FILE *yyin, *yyout;
|
||||
|
||||
#ifndef YY_STRUCT_YY_BUFFER_STATE
|
||||
#define YY_STRUCT_YY_BUFFER_STATE
|
||||
struct yy_buffer_state
|
||||
{
|
||||
FILE *yy_input_file;
|
||||
|
||||
char *yy_ch_buf; /* input buffer */
|
||||
char *yy_buf_pos; /* current position in input buffer */
|
||||
|
||||
/* Size of input buffer in bytes, not including room for EOB
|
||||
* characters.
|
||||
*/
|
||||
int yy_buf_size;
|
||||
|
||||
/* Number of characters read into yy_ch_buf, not including EOB
|
||||
* characters.
|
||||
*/
|
||||
int yy_n_chars;
|
||||
|
||||
/* Whether we "own" the buffer - i.e., we know we created it,
|
||||
* and can realloc() it to grow it, and should free() it to
|
||||
* delete it.
|
||||
*/
|
||||
int yy_is_our_buffer;
|
||||
|
||||
/* Whether this is an "interactive" input source; if so, and
|
||||
* if we're using stdio for input, then we want to use getc()
|
||||
* instead of fread(), to make sure we stop fetching input after
|
||||
* each newline.
|
||||
*/
|
||||
int yy_is_interactive;
|
||||
|
||||
/* Whether we're considered to be at the beginning of a line.
|
||||
* If so, '^' rules will be active on the next match, otherwise
|
||||
* not.
|
||||
*/
|
||||
int yy_at_bol;
|
||||
|
||||
int yy_bs_lineno; /**< The line count. */
|
||||
int yy_bs_column; /**< The column count. */
|
||||
|
||||
/* Whether to try to fill the input buffer when we reach the
|
||||
* end of it.
|
||||
*/
|
||||
int yy_fill_buffer;
|
||||
|
||||
int yy_buffer_status;
|
||||
|
||||
};
|
||||
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
|
||||
|
||||
void yyrestart ( FILE *input_file );
|
||||
void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer );
|
||||
YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size );
|
||||
void yy_delete_buffer ( YY_BUFFER_STATE b );
|
||||
void yy_flush_buffer ( YY_BUFFER_STATE b );
|
||||
void yypush_buffer_state ( YY_BUFFER_STATE new_buffer );
|
||||
void yypop_buffer_state ( void );
|
||||
|
||||
YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size );
|
||||
YY_BUFFER_STATE yy_scan_string ( const char *yy_str );
|
||||
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len );
|
||||
|
||||
void *yyalloc ( yy_size_t );
|
||||
void *yyrealloc ( void *, yy_size_t );
|
||||
void yyfree ( void * );
|
||||
|
||||
/* Begin user sect3 */
|
||||
|
||||
#define yywrap() (/*CONSTCOND*/1)
|
||||
#define YY_SKIP_YYWRAP
|
||||
|
||||
extern int yylineno;
|
||||
|
||||
extern char *yytext;
|
||||
#ifdef yytext_ptr
|
||||
#undef yytext_ptr
|
||||
#endif
|
||||
#define yytext_ptr yytext
|
||||
|
||||
#ifdef YY_HEADER_EXPORT_START_CONDITIONS
|
||||
#define INITIAL 0
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef YY_NO_UNISTD_H
|
||||
/* Special case for "unistd.h", since it is non-ANSI. We include it way
|
||||
* down here because we want the user's section 1 to have been scanned first.
|
||||
* The user has a chance to override it with an option.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef YY_EXTRA_TYPE
|
||||
#define YY_EXTRA_TYPE void *
|
||||
#endif
|
||||
|
||||
/* Accessor methods to globals.
|
||||
These are made visible to non-reentrant scanners for convenience. */
|
||||
|
||||
int yylex_destroy ( void );
|
||||
|
||||
int yyget_debug ( void );
|
||||
|
||||
void yyset_debug ( int debug_flag );
|
||||
|
||||
YY_EXTRA_TYPE yyget_extra ( void );
|
||||
|
||||
void yyset_extra ( YY_EXTRA_TYPE user_defined );
|
||||
|
||||
FILE *yyget_in ( void );
|
||||
|
||||
void yyset_in ( FILE * _in_str );
|
||||
|
||||
FILE *yyget_out ( void );
|
||||
|
||||
void yyset_out ( FILE * _out_str );
|
||||
|
||||
int yyget_leng ( void );
|
||||
|
||||
char *yyget_text ( void );
|
||||
|
||||
int yyget_lineno ( void );
|
||||
|
||||
void yyset_lineno ( int _line_number );
|
||||
|
||||
/* Macros after this point can all be overridden by user definitions in
|
||||
* section 1.
|
||||
*/
|
||||
|
||||
#ifndef YY_SKIP_YYWRAP
|
||||
#ifdef __cplusplus
|
||||
extern "C" int yywrap ( void );
|
||||
#else
|
||||
extern int yywrap ( void );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef yytext_ptr
|
||||
static void yy_flex_strncpy ( char *, const char *, int );
|
||||
#endif
|
||||
|
||||
#ifdef YY_NEED_STRLEN
|
||||
static int yy_flex_strlen ( const char * );
|
||||
#endif
|
||||
|
||||
#ifndef YY_NO_INPUT
|
||||
|
||||
#endif
|
||||
|
||||
/* Amount of stuff to slurp up with each read. */
|
||||
#ifndef YY_READ_BUF_SIZE
|
||||
#ifdef __ia64__
|
||||
/* On IA-64, the buffer size is 16k, not 8k */
|
||||
#define YY_READ_BUF_SIZE 16384
|
||||
#else
|
||||
#define YY_READ_BUF_SIZE 8192
|
||||
#endif /* __ia64__ */
|
||||
#endif
|
||||
|
||||
/* Number of entries by which start-condition stack grows. */
|
||||
#ifndef YY_START_STACK_INCR
|
||||
#define YY_START_STACK_INCR 25
|
||||
#endif
|
||||
|
||||
/* Default declaration of generated scanner - a define so the user can
|
||||
* easily add parameters.
|
||||
*/
|
||||
#ifndef YY_DECL
|
||||
#define YY_DECL_IS_OURS 1
|
||||
|
||||
extern int yylex (void);
|
||||
|
||||
#define YY_DECL int yylex (void)
|
||||
#endif /* !YY_DECL */
|
||||
|
||||
/* yy_get_previous_state - get the state just before the EOB char was reached */
|
||||
|
||||
#undef YY_NEW_FILE
|
||||
#undef YY_FLUSH_BUFFER
|
||||
#undef yy_set_bol
|
||||
#undef yy_new_buffer
|
||||
#undef yy_set_interactive
|
||||
#undef YY_DO_BEFORE_ACTION
|
||||
|
||||
#ifdef YY_DECL_IS_OURS
|
||||
#undef YY_DECL_IS_OURS
|
||||
#undef YY_DECL
|
||||
#endif
|
||||
|
||||
#ifndef yy_create_buffer_ALREADY_DEFINED
|
||||
#undef yy_create_buffer
|
||||
#endif
|
||||
#ifndef yy_delete_buffer_ALREADY_DEFINED
|
||||
#undef yy_delete_buffer
|
||||
#endif
|
||||
#ifndef yy_scan_buffer_ALREADY_DEFINED
|
||||
#undef yy_scan_buffer
|
||||
#endif
|
||||
#ifndef yy_scan_string_ALREADY_DEFINED
|
||||
#undef yy_scan_string
|
||||
#endif
|
||||
#ifndef yy_scan_bytes_ALREADY_DEFINED
|
||||
#undef yy_scan_bytes
|
||||
#endif
|
||||
#ifndef yy_init_buffer_ALREADY_DEFINED
|
||||
#undef yy_init_buffer
|
||||
#endif
|
||||
#ifndef yy_flush_buffer_ALREADY_DEFINED
|
||||
#undef yy_flush_buffer
|
||||
#endif
|
||||
#ifndef yy_load_buffer_state_ALREADY_DEFINED
|
||||
#undef yy_load_buffer_state
|
||||
#endif
|
||||
#ifndef yy_switch_to_buffer_ALREADY_DEFINED
|
||||
#undef yy_switch_to_buffer
|
||||
#endif
|
||||
#ifndef yypush_buffer_state_ALREADY_DEFINED
|
||||
#undef yypush_buffer_state
|
||||
#endif
|
||||
#ifndef yypop_buffer_state_ALREADY_DEFINED
|
||||
#undef yypop_buffer_state
|
||||
#endif
|
||||
#ifndef yyensure_buffer_stack_ALREADY_DEFINED
|
||||
#undef yyensure_buffer_stack
|
||||
#endif
|
||||
#ifndef yylex_ALREADY_DEFINED
|
||||
#undef yylex
|
||||
#endif
|
||||
#ifndef yyrestart_ALREADY_DEFINED
|
||||
#undef yyrestart
|
||||
#endif
|
||||
#ifndef yylex_init_ALREADY_DEFINED
|
||||
#undef yylex_init
|
||||
#endif
|
||||
#ifndef yylex_init_extra_ALREADY_DEFINED
|
||||
#undef yylex_init_extra
|
||||
#endif
|
||||
#ifndef yylex_destroy_ALREADY_DEFINED
|
||||
#undef yylex_destroy
|
||||
#endif
|
||||
#ifndef yyget_debug_ALREADY_DEFINED
|
||||
#undef yyget_debug
|
||||
#endif
|
||||
#ifndef yyset_debug_ALREADY_DEFINED
|
||||
#undef yyset_debug
|
||||
#endif
|
||||
#ifndef yyget_extra_ALREADY_DEFINED
|
||||
#undef yyget_extra
|
||||
#endif
|
||||
#ifndef yyset_extra_ALREADY_DEFINED
|
||||
#undef yyset_extra
|
||||
#endif
|
||||
#ifndef yyget_in_ALREADY_DEFINED
|
||||
#undef yyget_in
|
||||
#endif
|
||||
#ifndef yyset_in_ALREADY_DEFINED
|
||||
#undef yyset_in
|
||||
#endif
|
||||
#ifndef yyget_out_ALREADY_DEFINED
|
||||
#undef yyget_out
|
||||
#endif
|
||||
#ifndef yyset_out_ALREADY_DEFINED
|
||||
#undef yyset_out
|
||||
#endif
|
||||
#ifndef yyget_leng_ALREADY_DEFINED
|
||||
#undef yyget_leng
|
||||
#endif
|
||||
#ifndef yyget_text_ALREADY_DEFINED
|
||||
#undef yyget_text
|
||||
#endif
|
||||
#ifndef yyget_lineno_ALREADY_DEFINED
|
||||
#undef yyget_lineno
|
||||
#endif
|
||||
#ifndef yyset_lineno_ALREADY_DEFINED
|
||||
#undef yyset_lineno
|
||||
#endif
|
||||
#ifndef yyget_column_ALREADY_DEFINED
|
||||
#undef yyget_column
|
||||
#endif
|
||||
#ifndef yyset_column_ALREADY_DEFINED
|
||||
#undef yyset_column
|
||||
#endif
|
||||
#ifndef yywrap_ALREADY_DEFINED
|
||||
#undef yywrap
|
||||
#endif
|
||||
#ifndef yyget_lval_ALREADY_DEFINED
|
||||
#undef yyget_lval
|
||||
#endif
|
||||
#ifndef yyset_lval_ALREADY_DEFINED
|
||||
#undef yyset_lval
|
||||
#endif
|
||||
#ifndef yyget_lloc_ALREADY_DEFINED
|
||||
#undef yyget_lloc
|
||||
#endif
|
||||
#ifndef yyset_lloc_ALREADY_DEFINED
|
||||
#undef yyset_lloc
|
||||
#endif
|
||||
#ifndef yyalloc_ALREADY_DEFINED
|
||||
#undef yyalloc
|
||||
#endif
|
||||
#ifndef yyrealloc_ALREADY_DEFINED
|
||||
#undef yyrealloc
|
||||
#endif
|
||||
#ifndef yyfree_ALREADY_DEFINED
|
||||
#undef yyfree
|
||||
#endif
|
||||
#ifndef yytext_ALREADY_DEFINED
|
||||
#undef yytext
|
||||
#endif
|
||||
#ifndef yyleng_ALREADY_DEFINED
|
||||
#undef yyleng
|
||||
#endif
|
||||
#ifndef yyin_ALREADY_DEFINED
|
||||
#undef yyin
|
||||
#endif
|
||||
#ifndef yyout_ALREADY_DEFINED
|
||||
#undef yyout
|
||||
#endif
|
||||
#ifndef yy_flex_debug_ALREADY_DEFINED
|
||||
#undef yy_flex_debug
|
||||
#endif
|
||||
#ifndef yylineno_ALREADY_DEFINED
|
||||
#undef yylineno
|
||||
#endif
|
||||
#ifndef yytables_fload_ALREADY_DEFINED
|
||||
#undef yytables_fload
|
||||
#endif
|
||||
#ifndef yytables_destroy_ALREADY_DEFINED
|
||||
#undef yytables_destroy
|
||||
#endif
|
||||
#ifndef yyTABLES_NAME_ALREADY_DEFINED
|
||||
#undef yyTABLES_NAME
|
||||
#endif
|
||||
|
||||
#line 74 "lexicalStructure.lex"
|
||||
|
||||
|
||||
#line 476 "flex.h"
|
||||
#undef yyIN_HEADER
|
||||
#endif /* yyHEADER_H */
|
@ -8,7 +8,7 @@
|
||||
#include <stdbool.h>
|
||||
#include "typedefs.h"
|
||||
int line_number = 1, column_number = 1;
|
||||
bool DEBUG = true;
|
||||
bool DEBUG = false;
|
||||
%}
|
||||
|
||||
COM ([^*]|\*+[^)*])*
|
||||
@ -70,4 +70,4 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
||||
\n {line_number++; column_number = 1;}
|
||||
. {column_number++;}
|
||||
|
||||
%%
|
||||
%%
|
||||
|
31
runner.c
31
runner.c
@ -28,6 +28,12 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if (yyin != NULL) {
|
||||
fclose(yyin);
|
||||
}
|
||||
if (output != NULL && arg == TOK_ARG) {
|
||||
fclose(output);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -40,21 +46,20 @@ char *is_tok(int argc, char *argv[]) {
|
||||
return INVALID_ARG;
|
||||
}
|
||||
|
||||
int ignore_path = 0;
|
||||
int count_since_slash = 0;
|
||||
for (int i = 0; i < file_len; i++) {
|
||||
count_since_slash++;
|
||||
if (input_prog[i] == '/') {
|
||||
ignore_path += count_since_slash;
|
||||
count_since_slash = 0;
|
||||
}
|
||||
const char *basename = input_prog;
|
||||
const char *slash = strrchr(input_prog, '/');
|
||||
if (slash != NULL) {
|
||||
basename = slash + 1;
|
||||
}
|
||||
|
||||
// Calculate lengths
|
||||
int basename_len = strlen(basename);
|
||||
char* FILE_tok = calloc(basename_len - ALPHA_OFFSET + TOK_LEN + 1, sizeof(char));
|
||||
|
||||
// Copy filename and add .tok extension
|
||||
strncpy(FILE_tok, basename, basename_len - ALPHA_OFFSET);
|
||||
strcat(FILE_tok, ".tok");
|
||||
|
||||
file_len -= ignore_path;
|
||||
input_prog += ignore_path;
|
||||
char* FILE_tok = calloc(sizeof(char), file_len - ALPHA_OFFSET + TOK_LEN);
|
||||
strncpy(FILE_tok, input_prog, file_len - ALPHA_OFFSET); //copy name of prog before .alpha
|
||||
strcpy(FILE_tok + sizeof(char) * (file_len - ALPHA_OFFSET), ".tok"); //add .tok to end of file name
|
||||
return FILE_tok;
|
||||
}
|
||||
return CHECK_OTHER;
|
||||
|
9
test_comments.tok
Normal file
9
test_comments.tok
Normal file
@ -0,0 +1,9 @@
|
||||
1 1 700 "(* hello *)"
|
||||
2 1 700 "(* hello *)"
|
||||
3 1 700 "(* I'd think this is a legal "string" that contains several \n \t
|
||||
escaped characters, isn't it? *)"
|
||||
4 1 700 "(* \ *)"
|
||||
5 1 700 "(* *)"
|
||||
6 1 700 "(*{COMMENT}+ *)"
|
||||
7 1 700 "(* * *)"
|
||||
8 1 700 "(* (hello) *)"
|
61
test_generalTokenTest.tok
Normal file
61
test_generalTokenTest.tok
Normal file
@ -0,0 +1,61 @@
|
||||
1 1 101 "This"
|
||||
1 2 101 "is"
|
||||
1 3 101 "a"
|
||||
1 4 101 "test"
|
||||
2 1 301 "9"
|
||||
2 1 101 "combined"
|
||||
2 2 301 "7"
|
||||
2 2 101 "okens"
|
||||
3 1 301 "12345"
|
||||
4 1 301 "893247892"
|
||||
5 1 101 "combined"
|
||||
5 2 101 "DueToUnknownChar"
|
||||
5 3 101 "_validtoken"
|
||||
5 4 101 "__validtoken1"
|
||||
5 5 101 "_valid_token2"
|
||||
5 6 101 "validToken3_"
|
||||
6 1 305 "true"
|
||||
6 2 306 "false"
|
||||
7 1 302 "null"
|
||||
7 2 401 "while"
|
||||
7 3 609 "!"
|
||||
7 3 101 "wrong"
|
||||
7 4 402 "if"
|
||||
7 5 101 "when"
|
||||
8 1 404 "else"
|
||||
8 2 405 "type"
|
||||
8 3 406 "function"
|
||||
9 1 407 "return"
|
||||
9 3 408 "external"
|
||||
9 11 409 "as"
|
||||
10 1 101 "string"
|
||||
10 2 101 "_NOte_that_was_not_reserved"
|
||||
11 7 508 ":"
|
||||
11 7 507 ";"
|
||||
11 7 509 ","
|
||||
11 7 510 "->"
|
||||
12 1 601 "+"
|
||||
12 1 602 "-"
|
||||
12 1 603 "*"
|
||||
12 1 604 "/"
|
||||
12 1 605 "%"
|
||||
13 1 606 "<"
|
||||
13 1 607 "="
|
||||
14 1 608 ":="
|
||||
15 2 101 "This"
|
||||
15 3 101 "is"
|
||||
15 4 101 "not"
|
||||
15 5 101 "a"
|
||||
15 6 101 "valid"
|
||||
16 1 101 "String"
|
||||
17 1 304 ""This is a valid String""
|
||||
18 1 609 "!"
|
||||
18 1 611 "|"
|
||||
19 1 612 "."
|
||||
19 1 612 "."
|
||||
20 1 700 "(* this is a comment *)"
|
||||
21 2 603 "*"
|
||||
21 2 101 "Not"
|
||||
21 3 101 "a"
|
||||
21 4 101 "comment"
|
||||
22 3 610 "&"
|
29
test_keywords.tok
Normal file
29
test_keywords.tok
Normal file
@ -0,0 +1,29 @@
|
||||
1 1 401 "while"
|
||||
2 1 101 "While"
|
||||
3 1 101 "whiLe"
|
||||
4 1 402 "if"
|
||||
5 1 101 "IF"
|
||||
6 1 101 "If"
|
||||
7 1 101 "iF"
|
||||
8 1 403 "then"
|
||||
9 1 101 "Then"
|
||||
10 1 101 "theN"
|
||||
11 1 404 "else"
|
||||
12 1 101 "eLse"
|
||||
13 1 101 "elSe"
|
||||
14 1 101 "Else"
|
||||
15 1 405 "type"
|
||||
16 1 101 "Type"
|
||||
17 1 101 "tyPe"
|
||||
18 1 406 "function"
|
||||
19 1 101 "Function"
|
||||
20 1 101 "functioN"
|
||||
21 1 407 "return"
|
||||
22 1 101 "Return"
|
||||
23 1 101 "returN"
|
||||
24 1 408 "external"
|
||||
25 1 101 "External"
|
||||
26 1 101 "exteRnal"
|
||||
27 1 409 "as"
|
||||
28 1 101 "As"
|
||||
29 1 101 "aS"
|
22
test_operators.tok
Normal file
22
test_operators.tok
Normal file
@ -0,0 +1,22 @@
|
||||
1 1 601 "+"
|
||||
2 1 602 "-"
|
||||
3 1 603 "*"
|
||||
4 1 604 "/"
|
||||
6 1 605 "%"
|
||||
7 1 606 "<"
|
||||
9 1 607 "="
|
||||
10 1 608 ":="
|
||||
11 1 607 "="
|
||||
11 1 508 ":"
|
||||
12 1 508 ":"
|
||||
13 1 607 "="
|
||||
14 1 609 "!"
|
||||
15 1 610 "&"
|
||||
16 1 611 "|"
|
||||
17 1 612 "."
|
||||
18 1 101 "relEASE"
|
||||
19 1 614 "release"
|
||||
20 1 101 "RELEASE"
|
||||
21 1 613 "reserve"
|
||||
22 1 101 "RESERVE"
|
||||
23 1 101 "reSERVe"
|
7
test_otherpunc.tok
Normal file
7
test_otherpunc.tok
Normal file
@ -0,0 +1,7 @@
|
||||
1 1 507 ";"
|
||||
2 1 508 ":"
|
||||
3 1 509 ","
|
||||
4 1 510 "->"
|
||||
5 1 510 "->"
|
||||
6 1 602 "-"
|
||||
6 1 510 "->"
|
3
test_simpleIntTest.tok
Normal file
3
test_simpleIntTest.tok
Normal file
@ -0,0 +1,3 @@
|
||||
1 1 301 "45"
|
||||
2 1 301 "123"
|
||||
3 1 301 "8392"
|
62
test_simpleLiterals.tok
Normal file
62
test_simpleLiterals.tok
Normal file
@ -0,0 +1,62 @@
|
||||
1 1 304 ""this is a string""
|
||||
1 2 301 "721398"
|
||||
1 3 303 "'g'"
|
||||
1 5 604 "/"
|
||||
1 5 101 "n"
|
||||
1 7 700 "(* should print 3 tokens before this *)"
|
||||
4 1 301 "12893"
|
||||
4 3 101 "this"
|
||||
4 4 101 "is"
|
||||
4 5 101 "not"
|
||||
4 6 101 "a"
|
||||
4 7 101 "string"
|
||||
4 8 700 "(*one valid token before this*)"
|
||||
5 1 700 "(* spacey comment here
|
||||
over multiple lines
|
||||
will it work? *)"
|
||||
9 1 306 "false"
|
||||
10 1 700 "(**)"
|
||||
12 1 101 "nullfalse"
|
||||
13 2 101 "nulltrue"
|
||||
14 1 302 "null"
|
||||
15 1 303 "'7'"
|
||||
16 1 305 "true"
|
||||
17 2 301 "189"
|
||||
18 1 303 "'\t'"
|
||||
19 1 303 "'"'"
|
||||
20 1 303 "'/'"
|
||||
21 1 303 "'\n'"
|
||||
22 1 303 "'\''"
|
||||
23 1 303 "'\t'"
|
||||
25 1 303 "'n'"
|
||||
27 2 101 "fdsf"
|
||||
28 1 700 "(*/jnewjno2893u86^ Lots of random characters /n /t '") *)"
|
||||
33 1 304 ""STRINGwithnotSPaces""
|
||||
34 1 303 "' '"
|
||||
36 1 304 ""J""
|
||||
37 1 304 """"
|
||||
38 1 304 "" ""
|
||||
40 1 304 ""{SCHAR}""
|
||||
41 1 304 ""SCHAR""
|
||||
42 1 304 ""[SCHAR]""
|
||||
43 1 304 ""FINAL: I'd think this is a legal \"string\" that contains \n \t several escaped characters, isn't it?""
|
||||
44 2 101 "I"
|
||||
44 3 101 "d"
|
||||
44 4 101 "think"
|
||||
44 5 101 "this"
|
||||
44 6 101 "is"
|
||||
44 7 101 "a"
|
||||
44 8 101 "legal"
|
||||
44 11 101 "string"
|
||||
44 14 101 "that"
|
||||
44 15 101 "contains"
|
||||
44 16 101 "several"
|
||||
44 19 101 "n"
|
||||
44 21 101 "t"
|
||||
44 22 101 "escaped"
|
||||
44 23 101 "characters"
|
||||
44 23 509 ","
|
||||
44 24 101 "isn"
|
||||
44 25 101 "t"
|
||||
44 26 101 "it"
|
||||
45 1 101 "nullLike"
|
Reference in New Issue
Block a user