Beispiel #1
0
int main(int argc, char *argv[]){
    FILE *input = fopen(argv[1], "r");
    FILE *output;
    if(input == NULL) return -1;
    token_list *tl = lex(input);
    fclose(input);

    if(correctTokenList(tl) != 1)
	return 0;
    if(tl == NULL){
	fprintf(stderr, "scanning error\n");
	fflush(NULL);
	return 0;
    }
    program_node *pn = parse(tl);
    freeTokenList(tl);

    if(pn){
	int tmp;
	output = fopen("result.k15", "w");
	tmp =  checkSemantics(pn, output);
	fclose(output);
	return tmp;
    }

    return 0;
}
Beispiel #2
0
void evaluateExpressions() {
    int degree = 1;
    char *varName;
  char *ar;
  List tl, tl1; 
  double w;
  printf("give an expression: ");
  ar = readInput();
  while (ar[0] != '!') {
    tl = tokenList(ar); 
    printf("\nthe token list is ");
    printList(tl);
    tl1 = tl;
    if ( valueExpression(&tl1,&w) && tl1==NULL ) {
               /* there may be no tokens left */ 
      printf("this is a numerical expression with value %g\n",w); 
    } else {
      tl1 = tl;
      if ( acceptExpression(&tl1, varName, &degree) && tl1 == NULL ) {
        printf("this is an arithmetical expression\n"); 
      } else {
        printf("this is not an expression\n"); 
      }
    }
    free(ar);
    freeTokenList(tl);
    printf("\ngive an expression: ");
    ar = readInput();
  }
  free(ar);
  printf("good bye\n");
}
Beispiel #3
0
void recognizeExpressions() {
  char *ar;
  List tl, tl1;  
  printf("give an expression: ");
  ar = readInput();
  while (ar[0] != '!') {
    tl = tokenList(ar); 
    printf("the token list is ");
    printList(tl);
    tl1 = tl;
    if ( acceptExpression(&tl1) && tl1 == NULL ) {
      printf("this is an expression\n"); 
    } else {
      printf("this is not an expression\n"); 
    }
    free(ar);
    freeTokenList(tl);
    printf("\ngive an expression: ");
    ar = readInput();
  }
  free(ar);
  printf("good bye\n");
}