Radicalc  Diff

Differences From Artifact [6fe964fe34]:

  • File bootstrap/main.c — part of check-in [93a1d09191] at 2017-07-15 23:31:50 on branch trunk — tiny bit of refactoring and documenting (user: athaudia size: 13960)

To Artifact [6cb00cb1d8]:

  • File bootstrap/main.c — part of check-in [71d330ca80] at 2017-07-16 00:11:00 on branch trunk — refactored p_fun_param out of p_fun (user: athaudia size: 14044)


1
2
3
4
5
6
7

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

/******************************************************************************/
/*                                                                            */
>







1
2
3
4
5
6
7
8
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

/******************************************************************************/
/*                                                                            */
315
316
317
318
319
320
321
















322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
	switch(tokens[parse_pos].type) {
		default:
			node = p_expr();
			expect(TOK_NEWLINE);
	}
	return node;
}

















struct function*
p_fun() {
	struct function* fun = function_new();
	expect(TOK_FUN);
	fun->name = expect(TOK_IDENT)->str;
	expect(TOK_PAREN_OPEN);
	if(tokens[parse_pos].type != TOK_PAREN_CLOSE) {
		for(;;) {
			char* name;
			char* type;
			name = expect(TOK_IDENT)->str;
			expect(TOK_COLON);
			type = expect(TOK_IDENT)->str;
			function_add_param(fun, name, type);
			if(tokens[parse_pos].type == TOK_COMMA)
				expect(TOK_COMMA);
			else
				break;
		}
	}
	expect(TOK_PAREN_CLOSE);
	if(tokens[parse_pos].type == TOK_COLON) {
		expect(TOK_COLON);
		fun->return_type_str = expect(TOK_IDENT)->str;
	}
	expect(TOK_NEWLINE);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








<
<
<
<
<
<
|
<
<
<
<
<







316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346






347





348
349
350
351
352
353
354
	switch(tokens[parse_pos].type) {
		default:
			node = p_expr();
			expect(TOK_NEWLINE);
	}
	return node;
}

bool
p_fun_param(struct function* fun) {
	char* name;
	char* type;
	name = expect(TOK_IDENT)->str;
	expect(TOK_COLON);
	type = expect(TOK_IDENT)->str;
	function_add_param(fun, name, type);
	if(tokens[parse_pos].type == TOK_COMMA) {
		expect(TOK_COMMA);
		return true;
	}
	else
		return false;
}

struct function*
p_fun() {
	struct function* fun = function_new();
	expect(TOK_FUN);
	fun->name = expect(TOK_IDENT)->str;
	expect(TOK_PAREN_OPEN);
	if(tokens[parse_pos].type != TOK_PAREN_CLOSE) {






		while(p_fun_param(fun)) ;





	}
	expect(TOK_PAREN_CLOSE);
	if(tokens[parse_pos].type == TOK_COLON) {
		expect(TOK_COLON);
		fun->return_type_str = expect(TOK_IDENT)->str;
	}
	expect(TOK_NEWLINE);