ref: 7d2f1a2d83df21f0520180537eba7f930bbdb7ee
dir: /aplan.c/
#include <u.h> #include <libc.h> #include <thread.h> #include "dat.h" #include "fns.h" Array * parseaplan(TokenList *tokens, char **errp) { /* TODO: write a recursive descent parser for APLAN here. */ Array *val; int ok = 1; for(uvlong i = 0; i < tokens->count; i++) ok &= tokens->tokens[i].tag == TokNumber; if(!ok){ *errp = "can only parse simple constants"; return nil; } if(tokens->count == 1){ val = allocarray(TypeNumber, 0, 1); setint(val, 0, tokens->tokens[0].num); }else{ val = allocarray(TypeNumber, 1, tokens->count); setshape(val, 0, tokens->count); for(uvlong i = 0; i < tokens->count; i++) setint(val, i, tokens->tokens[i].num); } return val; }