Commits

PioneerAxon committed 280443b

Added static and const identifire.

Fixed: static functions.
Fixed: const arguments.
Fixed: code style for functions.

  • Participants
  • Parent commits b86e6bd

Comments (0)

Files changed (6)

 /*---------END TEMP code---------*/
 
 /* Insert generated token to the LexerState structure. */
-LexerToken*
-l_insert_token(LexerState* state, LexerTokenType type)
+static LexerToken*
+l_insert_token(LexerState* state, const LexerTokenType type)
 {
 	state->tokens = (LexerToken *) realloc (state->tokens, (state->token_count + 1) * sizeof (LexerToken));
 	assert (state->tokens != NULL);
 }
 
 /* Generates next token from pre-lexer stream and call l_insert_token() to insert it at the end. */
-LexerToken*
+static LexerToken*
 l_insert_next_token(LexerState* lstate)
 {
 	PreLexerState* state = lstate->prelexer;
 }
 
 /* Call l_insert_next_token() as many times as needed to completely tokenize the string. */
-void l_insert_all_tokens(LexerState* state)
+static void
+l_insert_all_tokens(LexerState* state)
 {
 	LexerToken* token;
 	while (1) {
 }
 
 /* Create a lexer state from given input string. This will take care of pre-lexer state. */
-LexerState *l_create_lexer(gchar* input)
+LexerState*
+l_create_lexer(const gchar* input)
 {
 	LexerState* ret;
 	ret = (LexerState *) malloc (sizeof (LexerState));
 }
 
 /* Destroy lexer state and free memory. */
-void l_destroy_lexer(LexerState* state)
+void
+l_destroy_lexer(LexerState* state)
 {
 	int l;
 	pl_destroy_scanner (state->prelexer);
 }
 
 /* Get next token interface. Will be called by parser to get pointer to next token in token stream. */
-LexerToken *l_get_next_token(LexerState* state)
+LexerToken*
+l_get_next_token(LexerState* state)
 {
 	/* Return PL_EOS token after token stream reaches to its end. */
 	if (state->next_token >= state->token_count)
 }
 
 /* Roll back one lexer token. */
-void l_roll_back(LexerState* state)
+void
+l_roll_back(LexerState* state)
 {
 	if (state->next_token > 0)
 		state->next_token--;
 } LexerState;
 
 /* Create a new LexerState object and fill the dynamic array with tokens. */
-LexerState *l_create_lexer (gchar *);
+LexerState *l_create_lexer (const gchar *);
 
 /* Destroy LexerState object and free up space. */
 void l_destroy_lexer (LexerState *);

File src/parser.c

 #include<parserfunc.h>
 
 /* Converts LexerTokenType to Precedence value. */
-guint p_get_precedence (LexerTokenType type)
+static guint
+p_get_precedence (LexerTokenType type)
 {
 	/* WARNING: This function doesn't work for Unary Plus and Unary Minus. */
 	if (type == T_ADD
 }
 
 /* Return associativity of specific token type from precedence. */
-Associativity p_get_associativity_p (Precedence type)
+static Associativity
+p_get_associativity_p (Precedence type)
 {
 	if (type == P_Boolean
 	 || type == P_Divide
 }
 
 /* Return associativity of specific token by converting it to precedence first. */
-Associativity p_get_associativity (LexerToken* token)
+static Associativity
+p_get_associativity (LexerToken* token)
 {
 	return p_get_associativity_p (p_get_precedence (token->token_type));
 }
 
 /* Generate precedence for a node from precedence value. Includes depth_level. */
-guint p_make_precedence_p (ParserState* state, Precedence p)
+static guint
+p_make_precedence_p (ParserState* state, Precedence p)
 {
 	return (p + (state->depth_level * P_Depth));
 }
 
 /* Generate precedence for a node from lexer token type. Includes depth_level. */
-guint p_make_precedence_t (ParserState* state, LexerTokenType type)
+static guint
+p_make_precedence_t (ParserState* state, LexerTokenType type)
 {
 	return (p_get_precedence (type) + (state->depth_level * P_Depth));
 }
 
 /* Allocate and create a new node. */
-ParseNode* p_create_node (ParserState* state, LexerToken* token, guint precedence, Associativity associativity, void* value, void* (*function) (ParseNode*))
+static ParseNode*
+p_create_node (ParserState* state, LexerToken* token, guint precedence, Associativity associativity, void* value, void* (*function) (ParseNode*))
 {
 	ParseNode* new;
 	new = (ParseNode*) malloc (sizeof (ParseNode));
 }
 
 /* Compares two nodes to decide, which will be parent and which willbe child. */
-gint p_cmp_nodes (ParseNode* left, ParseNode* right)
+static gint
+p_cmp_nodes (ParseNode* left, ParseNode* right)
 {
 	/* Return values.
 	   1 = right goes up (near root) in parse tree.
 }
 
 /* Unified interface (unary and binary nodes) to insert node into parse tree. */
-void p_insert_into_tree_all (ParserState* state, ParseNode* node, guint unary_function)
+static void
+p_insert_into_tree_all (ParserState* state, ParseNode* node, guint unary_function)
 {
 	if (state->root == NULL) {
 		state->root = node;
 }
 
 /* Insert binary node into the parse tree. */
-void p_insert_into_tree (ParserState* state, ParseNode* node)
+static void
+p_insert_into_tree (ParserState* state, ParseNode* node)
 {
 	p_insert_into_tree_all (state, node, 0);
 }
 
 /* Insert unary node into the parse tree. */
-void p_insert_into_tree_unary (ParserState* state, ParseNode* node)
+static void
+p_insert_into_tree_unary (ParserState* state, ParseNode* node)
 {
 	p_insert_into_tree_all (state, node, 1);
 }
 
 /* Recursive call to free every node of parse-tree. */
-void p_destroy_all_nodes (ParseNode* node)
+static void
+p_destroy_all_nodes (ParseNode* node)
 {
 	if (node == NULL)
 		return;
 }
 
 /* Create parser state. */
-ParserState* p_create_parser (gchar* input)
+ParserState*
+p_create_parser (const gchar* input)
 {
 	ParserState* state;
 	state = (ParserState*) malloc (sizeof (ParserState));
 }
 
 /* Prints debugging information on terminal to check if parse tree is constructed properly or not. */
-void p_display (ParseNode* node)
+static void
+p_display (ParseNode* node)
 {
 	/* If node is allocated, print it's information. */
 	if (node) {
 		printf (".\n");
 }
 
-guint statement (ParserState*);
+static guint statement (ParserState*);
 /* Start parsing input string. And call evaluate on success. */
-guint p_parse (ParserState* state)
+guint
+p_parse (ParserState* state)
 {
 	guint ret;
 	LexerToken* token;
 }
 
 /* Destroy parser state. */
-void p_destroy_parser (ParserState* state)
+void
+p_destroy_parser (ParserState* state)
 {
 	/* If state has a parse tree, destroy it first. */
 	if (state->root) {
 
 /* LL (*) parser. Lookahead count depends on tokens. Handle with care. :P */
 
-guint expression (ParserState* state);
-guint expression_1 (ParserState* state);
-guint expression_2 (ParserState* state);
-guint term (ParserState* state);
-guint unit (ParserState* state);
-guint variable (ParserState* state);
-guint term (ParserState* state);
-guint term_2 (ParserState* state);
-
-guint statement (ParserState* state)
+static guint expression (ParserState* state);
+static guint expression_1 (ParserState* state);
+static guint expression_2 (ParserState* state);
+static guint term (ParserState* state);
+static guint unit (ParserState* state);
+static guint variable (ParserState* state);
+static guint term (ParserState* state);
+static guint term_2 (ParserState* state);
+
+static guint
+statement (ParserState* state)
 {
 	LexerToken* token;
 	LexerToken* token_old;
 	}
 }
 
-guint unit (ParserState* state)
+static guint
+unit (ParserState* state)
 {
 	LexerToken* token;
 	LexerToken* token_old;
 	}
 }
 
-guint expression (ParserState* state)
+static guint
+expression (ParserState* state)
 {
 	if (!expression_1 (state))
 		return 0;
 	return 1;
 }
 
-guint expression_1 (ParserState* state)
+static guint
+expression_1 (ParserState* state)
 {
 	LexerToken* token;
 	ParseNode* node;
 	}
 }
 
-guint expression_2 (ParserState* state)
+static guint
+expression_2 (ParserState* state)
 {
 	LexerToken* token;
 	ParseNode* node;
 	}
 }
 
-guint variable (ParserState* state)
+static guint
+variable (ParserState* state)
 {
 	LexerToken* token;
 	LexerToken* token_old;
 	}
 }
 
-guint term (ParserState* state)
+static guint
+term (ParserState* state)
 {
 	LexerToken* token;
 	LexerToken* token_old;
 	}
 }
 
-guint term_2 (ParserState* state)
+static guint
+term_2 (ParserState* state)
 {
 	LexerToken* token;
 	ParseNode* node;

File src/parser.h

 } ParserState;
 
 /* Create ParserState object. */
-ParserState* p_create_parser (gchar*);
+ParserState* p_create_parser (const gchar*);
 
 /* Destroy ParserState object. */
 void p_destroy_parser (ParserState*);

File src/prelexer.c

 
 /* Creates a scanner state which will be useful for accessing the lexer later. */
 PreLexerState *
-pl_create_scanner(gchar* input)
+pl_create_scanner(const gchar* input)
 {
 	PreLexerState *state;
 	assert (input != NULL);
 
 /* Get marked substring. To be used for error reporting. */
 gchar *
-pl_get_marked_substring(PreLexerState * state)
+pl_get_marked_substring(const PreLexerState * state)
 {
 	return g_strndup (state->stream + state->mark_index, state->next_index - state->mark_index);
 }
 
 /* Compares a list of strings with given unichar. To be used by pl_get_next_token() only. */
-gint pl_compare_all(gunichar ch, gint count, gchar *arr[])
+static gint
+pl_compare_all(const gunichar ch, const gint count, gchar *arr[])
 {
 	gint l;
 	for (l = 0; l < count; l++) {

File src/prelexer.h

 } LexerTokenType;
 
 /* Creates a scanner state. Useful when multiple scanners are in action. */
-PreLexerState *pl_create_scanner (gchar *);
+PreLexerState *pl_create_scanner (const gchar *);
 
 /* Destroy and free memory used by LexerState object. */
 void pl_destroy_scanner (PreLexerState *);
 void pl_set_marker (PreLexerState *);
 
 /* Get marked substring. To be used for error reporting. */
-gchar *pl_get_marked_substring (PreLexerState *);
+gchar *pl_get_marked_substring (const PreLexerState *);
 
 /* Get next Pre-Lexer token from stream. */
 LexerTokenType pl_get_next_token (PreLexerState *);