ref: ad872eeb19b4fcc41a5d34750ca6cdcf88a39795
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; }