summaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/parser.c b/parser.c
index 51eb436..9ce68f1 100644
--- a/parser.c
+++ b/parser.c
@@ -42,6 +42,7 @@ enum {
static Biobuf *parsein;
static Token lookahead;
static Module *currentmod;
+static VarName *varnames;
void nexttoken(void);
Term *fullterm(int, Rune *, Term *);
@@ -49,19 +50,22 @@ Term *term(void);
Term *listterm(int);
Term *curlybracketterm(void);
Term *compound(void);
+Term *parsevar(void);
Term *parseoperators(Term *);
void match(int);
void syntaxerror_parser(char *);
Term *parseterm(void);
Term *
-parse(Biobuf *bio, Module *mod)
+parse(Biobuf *bio, Module *mod, VarName **vns)
{
parsein = bio;
currentmod = mod;
+ varnames = nil;
nexttoken();
Term *result = parseterm();
+ *vns = varnames;
if(result){
result = copyterm(result, &clausenr);
clausenr++;
@@ -107,8 +111,7 @@ term(void)
result = compound();
break;
case VarTok:
- result = mkvariable(lookahead.text);
- match(VarTok);
+ result = parsevar();
break;
case IntTok:
result = mkinteger(lookahead.ival);
@@ -202,6 +205,29 @@ compound(void)
}
Term *
+parsevar(void)
+{
+ Rune *name = lookahead.text;
+ match(VarTok);
+
+ VarName *vn;
+ uvlong i = 0;
+ for(vn = varnames; vn != nil; vn = vn->next, i++)
+ if(runestrcmp(vn->name, name) == 0 && !runestrcmp(vn->name, L"_") == 0){
+ vn->count++;
+ return copyterm(vn->var, nil);
+ }
+
+ VarName *new = gmalloc(sizeof(VarName));
+ new->name = name;
+ new->var = mkvariable();
+ new->count = 1;
+ new->next = varnames;
+ varnames = new;
+ return new->var;
+}
+
+Term *
parseoperators(Term *list)
{
int i;