From 882a2958015f951030d0313f5c15270d80b5d1ce Mon Sep 17 00:00:00 2001 From: khamidou Date: Mon, 2 Mar 2009 11:32:43 +0100 Subject: [PATCH] added support for empty argument lists --- lexer.l | 5 +++-- macro.h | 4 ++++ parse.c | 26 ++++++++++++++++++++------ tokens.h | 2 +- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lexer.l b/lexer.l index 164aaf2..46aeacf 100644 --- a/lexer.l +++ b/lexer.l @@ -22,10 +22,11 @@ int yywrap() "{{" { return LBRACKET; } "}}" { return RBRACKET; } "," { return COMMA; } -"'" { return QUOTE; } +"'"|"\\" { return QUOTE; } "foreach" { return FOREACH; } +"define" { return DEFINE; } "$$" { return DOLDOL; } [ \t\n]+ { return SPACES; } -[a-zA-Z0-9,?!%*$^]+ { return WORD; } +[a-zA-Z0-9,?!%*:;$^]+ { return WORD; } diff --git a/macro.h b/macro.h index 8bac741..1d32050 100644 --- a/macro.h +++ b/macro.h @@ -21,6 +21,10 @@ struct croma_block { TAILQ_ENTRY(croma_block) blocks; }; +/* + blocks_head is our symbol tab. +*/ + TAILQ_HEAD(croma_blocks_head, croma_block) blocks_head; /* this function inserts a block at the end of the queue. diff --git a/parse.c b/parse.c index ab273a4..4c8a343 100644 --- a/parse.c +++ b/parse.c @@ -15,7 +15,8 @@ char *token_list[] = { "left parenthesis", "spaces", "comma", "quote", - "foreach", NULL}; + "foreach", + "define", NULL}; void expect(int t) @@ -30,8 +31,9 @@ void expect(int t) if (c != t) { printf("c %d, t %d, yytext %s\n", c, t, yytext); - fail("Expected token %s in input, got %s (at line %d).\n", - token_list+t, token_list+c, yylineno); +/* fail("Expected token %s in input, got %s (at line %d).\n", + token_list+t, token_list+c, yylineno); */ + fail("EPIC FAIL\n"); } } @@ -51,7 +53,11 @@ void yyparse(void) case FOREACH: foreach_expr(); break; - + + case DEFINE: + define_expr(); + break; + default: printf("%s", yytext); } @@ -98,6 +104,10 @@ void foreach_expr(void) free_block(b); } +void define_expr(void) +{ + +} void parse_arglist(struct croma_block *b) { @@ -113,7 +123,10 @@ void parse_arglist(struct croma_block *b) int i; - expect(WORD); + int c = yylex(); + + if (c == RPAREN) + return; /* FIXME : use realloc to implement infinite length parameter lists @@ -124,7 +137,8 @@ void parse_arglist(struct croma_block *b) if (b->parameters[i] == NULL) fail("Unable to alloc memory for text %s\n", yytext); - int c = yylex(); + c = yylex(); + while (c == SPACES) c = yylex(); diff --git a/tokens.h b/tokens.h index ac89f9d..7cf95f4 100644 --- a/tokens.h +++ b/tokens.h @@ -3,7 +3,7 @@ enum { LPAREN = 0, RPAREN, LBRACKET, RBRACKET, WORD, DOLDOL, SPACES, COMMA, QUOTE, - FOREACH, + FOREACH, DEFINE, }; -- 2.43.0