コード例 #1
0
ファイル: pl0-ll-parser02.c プロジェクト: ryo33/pl0dash
void parse_Statement() {
  printf("Enter Statement\n");
  if (nextToken == T_ID) { /* 代入文 */
    nextToken = getToken();
    if (nextToken != T_COLEQ) pl0parse_error("not :=");
    nextToken = getToken();
    parse_Expression();
  } else if (nextToken == T_BEGIN) { /* begn ~ end */
    nextToken = getToken();
    parse_StatementList();
    if (nextToken != T_END) pl0parse_error("not end");
    nextToken = getToken();
  } else if (nextToken == T_IF) { /* if then */
    nextToken = getToken();
    parse_Condition();
    if (nextToken != T_THEN) pl0parse_error("not then");
    nextToken = getToken();
    parse_Statement();
  } else if (nextToken == T_WHILE)  { /* while do */
    nextToken = getToken();
    parse_Condition();
    if (nextToken != T_DO) pl0parse_error("not do");
    nextToken = getToken();
    parse_Statement();
  } else if (nextToken == T_RETURN) { /* return */
    nextToken = getToken();
    parse_Expression();
  } else if (nextToken == T_WRITE) { /* write */
    nextToken = getToken();
    parse_Expression();
  } else if (nextToken ==  T_WRITELN) { /* writeln */
    /* writeln の処理 */
    nextToken = getToken();
  } else {
  }
}
コード例 #2
0
void parse_Statement() {
  printf("Enter Statement\n");
  if (nextToken == T_ID) { /* 代入文 */
    nextToken = getToken();
    if (nextToken != T_COLEQ) pl0_error(yytext, line_no, ":=がない");
    nextToken = getToken();
    parse_Expression();
  } else if (nextToken == T_BEGIN) { /* begn ~ end */
    nextToken = getToken();
    parse_StatementList();
    if (nextToken != T_END) pl0_error(yytext, line_no, "endがない");
    nextToken = getToken();
  } else if (nextToken == T_IF) { /* if then */
    nextToken = getToken();
    parse_Condition();
    if (nextToken != T_THEN) pl0_error(yytext, line_no, "thenがない");
    nextToken = getToken();
    parse_Statement();
  } else if (nextToken == T_WHILE)  { /* while do */
    nextToken = getToken();
    parse_Condition();
    if (nextToken != T_DO) pl0_error(yytext, line_no, "doがない");
    nextToken = getToken();
    parse_Statement();
  } else if (nextToken == T_RETURN) { /* return */
    nextToken = getToken();
    parse_Expression();
  } else if (nextToken == T_WRITE) { /* write */
    nextToken = getToken();
    parse_Expression();
  } else if (nextToken ==  T_WRITELN) { /* writeln */
    /* writeln の処理 */
    nextToken = getToken();
  }
  printf("Exit  Statement\n");
}