kind "SharedLib"
language "C"
location "build"
- files { "source/runtime/**.*" }
+ files {
+ "source/runtime/**.*"
+ }
project "sclpl-rt-tests"
kind "ConsoleApp"
language "C++"
location "build"
- links { "UnitTest++", "sclpl-rt" }
- includedirs { "source/runtime/**", "tools/UnitTest++/**" }
- files { "tests/runtime/*.c*" }
- postbuildcommands { "./sclpl-rt-tests" }
+ links {
+ "UnitTest++",
+ "sclpl-rt"
+ }
+ includedirs {
+ "source/runtime/**",
+ "tools/UnitTest++/**"
+ }
+ files {
+ "tests/runtime/*.c*"
+ }
+ postbuildcommands {
+ "./sclpl-rt-tests"
+ }
-------------------------------------------------------------------------------
-- SCLPL Lexer
location "build"
includedirs {
"source/lexer/**",
- "source/common/",
- "source/runtime/**"
+ "source/runtime/**",
+ "source/common/**",
}
files {
"source/lexer/**.*",
- "source/runtime/collector/**.*"
+ "source/common/**.*",
}
project "sclpl-lex-tests"
kind "ConsoleApp"
language "C++"
location "build"
- links { "UnitTest++" }
- includedirs { "source/lexer/**", "tools/UnitTest++/**" }
- files { "tests/lexer/*.c*" }
- postbuildcommands { "./sclpl-lex-tests" }
+ links {
+ "UnitTest++"
+ }
+ includedirs {
+ "source/lexer/**",
+ "tools/UnitTest++/**"
+ }
+ files {
+ "tests/lexer/*.c*"
+ }
+ postbuildcommands {
+ "./sclpl-lex-tests"
+ }
-------------------------------------------------------------------------------
-- SCLPL Parser
includedirs {
"source/lexer/**",
"source/runtime/**",
- "source/common/**"
+ "source/common/**",
}
files {
"source/parser/**.*",
kind "ConsoleApp"
language "C++"
location "build"
- links { "UnitTest++" }
- includedirs { "source/parser/**", "tools/UnitTest++/**" }
- files { "tests/parser/*.c*" }
- postbuildcommands { "./sclpl-parse-tests" }
+ links {
+ "UnitTest++"
+ }
+ includedirs {
+ "source/parser/**",
+ "tools/UnitTest++/**"
+ }
+ files {
+ "tests/parser/*.c*"
+ }
+ postbuildcommands {
+ "./sclpl-parse-tests"
+ }
-------------------------------------------------------------------------------
-- UnitTest++ - A C/C++ unit testing library
--- /dev/null
+/**
+ @file tokens.c
+ @brief See header for details
+ $Revision$
+ $HeadURL$
+*/
+#include "tokens.h"
+
+const char* Token_Types[TOK_MAX] = {
+ "EOF", /* TOK_EOF */
+ "ID", /* TOK_ID */
+ "NUM", /* TOK_NUM */
+ "LPAREN", /* TOK_LPAR */
+ "RPAREN", /* TOK_RPAR */
+ "LBRACK", /* TOK_LBRACK */
+ "RBRACK", /* TOK_RBRACK */
+ "LBRACE", /* TOK_LBRACE */
+ "RBRACE", /* TOK_RBRACE */
+ "TERM", /* TOK_TERM */
+ "BOOL", /* TOK_BOOL */
+};
+
TOK_MAX = 11,
} tok_type_t;
+extern const char* Token_Types[TOK_MAX];
+
#endif /* TOKENS_H */
#include "classes.h"
#include "file.h"
#include "buf.h"
+#include "tokens.h"
/* Prototypes
*****************************************************************************/
*****************************************************************************/
jmp_buf Jump_Point;
-const char* Types[TOK_MAX] = {
- "EOF", /* TOK_EOF */
- "ID", /* TOK_ID */
- "NUM", /* TOK_NUM */
- "LPAREN", /* TOK_LPAR */
- "RPAREN", /* TOK_RPAR */
- "LBRACK", /* TOK_LBRACK */
- "RBRACK", /* TOK_RBRACK */
- "LBRACE", /* TOK_LBRACE */
- "RBRACE", /* TOK_RBRACE */
- "TERM", /* TOK_TERM */
- "BOOL", /* TOK_BOOL */
-};
-
const lex_keyword_t Keywords[] = {
{ "end", TOK_TERM },
{ "true", TOK_BOOL },
static void accept_char(tok_type_t tok)
{
- tok_set_type( Types[tok] );
+ tok_set_type( Token_Types[tok] );
tok_consume();
tok_accept();
}
{
if (0 == strcmp( p_text, Keywords[i].p_text ))
{
- tok_set_type( Types[ Keywords[i].type ] );
+ tok_set_type( Token_Types[ Keywords[i].type ] );
break;
}
i++;
static void number(void)
{
- tok_set_type(Types[TOK_NUM]);
+ tok_set_type(Token_Types[TOK_NUM]);
if (matches('0'))
{
tok_consume();
static void identifier(void)
{
- tok_set_type(Types[TOK_ID]);
+ tok_set_type(Token_Types[TOK_ID]);
while (!token_end())
tok_consume();
accept();
#include <stdio.h>
+#include "tok.h"
int parse_files(int num_files, char** fnames);
int parse_input(char* outfile);
int parse_input(char* outfile)
{
- //tok_open(outfile);
-
- //tok_close();
+ int ret = 0;
+ if (tok_source(outfile))
+ {
+ while (!tok_eof())
+ {
+ tok_t* p_tok = tok_read();
+ if (NULL != p_tok)
+ {
+ printf( "%s:%d:%d:\t%d\t%s",
+ p_tok->p_file_name,
+ p_tok->line,
+ p_tok->column,
+ p_tok->type,
+ p_tok->p_text );
+ }
+ }
+ tok_finish();
+ }
+ return ret;
}
--- /dev/null
+/**
+ @file tok.c
+ @brief See header for details
+ $Revision$
+ $HeadURL$
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "tok.h"
+#include "tokens.h"
+
+#define FIELD_TYPE 0
+#define FIELD_LINE_NUM 1
+#define FIELD_COLUMN_NUM 2
+#define FIELD_TEXT 3
+#define FIELD_MAX 4
+
+#define MAX_INPUT_STR 1024
+FILE* Handle = NULL;
+tok_t Token = { 0 };
+char Buffer[MAX_INPUT_STR];
+
+bool tok_source(char* fname)
+{
+ if (NULL == fname)
+ {
+ Handle = stdin;
+ }
+ else
+ {
+ Handle = fopen(fname,"r");
+ }
+ return (NULL != Handle);
+}
+
+bool tok_eof(void)
+{
+ bool ret = true;
+ if (NULL != Handle)
+ {
+ ret = feof( Handle );
+ }
+ return ret;
+}
+
+void tok_finish(void)
+{
+ fclose(Handle);
+}
+
+tok_t* tok_read(void)
+{
+ tok_t* p_tok = NULL;
+ if (NULL != Handle)
+ {
+ fgets(Buffer, MAX_INPUT_STR, Handle);
+ if ('\0' != Buffer[0])
+ {
+ if ('@' == Buffer[0])
+ {
+ tok_read_fname();
+ p_tok = tok_read();
+ }
+ else
+ {
+ p_tok = tok_build_token();
+ }
+ Buffer[0] = '\0';
+ }
+ }
+ return p_tok;
+}
+
+void tok_read_fname(void)
+{
+ uint32_t index = 0;
+ Buffer[strlen(Buffer)-1] = '\0';
+ while(' ' != Buffer[index]) index++;
+ char* new_str = (char*)malloc( strlen(&Buffer[index+1]) );
+ strcpy( new_str, &Buffer[index+1] );
+ Token.p_file_name = new_str;
+}
+
+tok_t* tok_build_token(void)
+{
+ tok_t* ret = NULL;
+ uint32_t index;
+ uint32_t start = 0;
+ uint32_t end = 0;
+
+ /* Look for and read all of the fields */
+ for (index = 0; index < FIELD_MAX; index++)
+ {
+ /* Advance to the next field */
+ bool last_field = tok_next_field( &end );
+ /* copy the filed data */
+ tok_read_field( index, &Buffer[start] );
+ /* advance to next field or exit if last field */
+ if (last_field) break;
+ else start = ++end;
+ }
+
+ /* Copy the token to the heap */
+ if (index == FIELD_TEXT)
+ {
+ ret = (tok_t*)calloc(1,sizeof(tok_t));
+ *ret = Token;
+ }
+
+ return ret;
+}
+
+bool tok_next_field(uint32_t* end)
+{
+ bool last_field = false;
+ while (('\t' != Buffer[*end]) &&
+ !(('\r' == Buffer[*end]) ||
+ ('\0' == Buffer[*end])))
+ {
+ (*end)++;
+ }
+ last_field = (('\r' == Buffer[*end]) ||
+ ('\0' == Buffer[*end])) ? true : false;
+ Buffer[*end] = '\0';
+ return last_field;
+}
+
+void tok_read_field(uint32_t index, char* str)
+{
+ uint32_t type;
+ switch (index)
+ {
+ case FIELD_TYPE:
+ for (type = 0; type < TOK_MAX; type++)
+ {
+ if (0 == strcmp(Token_Types[type],str))
+ {
+ Token.type = (tok_type_t)type;
+ break;
+ }
+ }
+ break;
+
+ case FIELD_LINE_NUM:
+ Token.line = atoi( str );
+ break;
+
+ case FIELD_COLUMN_NUM:
+ Token.column = atoi( str );
+ break;
+
+ case FIELD_TEXT:
+ Token.p_text = (char*)malloc(strlen(str));
+ strcpy( Token.p_text, str );
+ break;
+
+ default:
+ tok_fatal_error(1);
+ break;
+ }
+}
+
+void tok_fatal_error(uint32_t err_code)
+{
+ fprintf(stderr,"Fatal Error\n");
+ exit(err_code);
+}
+
--- /dev/null
+/**
+ @file tok.h
+ @brief TODO: Describe this file
+ $Revision$
+ $HeadURL$
+*/
+#ifndef TOK_H
+#define TOK_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "tokens.h"
+
+typedef struct
+{
+ tok_type_t type;
+ char* p_text;
+ char* p_file_name;
+ long line;
+ long column;
+} tok_t;
+
+bool tok_source(char* fname);
+bool tok_eof(void);
+void tok_finish(void);
+tok_t* tok_read(void);
+void tok_read_fname(void);
+tok_t* tok_build_token(void);
+bool tok_next_field(uint32_t* end);
+void tok_read_field(uint32_t index, char* str);
+void tok_fatal_error(uint32_t err_code);
+
+#endif /* TOK_H */
$HeadURL$
*/
#include "types.h"
+//#include "gc.h"
var_t new_num(double val)
{