Modified the syntax of writing real-valued literals with the DSL. Casts are not needed any more: f.ex. 1.0 is implicitly cast to AcReal. The syntax is now more consistent: reals must be explicitly written as a.b, where a and b are some integers. IMPORTANT: Previously the shorthands a. and .b were allowed, not anymore. Using those shorthands will result in a compilation error
This commit is contained in:
@@ -7,14 +7,15 @@
|
||||
Statements: return value
|
||||
block
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define BUFFER_SIZE (4096)
|
||||
|
||||
#define GEN_ID(X) X
|
||||
#define GEN_STR(X) #X
|
||||
|
||||
// clang-format off
|
||||
#define FOR_NODE_TYPES(FUNC) \
|
||||
FUNC(NODE_UNKNOWN), \
|
||||
FUNC(NODE_DEFINITION), \
|
||||
@@ -27,16 +28,18 @@
|
||||
FUNC(NODE_FUNCTION_DECLARATION), \
|
||||
FUNC(NODE_COMPOUND_STATEMENT), \
|
||||
FUNC(NODE_FUNCTION_PARAMETER_DECLARATION), \
|
||||
FUNC(NODE_MULTIDIM_SUBSCRIPT_EXPRESSION)
|
||||
FUNC(NODE_MULTIDIM_SUBSCRIPT_EXPRESSION), \
|
||||
FUNC(NODE_REAL_NUMBER)
|
||||
// clang-format on
|
||||
|
||||
/*
|
||||
/*
|
||||
// Recreating strdup is not needed when using the GNU compiler.
|
||||
// Let's also just say that anything but the GNU
|
||||
// compiler is NOT supported, since there are also
|
||||
// some gcc-specific calls in the files generated
|
||||
// some gcc-specific calls in the files generated
|
||||
// by flex and being completely compiler-independent is
|
||||
// not a priority right now
|
||||
#ifndef strdup
|
||||
#ifndef strdup
|
||||
static inline char*
|
||||
strdup(const char* in)
|
||||
{
|
||||
@@ -53,36 +56,32 @@ strdup(const char* in)
|
||||
#endif
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
FOR_NODE_TYPES(GEN_ID),
|
||||
NUM_NODE_TYPES
|
||||
} NodeType;
|
||||
typedef enum { FOR_NODE_TYPES(GEN_ID), NUM_NODE_TYPES } NodeType;
|
||||
|
||||
typedef struct astnode_s {
|
||||
int id;
|
||||
struct astnode_s* lhs;
|
||||
struct astnode_s* rhs;
|
||||
NodeType type; // Type of the AST node
|
||||
char* buffer; // Indentifiers and other strings (empty by default)
|
||||
NodeType type; // Type of the AST node
|
||||
char* buffer; // Indentifiers and other strings (empty by default)
|
||||
|
||||
int token; // Type of a terminal (that is not a simple char)
|
||||
int prefix; // Tokens. Also makes the grammar since we don't have
|
||||
int infix; // to divide it into max two-child rules
|
||||
int postfix; // (which makes it much harder to read)
|
||||
int token; // Type of a terminal (that is not a simple char)
|
||||
int prefix; // Tokens. Also makes the grammar since we don't have
|
||||
int infix; // to divide it into max two-child rules
|
||||
int postfix; // (which makes it much harder to read)
|
||||
} ASTNode;
|
||||
|
||||
|
||||
static inline ASTNode*
|
||||
astnode_create(const NodeType type, ASTNode* lhs, ASTNode* rhs)
|
||||
{
|
||||
ASTNode* node = malloc(sizeof(node[0]));
|
||||
|
||||
static int id_counter = 0;
|
||||
node->id = id_counter++;
|
||||
node->type = type;
|
||||
node->lhs = lhs;
|
||||
node->rhs = rhs;
|
||||
node->buffer = NULL;
|
||||
node->id = id_counter++;
|
||||
node->type = type;
|
||||
node->lhs = lhs;
|
||||
node->rhs = rhs;
|
||||
node->buffer = NULL;
|
||||
|
||||
node->prefix = node->infix = node->postfix = 0;
|
||||
|
||||
@@ -107,7 +106,6 @@ astnode_destroy(ASTNode* node)
|
||||
free(node);
|
||||
}
|
||||
|
||||
|
||||
extern ASTNode* root;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user