Пример #1
0
void CaseStat()
{
  /*
    CaseStat -> CASE expr OF 
                case { '|' case } [ ELSE StatSeq ]END
  */

  if ( debugMode) printf( "In CaseStat\n");
  accept( CASE_SYM, 164);
  expr();
  accept( OF_SYM, 158);
  Case();

  while ( sym == OR_SYM)
  {
    writesym();
    nextsym();
    Case();
  }

  if ( sym == ELSIF_SYM)
  {
    writesym();
    nextsym();
    StatSeq();
  }

  accept( END_SYM, 155);
  if ( debugMode) printf( "Out CaseStat\n");

}
Пример #2
0
void Receiver()
{
  /*
    Receiver -> '(' [ VAR ] ident : ident ')'
  */

  if ( debugMode) printf( "In Receiver\n");
  accept( lparen, 143);
  if ( sym == VAR_SYM)
  {
    writesym();
    nextsym();
  }
  accept( ident, 124);
  accept( colon, 153);
  if ( sym == ident || sym == REAL_SYM || sym == INTEGER_SYM) {
    writesym();
    nextsym();
  }
  else
  {
    error( ident, 124);
  }
  accept( rparen, 142);
  if ( debugMode) printf( "Out Receiver\n");
}
Пример #3
0
void IfStat()
{
  /*
    IfStat -> IF expr THEN StatSeq
              { ELSIF expr THEN StatSeq }
              [ ELSE StatSeq ] END
  */

  if ( debugMode) printf( "In IfStat\n");
  accept( IF_SYM, 163);
  expr();
  accept( THEN_SYM, 136);
  StatSeq();

  while ( sym == ELSIF_SYM)
  {
    writesym();
    nextsym();
    expr();
    accept( THEN_SYM, 136);
    StatSeq();
  }

  if ( sym == ELSE_SYM)
  {
    writesym();
    nextsym();
    StatSeq();
  }

  accept( END_SYM, 155);
  if ( debugMode) printf( "Out IfStat\n");
}
Пример #4
0
void WithStat()
{
	/*
		WithStat -> WITH guard DO StatSeq
      				{ | guard DO StatSeq }
      				[ ELSE StatSeq ] END
	*/

  if ( debugMode) printf( "In WithStat\n");
  accept( WITH_SYM, 172);
  guard();
  accept( DO_SYM, 166);
  StatSeq();

  while ( sym == OR_SYM)
  {
    writesym();
    nextsym();
    guard();
    accept( DO_SYM, 166);
    StatSeq();
  } 

  if ( sym == ELSE_SYM) 
  {
    writesym();
    nextsym();
    StatSeq();
  }     			

  accept( END_SYM, 155);	
  if ( debugMode) printf( "Out WithStat\n");
}
Пример #5
0
void FormParams()
{
  /*
    FormParams -> '(' [ FormParamSect { ; FormParamSect } ] ')' [ : qualident ]
  */

  if ( debugMode) printf( "In FormParams\n");
  accept( lparen, 143);

  if ( sym != rparen) {
    FormParamSect();
    while ( sym == semic)
    {
      writesym();
      nextsym();
      FormParamSect();
    }
  }

  accept( rparen, 142);

  if ( sym == colon)
  {
    writesym();
    nextsym();
    qualident();
  }
  if ( debugMode) printf( "Out FormParams\n");
}
Пример #6
0
void FormParamSect()
{
  /*
    FormParamSect -> [ VAR ] ident { , ident } : FormType
  */

  if ( debugMode) printf( "In FormParamSect\n");
  if ( sym == VAR_SYM)
  {
    writesym();
    nextsym();
  }

  accept( ident, 124);
  while ( sym == comma)
  {
    writesym();
    nextsym();
    accept( ident, 1);
  }

  accept( colon, 153);
  FormType();
  if ( debugMode) printf( "Out FormParamSect\n");
}
Пример #7
0
void ScaleFac()
{
	/*
		ScaleFac -> ( E  | D ) [ + | - ] digit { digit }
	*/

  if ( debugMode) printf( "In ScaleFac\n");
	if ( strcmp( idbuff, "E") == 0 || strcmp( idbuff, "D") == 0)
	{
    writesym();
		nextsym();
	}
	else
	{
		error( invalid_sym, 1);
	}

	if ( sym == plus || sym == hyphen)
	{
    writesym();
		nextsym();
	}

	accept( int_number, 122); // this is digit { digit }
  if ( debugMode) printf( "Out ScaleFac\n");
}
Пример #8
0
void ProcBody()
{
  /*
    ProcBody -> DeclSeq [ BEGIN StatSeq ] [ RETURN expr ] END
  */

  if ( debugMode) printf( "In ProcBody\n");
  DeclSeq();
  if ( sym == BEGIN_SYM)
  {
    writesym();
    nextsym();
    StatSeq();
  }

  if ( sym == RETURN_SYM)
  {
    writesym();
    nextsym();
    expr();
  }

  accept( END_SYM, 155);
  if ( debugMode) printf( "Out ProcBody\n");
}
Пример #9
0
void qualident()
{
  /*
    qualident -> [ ident . ] ident

    This can be rewritten equivalently as:

    qualident -> ident [ . ident ]
  */

  if ( debugMode) printf( "In qualident\n");
  if ( sym == INTEGER_SYM || sym == REAL_SYM)
  {
    writesym();
    nextsym();
  }
  else
  {
    accept( ident, 124);
  }

  if ( sym == per)
  {
    writesym();
    nextsym();
    accept( ident, 124);
  }
  if ( debugMode) printf( "Out qualident\n");
}
Пример #10
0
void LabelRange()
{
  /*
    LabelRange -> label [ .. label ]
  */

  if ( debugMode) printf( "In LabelRange\n");
  if ( isLabel( sym))
  {
    writesym();
    nextsym();
  }
  else 
  {
    error( invalid_sym, 1);
    return;
  }

  if ( sym == doubledot)
  {
    if ( isLabel( sym))
    {
      writesym();
      nextsym();
    }
    else 
    {
      error( invalid_sym, 1);
      return;
    } 
  }
  if ( debugMode) printf( "Out LabelRange\n");
}
Пример #11
0
void ForStat()
{
  /*
    ForStat -> FOR ident := expr TO expr [ BY ConstExpr ] DO StatSeq END
  */

  if ( debugMode) printf( "In ForStat\n");
  accept( FOR_SYM, 169);
  accept( ident, 124);
  accept( assign, 133);
  expr();
  accept( TO_SYM, 161);

  if ( sym == BY_SYM)
  {
    writesym();
    nextsym();
    ConstExpr();
  }

  accept( DO_SYM, 166);
  StatSeq();
  accept( END_SYM, 155);
  if ( debugMode) printf( "Out ForStat\n");
}
Пример #12
0
// run the code
int main( int argc, char **argv) 
{
   ch = ' ';
   InitCompile();

   // arg[1] is the first command line arg

   if ( argc != 2) 
   {
       fputs( "\nError exiting now\nUsage: ./a.out fileToScan\n\n", stdout);
       exit( 0);
   }
   
   fileIn = fopen( argv[ 1], "r");

   /*do 
   {
     nextsym();
     writesym();
    } while( sym != eof_sym); 
   */

    nextsym();
    module();

   return(0);
} // end main
Пример #13
0
void RecType()
{
  /*
    RecType -> RECORD [ '(' BaseType ')' ] [ FieldListSeq ] END
  */

  if ( debugMode) printf( "In RecType\n");
  accept( RECORD_SYM, 159);
  if ( sym == lparen)
  {
    writesym();
    nextsym();
    BaseType();
    accept( rparen, 142);
  }

  if ( sym != END_SYM)
  {
    FieldListSeq();
  }

  accept( END_SYM, 155);

  if ( debugMode) printf( "Out RecType\n");
}
Пример #14
0
void WhileStat()
{
  /*
    WhileStat -> WHILE expr DO StatSeq
                 { ELSIF expr DO StatSeq } END
  */

  if ( debugMode) printf( "In WhileStat\n");
  accept( WHILE_SYM, 165);
  expr();
  accept( DO_SYM, 166);
  StatSeq();

  while ( sym == ELSIF_SYM)
  {
    writesym();
    nextsym();
    expr();
    accept( DO_SYM, 166);
    StatSeq();
  }

  accept( END_SYM, 155);
  if ( debugMode) printf( "Out WhileStat\n");
}
Пример #15
0
static void expect(TSym s, Lexer *l)
{
  if (l->tok.sym == s) {
    nextsym(l);
    return;
  }
  fprintf(stderr, "error: expected %s, got %s\n", names[s], names[l->tok.sym]);
  exit(1);
}
Пример #16
0
bool accept( Token expectedsym, int errnum) 
{
	if ( sym == expectedsym) 
	{
    writesym();
		nextsym();
		return true;
	}
	else 
	{
		error( expectedsym, errnum);
    printf("\n*********\nexpectedsym: ");
    fputs( symname[ expectedsym][ 0], stdout);
    printf("\nActual sym : ");
    writesym();
    printf("*********\n");
    nextsym();
		return false;
	}
}
Пример #17
0
void SimplExpr() {
	/* 
		SimplExpr -> [ + | - ] term { addop term }
	*/

  if ( debugMode) printf( "In SimplExpr\n");
	if ( sym == plus || sym == hyphen)
	{
    writesym();
		nextsym();
	}

	term();

	while ( isAddOp( sym))
	{
		nextsym();
		term();
	}
  if ( debugMode) printf( "Out SimplExpr\n");
}
Пример #18
0
void stat()
{
  /*
    stat -> [ AssignStat | ProcCall | IfStat | CaseStat | WhileStat | 
              RepeatStat | ForStat ]
  */

  if ( debugMode) printf( "In stat\n");
  if ( sym == IF_SYM)
  {
    IfStat();
  }
  else if ( sym == CASE_SYM)
  {
    CaseStat();
  }
  else if ( sym == WHILE_SYM)
  {
    WhileStat();
  }
  else if ( sym == REPEAT_SYM)
  {
    RepeatStat();
  }
  else if ( sym == FOR_SYM)
  {
    ForStat();
  }
  else if ( sym == ident)
  {
    designator();
    if ( sym == assign)
    {
      // then it was AssignStat
      writesym();
      nextsym();
      expr();
    }
    else 
    {
      // then it was ProcCall
      if ( sym == lparen)
      {
        ActParams();
      }
    }
  }
  if ( debugMode) printf( "Out stat\n");
}
Пример #19
0
void selector()
{
	/*
		selector -> . ident 
                | '[' ExprList ']' 
                | ^ 
                | '(' qualident ')'
	*/

  if ( debugMode) printf( "In selector\n");

  switch( sym)
  {
  	case per:
  		nextsym();
  		accept( ident, 1);
  		break;
  	case lbrac:
  		nextsym();
  		ExprList();
  		accept( rbrac, 147);
  		break;
  	case carat:
  		nextsym();
  		break;
  	// case lparen:
  	// 	nextsym();
  	// 	qualident();
  	// 	accept( rparen, 142);
  		break;
  	default:
  		error( invalid_sym, 1);
  		break;
  }
  if ( debugMode) printf( "Out selector\n");
}
Пример #20
0
void FieldListSeq()
{
  /*
    FieldListSeq -> FieldList { ; FieldList }
  */

  if ( debugMode) printf( "In FieldListSeq\n");
  FieldList();
  while ( sym == semic)
  {
    writesym();
    nextsym();
    FieldList();
  }
  if ( debugMode) printf( "Out FieldListSeq\n");
}
Пример #21
0
void IdentList()
{
  /*
    IdentList -> identdef { , identdef }
  */

  if ( debugMode) printf( "In IdentList\n");
  identdef();
  while( sym == comma)
  {
    writesym();
    nextsym();
    identdef();
  }
  if ( debugMode) printf( "Out IdentList\n");
}
Пример #22
0
void ExprList() {
	/*
		ExprList -> expr { , expr }
	*/

  if ( debugMode) printf( "In expr\n");
	expr();

	while( sym == comma)
	{
    writesym();
		nextsym();
		expr();
	}
  if ( debugMode) printf( "Out expr\n");
}
Пример #23
0
void elem()
{
	/*
		elem -> expr [ .. expr ]
	*/

  if ( debugMode) printf( "In elem\n");
	elem();

	if ( sym == doubledot)
	{
    writesym();
		nextsym();
		elem();
	}
  if ( debugMode) printf( "Out elem\n");
}
Пример #24
0
void term() 
{
	/*
		term -> factor { mulop factor }
	*/

  if ( debugMode) printf( "In term\n");
	factor();

	while ( isMulOp( sym))
	{
    writesym();
		nextsym();
		factor();
	}
  if ( debugMode) printf( "Out term\n");
}
Пример #25
0
void expr()
{
	/*
		expr -> SimplExpr [ relop SimplExpr ]
	*/

  if ( debugMode) printf( "In expr\n");
	SimplExpr();

	while ( isRelOp( sym))
	{
    writesym();
		nextsym();
		SimplExpr();
	}
  if ( debugMode) printf( "Out expr\n");
}
Пример #26
0
void StatSeq()
{
  /*
    StatSeq -> stat { ; stat }
  */

  if ( debugMode) printf( "In StatSeq\n");
  stat();

  while ( sym == semic)
  {
    writesym();
    nextsym();
    stat();
  }
  if ( debugMode) printf( "Out StatSeq\n");
}
Пример #27
0
void CaseLabList()
{
  /*
    CaseLabList -> LabelRange { , LabelRange }
  */

  if ( debugMode) printf( "In CaseLabList\n");
  LabelRange();

  while ( sym == comma)
  {
    writesym();
    nextsym();
    LabelRange();
  }
  if ( debugMode) printf( "Out CaseLabList\n");
}
Пример #28
0
void identdef()
{
  /*
    identdef -> ident [ * | - ]
  */

  if ( debugMode) printf( "In identdef\n");

  accept( ident, 124);
  if ( sym == star || sym == hyphen)
  {
    writesym();
    nextsym();
  }

  if ( debugMode) printf( "Out identdef\n");
}
Пример #29
0
void import() 
{
	/*
		import -> ident [ := ident ]
	*/

  if ( debugMode) printf( "In import\n");

	accept( ident, 124);
	if ( sym == assign)
	{
    writesym();
    nextsym();
		accept( ident, 124);
	}

  if ( debugMode) printf( "Out import\n");
}
Пример #30
0
void factor()
{
	/*
		factor -> num | string | NIL | TRUE | FALSE
              | set | designator [ ActParams ] 
              | '(' expr ')'
	*/

  if ( debugMode) printf( "In factor\n");
  if ( isNumber( sym)) {
    writesym();
  	nextsym();
  }
  else {
  	switch( sym)
  	{
  		case string:
        writesym();
  			nextsym();
  			break;
  		case NIL_SYM:
        writesym();
  			nextsym();
  			break;
  		case TRUE_SYM:
        writesym();
  			nextsym();
  			break;
  		case FALSE_SYM:
        writesym();
  			nextsym();
  			break;
      case lparen:
        writesym();
        nextsym();
        expr();
        accept( rparen, 1);
        break;
      case lcurb:
        set();
        break;
  		default:
  			designator();
        if ( sym == lparen)
        {
          ActParams();
        }
  	}
  }
  if ( debugMode) printf( "Out factor\n");
}