aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_LSL_tree.h
blob: 9c27a8f674763dad6fc8a8654a29002ad61ce0b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Definition of the structure used to build the abstract syntax tree.
 */
#ifndef __EXPRESSION_H__
#define __EXPRESSION_H__

#ifndef YY_NO_UNISTD_H
#define YY_NO_UNISTD_H 1
#endif // YY_NO_UNISTD_H


/**
 * @brief The operation type
 */
typedef enum tagEOperationType
{
    eVALUE,
    eMULTIPLY,
    ePLUS
} EOperationType;

/**
 * @brief The expression structure
 */
typedef struct tagSExpression
{
    EOperationType type;///< type of operation

    int value;///< valid only when type is eVALUE
    struct tagSExpression* left; ///< left side of the tree
    struct tagSExpression* right;///< right side of the tree
} SExpression;

/**
 * @brief The structure used by flex and bison
 */
typedef union tagTypeParser
{
        SExpression			*expression;
        int				value;
	int				ival;
	float				fval;
	char				*sval;
//	class LLScriptType		*type;
//	class LLScriptConstant		*constant;
//	class LLScriptIdentifier	*identifier;
//	class LLScriptSimpleAssignable	*assignable;
//	class LLScriptGlobalVariable	*global;
//	class LLScriptEvent		*event;
//	class LLScriptEventHandler	*handler;
//	class LLScriptExpression	*expression;
//	class LLScriptStatement		*statement;
//	class LLScriptGlobalFunctions	*global_funcs;
//	class LLScriptFunctionDec	*global_decl;
//	class LLScriptState		*state;
//	class LLScritpGlobalStorage	*global_store;
//	class LLScriptScript		*script;
}STypeParser;
 
// define the type for flex and bison
#define YYSTYPE STypeParser


#ifndef excludeLexer
    #include "LuaSL_lexer.h"
#endif


/**
 * @brief structure given as argument to the reentrant 'yyparse' function.
 */
typedef struct tagSParserParam
{
        yyscan_t scanner;
        SExpression *expression;
}SParserParam;
 
// the parameter name (of the reentrant 'yyparse' function)
// data is a pointer to a 'SParserParam' structure
#define YYPARSE_PARAM data
 
// the argument for the 'yylex' function
#define YYLEX_PARAM   ((SParserParam*)data)->scanner

/**
 * @brief It creates an identifier
 * @param value The number value
 * @return The expression or NULL in case of no memory
 */
SExpression* createNumber(int value);

/**
 * @brief It creates an operation
 * @param type The operation type
 * @param left The left operand
 * @param right The right operand
 * @return The expression or NULL in case of no memory
 */
SExpression* createOperation(EOperationType type, SExpression *left, SExpression *right);

/**
 * @brief Deletes a expression
 * @param b The expression
 */
void deleteExpression(SExpression *b);

SExpression *getAST(const char *expr);

int evaluate(SExpression *e);

int yyerror(const char *msg);
int yyparse(void *param);

#include "LuaSL_yaccer.tab.h"


#endif // __EXPRESSION_H__