提交 17d5c5f6 创建 作者: demo10's avatar demo10

modify

上级 f2279c21
流水线 #855 已失败 于阶段
用时 41 秒
image: "registry.cn-hangzhou.aliyuncs.com/engintime/ubuntu_16.04_program:latest"
stages:
- make
- code-analysis
- case1
variables:
TEACHERCHECK_REPO: "engintime/cp-lab/teachers-packet/Lab001.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
\ 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"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1" AdditionalOptions="-std=c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool" AdditionalDependencies="&quot;$(CPLInstallDir)Dump\lib\PickupLeftFactor_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>
......@@ -51,6 +51,7 @@ void PickupLeftFactor(Rule* pHead);
void FreeSelect(RuleSymbol* pSelect);
Rule* InitRules();
Rule* InitRules_CI();
Rule* CreateRule(const char* pRuleName);
RuleSymbol* CreateSymbol();
Rule* FindRule(Rule* pHead, const char* RuleName);
......
A -> abC | abcD | abcE
\ No newline at end of file
#include "PickupLeftFactor.h"
#include <string.h>
#include <stdlib.h>
const char* VoidSymbol = "$"; // "ε"
const char* Postfix = "'";
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
//
// 输出提取左因子之前的文法
......@@ -220,6 +228,13 @@ static const RULE_ENTRY rule_table[] =
}
};
/*
功能:
初始化文法链表。
返回值:
文法的头指针。
*/
Rule* InitRules()
{
Rule *pHead, *pRule;
......@@ -274,6 +289,119 @@ Rule* InitRules()
/*
功能:
初始化文法链表(在执行流水线时调用)。
返回值:
文法的头指针。
*/
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 **pSymbolPtr1, **pSymbolPtr2;
int i, j, k;
Rule** pRulePtr = &pHead;
for(i=0; i<nRuleCount; i++)
{
*pRulePtr = CreateRule(ruleNameArr[i]);
pRulePtr = &(*pRulePtr)->pNextRule;
}
pRule = pHead;
for(i=0; i<nRuleCount; i++)
{
pSymbolPtr1 = &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(k = start; rule_table_ci[i][k] != '\0'; k++)
{
if(rule_table_ci[i][k] == '|')
{
pSymbolPtr1 = &(*pSymbolPtr1)->pOther;
pSymbolPtr2 = pSymbolPtr1;
continue;
}
if(rule_table_ci[i][k] == ' ')
{
continue;
}
if(k == start)
{
pSymbolPtr2 = pSymbolPtr1;
}
*pSymbolPtr2 = CreateSymbol();
char tokenName[MAX_STR_LENGTH] = {};
tokenName[0] = rule_table_ci[i][k];
tokenName[1] = '\0';
(*pSymbolPtr2)->isToken = 1;
for(int m = 0; m < nRuleCount; m++)
{
if(strcmp(tokenName,ruleNameArr[m]) == 0)
{
(*pSymbolPtr2)->isToken = 0;
(*pSymbolPtr2)->pRule = FindRule(pHead, tokenName);
if(NULL == (*pSymbolPtr2)->pRule)
{
printf("Init rules error, miss rule \"%s\"\n", tokenName);
exit(1);
}
}
}
if((*pSymbolPtr2)->isToken == 1)
{
strcpy((*pSymbolPtr2)->TokenName, tokenName);
}
pSymbolPtr2 = &(*pSymbolPtr2)->pNextSymbol;
}
pRule = pRule->pNextRule;
}
return pHead;
}
/*
功能:
创建一个新的 Rule。
参数:
......
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
Before Pickup Left Factor:
A->abC|abcD|abcE
After Pickup Left Factor:
A->abA'
A'->C|cA''
A''->D|E
# 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论