#define MAX_GRAMMAR 378
#define PHRASE_BASE 515
int gram[MAX_GRAMMAR] = {
    2,     2,   519,   515,     0,     1,     0,     1,     1,   512,     1,     1,   512,     2,     4,   517, 
   58,   520,   549,     2,   520,   549,     7,     1,   534,     1,   525,     1,   526,     1,   531,     1, 
  529,     1,   521,     1,   522,     1,     2,   256,   517,     1,     8,   257,   517,    40,   524,    41, 
  549,   523,   258,     2,     3,   534,   549,   523,     0,     2,     2,   517,   524,     0,     1,     4, 
  259,   517,    61,   513,     1,     3,   260,   527,   528,     2,     3,   512,    61,   513,     1,   512, 
    2,     3,    44,   527,   528,     0,     2,     9,   261,   262,   517,    91,   513,    93,    61,   530, 
  549,     5,   262,   512,    91,   513,    93,     2,     2,   513,   530,     0,     1,     7,   263,   517, 
   40,   532,    41,    61,   543,     1,     2,   517,   533,     2,     3,    44,   517,   533,     0,     8, 
    4,   517,    61,   543,   542,     7,   517,    91,   552,    93,    61,   543,   542,     2,   541,   542, 
    1,   535,     1,   539,     3,   264,   543,   542,     2,   264,   542,     3,   265,   517,   542,     1, 
    6,   266,   543,   549,   536,   537,   267,     2,     3,   534,   549,   536,     0,     2,     2,   268, 
  536,     0,     2,     2,   268,   266,     1,   269,     1,     4,   270,   540,   271,   542,     2,     3, 
  534,   549,   540,     0,     1,     4,   517,    40,   567,    41,     2,     2,   266,   543,     0,     1, 
    2,   545,   544,     2,     3,   561,   545,   544,     0,     1,     2,   547,   546,     2,     3,   562, 
  547,   546,     0,     1,     2,   548,   550,     2,     1,    33,     0,     2,     1,    59,     0,     1, 
    2,   552,   551,     2,     2,   563,   552,     0,     1,     2,   554,   553,     2,     3,   564,   554, 
  553,     0,     1,     3,   557,   559,   558,     3,     1,    43,     1,    45,     2,    92,    92,     2, 
    1,    43,     1,    45,     2,     1,   556,     0,     2,     3,   556,   559,   558,     0,     1,     2, 
  566,   560,     2,     3,   565,   566,   560,     0,     1,     2,   124,   124,     1,     2,    38,    38, 
    9,     2,    60,    62,     2,    60,    61,     1,    60,     2,    62,    61,     1,    62,     2,    33, 
   61,     2,    61,    61,     1,    35,     1,    61,     2,     2,    60,    60,     2,    62,    62,     2, 
    1,    42,     1,    47,     5,     3,    40,   543,    41,     4,   517,    40,   567,    41,     4,   517, 
   91,   552,    93,     1,   517,     1,   569,     2,     2,   552,   568,     0,     2,     3,    44,   552, 
  568,     0,     3,     1,   513,     2,   555,   513,     1,   514, 
};

#define MAX_KEYWORD 16
char *keyword[MAX_KEYWORD] = { // Keywords are based at 256
  "extern", "proc", "end", "const", 
  "var", "initialised", "array", "let", 
  "return", "jump", "if", "finish", 
  "else", "elseif", "cycle", "repeat", 
  };

#define MAX_BIP 3
int BIP[MAX_BIP] = { // BIPs precede PHRASEs at 512 upwards
 1,  5,  3, 
};

#define MAX_PHRASE 58
#ifdef DEBUG_PARSER
// FOR DEBUGGING ONLY
char *phrasename[MAX_PHRASE] = { // Based at 512 upwards
  "IDENT", "NUM", "CHARLIT", "SSLIST", 
  "SYNTAXERROR", "EXISTINGVAR", "NEWVAR", "STATEMENT", 
  "SIMPLE", "EXTERN", "PROCDEF", "PROCBODY", 
  "ARGLIST", "CONSTDECL", "VARDECL", "VARDEC", 
  "VARDECLIST", "ARRAY", "INITLIST", "DEFFN", 
  "FORMALS", "RESTOFFORMALS", "SS", "IFSEQ", 
  "THENPART", "OPTELSEPART", "ELSEIFLIT", "LOOP", 
  "LOOPPART", "PROCCALL", "OPTIF", "BOOLEXPR", 
  "RESTOFBOOLTERM", "BOOLTERM", "RESTOFBOOLFACTOR", "BOOLFACTOR", 
  "OPTNOT", "OPTSEMI", "RELATION", "RESTOFRELATION", 
  "EXPR", "RESTOFEXPR", "SUM", "UNOP", 
  "ADDOP", "OPTADDOP", "RESTOFSUM", "TERM", 
  "RESTOFTERM", "OROP", "ANDOP", "RELOP", 
  "SHIFTOP", "MULOP", "FACTOR", "PARAMLIST", 
  "RESTOFPARAMLIST", "NUMBER", 
};
#endif /* DEBUG_PARSER */

int phrase_start[MAX_PHRASE-MAX_BIP] = {
    0,     5,     7,    10,    13,    22,    37,    41,    51,    57,    62,    68,    73, 
   80,    86,   103,   108,   117,   121,   127,   159,   167,   173,   178,   184,   190,   196,   202,   207, 
  211,   217,   221,   227,   231,   235,   239,   243,   248,   252,   258,   263,   271,   276,   280,   286, 
  290,   296,   300,   304,   328,   335,   340,   359,   364,   370, 
};

#define P_IDENT 512
#define P_NUM 513
#define P_CHARLIT 514
#define P_SSLIST 515
#define P_SYNTAXERROR 516
#define P_EXISTINGVAR 517
#define P_NEWVAR 518
#define P_STATEMENT 519
#define P_SIMPLE 520
#define P_EXTERN 521
#define P_PROCDEF 522
#define P_PROCBODY 523
#define P_ARGLIST 524
#define P_CONSTDECL 525
#define P_VARDECL 526
#define P_VARDEC 527
#define P_VARDECLIST 528
#define P_ARRAY 529
#define P_INITLIST 530
#define P_DEFFN 531
#define P_FORMALS 532
#define P_RESTOFFORMALS 533
#define P_SS 534
#define P_IFSEQ 535
#define P_THENPART 536
#define P_OPTELSEPART 537
#define P_ELSEIFLIT 538
#define P_LOOP 539
#define P_LOOPPART 540
#define P_PROCCALL 541
#define P_OPTIF 542
#define P_BOOLEXPR 543
#define P_RESTOFBOOLTERM 544
#define P_BOOLTERM 545
#define P_RESTOFBOOLFACTOR 546
#define P_BOOLFACTOR 547
#define P_OPTNOT 548
#define P_OPTSEMI 549
#define P_RELATION 550
#define P_RESTOFRELATION 551
#define P_EXPR 552
#define P_RESTOFEXPR 553
#define P_SUM 554
#define P_UNOP 555
#define P_ADDOP 556
#define P_OPTADDOP 557
#define P_RESTOFSUM 558
#define P_TERM 559
#define P_RESTOFTERM 560
#define P_OROP 561
#define P_ANDOP 562
#define P_RELOP 563
#define P_SHIFTOP 564
#define P_MULOP 565
#define P_FACTOR 566
#define P_PARAMLIST 567
#define P_RESTOFPARAMLIST 568
#define P_NUMBER 569