提交 ec5342d9 创建 作者: demo10's avatar demo10

modify

上级 4a7e5e28
流水线 #857 已失败 于阶段
用时 42 秒
image: "registry.cn-hangzhou.aliyuncs.com/engintime/ubuntu_16.04_program:latest"
stages:
- make
- code-analysis
- case1
- case2
- case3
- case4
- case5
- case6
- case7
- case8
variables:
TEACHERCHECK_REPO: "engintime/cp-lab/teachers-packet/Lab008.git"
.codecode-runner: &codecode-runner
tags:
- ubuntu-16.04
- short-job
make:
stage: make
<<: *codecode-runner
script:
- make
- ./app < input1.txt > user_output1.txt
- execscore.sh 40
only:
- master
code-analysis:
stage: code-analysis
<<: *codecode-runner
script:
- make
- mkdir -p build
- cppcheck -v --force --enable=all --xml -I./ ./ 2> ./build/cppcheck-report.xml
- bash -c 'find ./ -regex ".*\.c\|.*\.h" | vera++ -S -s -d -c ./build/vera-report.xml'
- valgrind --xml=yes --xml-file=./build/valgrind-report.xml ./app < input1.txt
- sonar-scanner -Dsonar.projectKey=ProjectKey-$CI_PROJECT_ID -Dsonar.projectName=$CI_PROJECT_NAME -Dsonar.links.homepage=$CI_PROJECT_URL -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.url=$CODECODE_PROTOCOL$CODECODE_DOMAIN
allow_failure: true
only:
- master
case1:
stage: case1
<<: *codecode-runner
script:
- make
- ./app < input1.txt > user_output1.txt
- diff output1.txt user_output1.txt -b -B -y -i --suppress-common-lines
- execscore.sh 50
only:
- master
teacher-check1:
stage: case1
<<: *codecode-runner
script:
- make
- ./app < input1.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input1.txt input1.txt -b -B -y -i --suppress-common-lines
- diff template/output1.txt output1.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input1.txt > user_output1.txt
- diff teacher_check/output1.txt user_output1.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
case2:
stage: case2
<<: *codecode-runner
script:
- make
- ./app < input2.txt > user_output2.txt
- diff output2.txt user_output2.txt -b -B -y -i --suppress-common-lines
- execscore.sh 60
only:
- master
teacher-check2:
stage: case2
<<: *codecode-runner
script:
- make
- ./app < input2.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input2.txt input2.txt -b -B -y -i --suppress-common-lines
- diff template/output2.txt output2.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input2.txt > user_output2.txt
- diff teacher_check/output2.txt user_output2.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
case3:
stage: case3
<<: *codecode-runner
script:
- make
- ./app < input3.txt > user_output3.txt
- diff output3.txt user_output3.txt -b -B -y -i --suppress-common-lines
- execscore.sh 65
only:
- master
teacher-check3:
stage: case3
<<: *codecode-runner
script:
- make
- ./app < input3.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input3.txt input3.txt -b -B -y -i --suppress-common-lines
- diff template/output3.txt output3.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input3.txt > user_output3.txt
- diff teacher_check/output3.txt user_output3.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
case4:
stage: case4
<<: *codecode-runner
script:
- make
- ./app < input4.txt > user_output4.txt
- diff output4.txt user_output4.txt -b -B -y -i --suppress-common-lines
- execscore.sh 70
only:
- master
teacher-check4:
stage: case4
<<: *codecode-runner
script:
- make
- ./app < input4.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input4.txt input4.txt -b -B -y -i --suppress-common-lines
- diff template/output4.txt output4.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input4.txt > user_output4.txt
- diff teacher_check/output4.txt user_output4.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
case5:
stage: case5
<<: *codecode-runner
script:
- make
- ./app < input5.txt > user_output5.txt
- diff output5.txt user_output5.txt -b -B -y -i --suppress-common-lines
- execscore.sh 75
only:
- master
teacher-check5:
stage: case5
<<: *codecode-runner
script:
- make
- ./app < input5.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input5.txt input5.txt -b -B -y -i --suppress-common-lines
- diff template/output5.txt output5.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input5.txt > user_output5.txt
- diff teacher_check/output5.txt user_output5.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
case6:
stage: case6
<<: *codecode-runner
script:
- make
- ./app < input6.txt > user_output6.txt
- diff output6.txt user_output6.txt -b -B -y -i --suppress-common-lines
- execscore.sh 80
only:
- master
teacher-check6:
stage: case6
<<: *codecode-runner
script:
- make
- ./app < input6.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input6.txt input6.txt -b -B -y -i --suppress-common-lines
- diff template/output6.txt output6.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input6.txt > user_output6.txt
- diff teacher_check/output6.txt user_output6.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
case7:
stage: case7
<<: *codecode-runner
script:
- make
- ./app < input7.txt > user_output7.txt
- diff output7.txt user_output7.txt -b -B -y -i --suppress-common-lines
- execscore.sh 90
only:
- master
teacher-check7:
stage: case7
<<: *codecode-runner
script:
- make
- ./app < input7.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input7.txt input7.txt -b -B -y -i --suppress-common-lines
- diff template/output7.txt output7.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input7.txt > user_output7.txt
- diff teacher_check/output7.txt user_output7.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
case8:
stage: case8
<<: *codecode-runner
script:
- make
- ./app < input8.txt > user_output8.txt
- diff output8.txt user_output8.txt -b -B -y -i --suppress-common-lines
- execscore.sh 100
only:
- master
teacher-check8:
stage: case8
<<: *codecode-runner
script:
- make
- ./app < input8.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input8.txt input8.txt -b -B -y -i --suppress-common-lines
- diff template/output8.txt output8.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input8.txt > user_output8.txt
- diff teacher_check/output8.txt user_output8.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
\ No newline at end of file
......@@ -4,7 +4,7 @@
<Configuration Name="Debug">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1" AdditionalOptions=""/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1" AdditionalOptions="-std=c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool" AdditionalDependencies="&quot;$(CPLInstallDir)Dump\lib\Follow_Demo.o&quot;"/>
<Tool Name="PostBuildEventTool"/>
......@@ -18,7 +18,7 @@
<Configuration Name="Release">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="NDEBUG"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="NDEBUG" AdditionalOptions="-std=c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool"/>
<Tool Name="PostBuildEventTool"/>
......@@ -33,5 +33,11 @@
<File RelativePath=".\main.c">
</File>
</Filter>
<File RelativePath=".\input1.txt">
</File>
<File RelativePath=".\makefile">
</File>
<File RelativePath=".\output1.txt">
</File>
</Files>
</OSLProject>
......@@ -60,11 +60,14 @@ int AddSetToSet(Set* pDesSet, const Set* pSrcSet);
int SetHasVoid(const Set* pSet);
Rule* InitRules();
Rule* InitRules_CI();
Rule* CreateRule(const char* pRuleName);
RuleSymbol* CreateSymbol();
void PrintRule(const Rule* pHead);
void PrintFollowSet(SetList* pFollowSetList);
//
// 在此声明全局变量
......
exp -> exp addop term
exp -> term
addop -> +
addop -> -
term -> term mulop factor
term -> factor
mulop -> *
factor -> ( exp )
factor -> number
\ No newline at end of file
#include "Follow.h"
#include <string.h>
#include <stdlib.h>
const char* VoidSymbol = "#"; // "ε"
const char* DollarSymbol = "$";
char rule_table_ci[20][256];
char ruleNameArr[20][64];
int main(int argc, char* argv[])
{
//
// 调用 InitRules 函数初始化文法
//
#ifdef CODECODE_CI
Rule* pHead = InitRules_CI();
#else
Rule* pHead = InitRules();
#endif
//
// 初始化 First 集合、Follow 集合
......@@ -27,6 +36,11 @@ int main(int argc, char* argv[])
//
PrintRule(pHead);
//
// 输出Follow集合
//
PrintFollowSet(&FollowSetList);
return 0;
}
......@@ -247,6 +261,105 @@ Rule* InitRules()
return pHead;
}
Rule* InitRules_CI()
{
int nRuleCount = 0;
// 需要读取多行文本
for(int i = 0; i < 20; i++)
{
gets(rule_table_ci[i]);
int length = strlen(rule_table_ci[i]);
if(length == 0)
{
break;
}
for(int j = 0; j < length; j++)
{
if(rule_table_ci[i][j] == ' ')
{
ruleNameArr[i][j] = '\0';
break;
}
ruleNameArr[i][j]= rule_table_ci[i][j];
}
nRuleCount++;
}
Rule *pHead, *pRule;
RuleSymbol **pSymbolPtr, *pNewSymbol;
Rule** pRulePtr = &pHead;
for(int i=0; i<nRuleCount; i++)
{
*pRulePtr = CreateRule(ruleNameArr[i]);
pRulePtr = &(*pRulePtr)->pNextRule;
}
pRule = pHead;
for(int i=0; i<nRuleCount; i++)
{
pSymbolPtr = &pRule->pFirstSymbol;
int start = 0;
for(int j=0; rule_table_ci[i][j] != '\0'; j++)
{
if(rule_table_ci[i][j] == ' '
&& rule_table_ci[i][j + 1] == '-'
&& rule_table_ci[i][j + 2] == '>'
&& rule_table_ci[i][j + 3] == ' ')
{
start = j + 4;
break;
}
}
for(int k=start; rule_table_ci[i][k] != '\0'; k++)
{
if(rule_table_ci[i][k] == ' ')
{
continue;
}
pNewSymbol = CreateSymbol();
char tokenName[MAX_STR_LENGTH] = {};
for(int m = 0; ;m++)
{
if(rule_table_ci[i][k] == ' ' || rule_table_ci[i][k] == '\0' || rule_table_ci[i][k] == '\n')
{
tokenName[m] = '\0';
break;
}
tokenName[m] = rule_table_ci[i][k++];
}
strcpy(pNewSymbol->SymbolName, tokenName);
pNewSymbol->isToken = 1;
for(int n = 0; n < nRuleCount; n++)
{
if(strcmp(pNewSymbol->SymbolName, ruleNameArr[n]) == 0)
{
pNewSymbol->isToken = 0;
break;
}
}
*pSymbolPtr = pNewSymbol;
pSymbolPtr = &pNewSymbol->pNextSymbol;
}
pRule = pRule->pNextRule;
}
return pHead;
}
/*
功能:
创建一个新的文法。
......@@ -309,3 +422,34 @@ void PrintRule(const Rule* pHead)
}
}
/*
功能:
输出 First 集合。
参数:
pFirstSetList -- First 集合指针。
*/
void PrintFollowSet(SetList* pFollowSetList)
{
printf("\nThe Follow Set:\n");
for(int i = 0; i < pFollowSetList->nSetCount; i++)
{
printf("Follow(%s) = { ", pFollowSetList->Sets[i].Name);
for(int j = 0; j < pFollowSetList->Sets[i].nTerminalCount; j++)
{
if(j == pFollowSetList->Sets[i].nTerminalCount - 1)
{
printf("%s ", pFollowSetList->Sets[i].Terminal[j]);
}
else
{
printf("%s, ", pFollowSetList->Sets[i].Terminal[j]);
}
}
printf("}\n");
}
}
DIR_INC = .
DIR_SRC = .
DIR_OBJ = .
DIR_BIN = .
SRC = $(wildcard ${DIR_SRC}/*.c)
OBJ = $(patsubst %.c,${DIR_OBJ}/%.o,$(notdir ${SRC}))
TARGET = app
BIN_TARGET = ${DIR_BIN}/${TARGET}
CC = gcc
CFLAGS = -g -w -fmax-errors=10 -std=c99 -fsigned-char -I${DIR_INC} -D CODECODE_CI
${BIN_TARGET}:${OBJ}
$(CC) $(OBJ) -o $@
${DIR_OBJ}/%.o:${DIR_SRC}/%.c
$(CC) $(CFLAGS) -c $< -o $@
\ No newline at end of file
exp -> exp addop term
exp -> term
addop -> +
addop -> -
term -> term mulop factor
term -> factor
mulop -> *
factor -> ( exp )
factor -> number
The Follow Set:
Follow(exp) = { $, +, -, ) }
Follow(addop) = { (, number }
Follow(term) = { $, +, -, *, ) }
Follow(mulop) = { (, number }
Follow(factor) = { $, +, -, *, ) }
# required metadata
sonar.language=c
# path to source directories (required)
sonar.sources=./
# path to the build artifact
sonar.artifact.path=build/app
# paths to the reports
sonar.c.cppcheck.reportPath=./build/cppcheck-report.xml
#sonar.c.pclint.reportPath=./build/pclint-report.xml
#sonar.c.coverage.reportPath=./build/gcovr-report*.xml
#sonar.c.coverage.itReportPath=./build/gcovr-report*.xml
#sonar.c.coverage.overallReportPath=./build/gcovr-report*.xml
sonar.c.valgrind.reportPath=./build/valgrind-report.xml
sonar.c.vera.reportPath=./build/vera-report.xml
#sonar.c.rats.reportPath=./build/rats-report.xml
#sonar.c.xunit.reportPath=./build/xunit-report.xml
#sonar.c.drmemory.reportPath=./build/drmemory-logs/**/results.txt
sonar.c.includeDirectories=/usr/include/,/usr/include/linux,/usr/include/x86_64-linux-gnu/bits,/usr/include/x86_64-linux-gnu/sys,/usr/include/c++/5/tr1,./
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论