當前位置:首頁 » 編程軟體 » 用c語言實現一個簡單的編譯器

用c語言實現一個簡單的編譯器

發布時間: 2023-08-14 21:19:52

① 求一個c語言編寫的pl0編譯

// pl0 compiler source code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "set.h"
#include "pl0.h"
//////////////////////////////////////////////////////////////////////
// print error message.
void error(n)
{
int i;
printf(" ");
for (i = 1; i <= cc - 1; i++)
printf(" ");
fprintf(outfile, " ");
fprintf(outfile, "^\n");
printf("^\n");
fprintf(outfile, "Error %3d: %s\n", n, err_msg[n]);
printf("Error %3d: %s\n", n, err_msg[n]);
err++;
} // error
//////////////////////////////////////////////////////////////////////
void getch(void)
{
if (cc == ll)
{
if (feof(infile))
{
printf("\nPROGRAM INCOMPLETE\n");
exit(1);
}
ll = cc = 0;
fprintf(outfile, "%5d ", cx);
printf("%5d ", cx);
while ( (!feof(infile)) // added & modified by alex 01-02-09
&& ((ch = getc(infile)) != '\n'))
{
fprintf(outfile, "%c", ch);
printf("%c", ch);
line[++ll] = ch;
} // while
fprintf(outfile, "\n");
printf("\n");
line[++ll] = ' ';
}
ch = line[++cc];
} // getch
//////////////////////////////////////////////////////////////////////
// gets a symbol from input stream.
void getsym(void)
{
int i, k;
char a[MAXIDLEN + 1];
while (ch == ' '|| ch == '\t')
// modified by yzhang 02-03-12,add some white space
getch();
if (isalpha(ch))
{ // symbol is a reserved word or an identifier.
k = 0;
do
{
if (k < MAXIDLEN)
a[k++] = ch;
getch();
}
while (isalpha(ch) || isdigit(ch));
a[k] = 0;
strcpy(id, a);
word[0] = id;
i = NRW;
while (strcmp(id, word[i--]));
if (++i)
sym = wsym[i]; // symbol is a reserved word
else
sym = SYM_IDENTIFIER; // symbol is an identifier
}
else if (isdigit(ch))
{ // symbol is a number.
k = num = 0;
sym = SYM_NUMBER;
do
{
num = num * 10 + ch - '0';
k++;
getch();
}
while (isdigit(ch));
if (k > MAXNUMLEN)
error(25); // The number is too great.
}
else if (ch == ':')
{
getch();
if (ch == '=')
{
sym = SYM_BECOMES; // :=
getch();
}
else
{
sym = SYM_NULL; // illegal?
}
}
else if (ch == '>')
{
getch();
if (ch == '=')
{
sym = SYM_GEQ; // >=
getch();
}
else
{
sym = SYM_GTR; // >
}
}
else if (ch == '<')
{
getch();
if (ch == '=')
{
sym = SYM_LEQ; // <=
getch();
}
else if (ch == '>')
{
sym = SYM_NEQ; // <>
getch();
}
else
{
sym = SYM_LES; // <
}
}
else
{ // other tokens
i = NSYM;
csym[0] = ch;
while (csym[i--] != ch);
if (++i)
{
sym = ssym[i];
getch();
}
else
{
printf("Fatal Error: Unknown character.\n");
fprintf(outfile, "Fatal Error: Unknown character.\n");
exit(1);
}
}
} // getsym
//////////////////////////////////////////////////////////////////////
// generates (assembles) an instruction.
void gen(int x, int y, int z)
{
if (cx > CXMAX)
{
fprintf(outfile, "Fatal Error: Program too long.\n");
printf("Fatal Error: Program too long.\n");
exit(1);
}
code[cx].f = x;
code[cx].l = y;
code[cx++].a = z;
} // gen
//////////////////////////////////////////////////////////////////////
// tests if error occurs and skips all symbols that do not belongs to s1 or s2.
void test(symset s1, symset s2, int n)
{
symset s;
if (! inset(sym, s1))
{
showset(s1);
showset(s2);
printf("sym=%d, id=%s\n", sym, id);
error(n);
s = uniteset(s1, s2);
while(! inset(sym, s))
getsym();
destroyset(s);
}
} // test
//////////////////////////////////////////////////////////////////////
int dx; // data allocation index
// enter object(constant, variable or procedre) into table.
void enter(int kind)
{
mask* mk;
// added by yzhang 02-02-28
if ( position(id)> 0 ){
error(26); //Redeclared identifier.
}
// end
tx++;
strcpy(table[tx].name, id);
table[tx].kind = kind;
switch (kind)
{
case ID_CONSTANT:
if (num > MAXADDRESS)
{
error(25); // The number is too great.
num = 0;
}
table[tx].value = num;
break;
case ID_VARIABLE:
mk = (mask*) &table[tx];
mk->level = level;
mk->address = dx++;
break;
case ID_PROCEDURE:
mk = (mask*) &table[tx];
mk->level = level;
break;
} // switch
} // enter
//////////////////////////////////////////////////////////////////////
// locates identifier in symbol table.
int position(char* id)
{
int i;
strcpy(table[0].name, id);
i = tx + 1;
while (strcmp(table[--i].name, id) != 0);
return i;
} // position
//////////////////////////////////////////////////////////////////////
void constdeclaration()
{
if (sym == SYM_IDENTIFIER)
{
getsym();
if (sym == SYM_EQU || sym == SYM_BECOMES)
{
if (sym == SYM_BECOMES)
error(1); // Found ':=' when expecting '='.
getsym();
if (sym == SYM_NUMBER)
{
enter(ID_CONSTANT);
getsym();
}
else
{
error(2); // There must be a number to follow '='.
}
}
else
{
error(3); // There must be an '=' to follow the identifier.
}
}
else //added by yzhang 02-02-28
error(4); // There must be an identifier to follow 'const', 'var', or 'procere'.
} // constdeclaration
//////////////////////////////////////////////////////////////////////
void vardeclaration(void)
{
if (sym == SYM_IDENTIFIER)
{
enter(ID_VARIABLE);
getsym();
}
else
{
error(4); // There must be an identifier to follow 'const', 'var', or 'procere'.
}
} // vardeclaration
//////////////////////////////////////////////////////////////////////
void listcode(int from, int to)
{
int i;

printf("\n");
fprintf(outfile, "\n");
for (i = from; i < to; i++)
{
printf("%5d %s\t%d\t%d\n", i, mnemonic[code[i].f], code[i].l, code[i].a);
fprintf(outfile, "%5d %s\t%d\t%d\n", i, mnemonic[code[i].f], code[i].l, code[i].a);
}
printf("\n");
fprintf(outfile, "\n");
} // listcode
//////////////////////////////////////////////////////////////////////
void factor(symset fsys)
{
void expression();
int i;
symset set;

test(facbegsys, fsys, 24); // The symbol can not be as the beginning of an expression.
while (inset(sym, facbegsys))
{
if (sym == SYM_IDENTIFIER)
{
if ((i = position(id)) == 0)
{
error(11); // Undeclared identifier.
}
else
{
switch (table[i].kind)
{
mask* mk;
case ID_CONSTANT:
gen(LIT, 0, table[i].value);
break;
case ID_VARIABLE:
mk = (mask*) &table[i];
gen(LOD, level - mk->level, mk->address);
break;
case ID_PROCEDURE:
error(21); // Procere identifier can not be in an expression.
break;
} // switch
}
getsym();
}
else if (sym == SYM_NUMBER)
{
if (num > MAXADDRESS)
{
error(25); // The number is too great.
num = 0;
}
gen(LIT, 0, num);
getsym();
}
else if (sym == SYM_LPAREN)
{
getsym();
set = uniteset(createset(SYM_RPAREN, SYM_NULL), fsys);
expression(set);
destroyset(set);
if (sym == SYM_RPAREN)
{
getsym();
}
else
{
error(22); // Missing ')'.
}
}
else // added by yzhang 02-02-28
test(fsys, createset(SYM_LPAREN, SYM_NULL), 23);
} // while
} // factor
//////////////////////////////////////////////////////////////////////
void term(symset fsys)
{
int mulop;
symset set;

set = uniteset(fsys, createset(SYM_TIMES, SYM_SLASH, SYM_NULL));
factor(set);
while (sym == SYM_TIMES || sym == SYM_SLASH)
{
mulop = sym;
getsym();
factor(set);
if (mulop == SYM_TIMES)
{
gen(OPR, 0, OPR_MUL);
}
else
{
gen(OPR, 0, OPR_DIV);
}
} // while
destroyset(set);
} // term
//////////////////////////////////////////////////////////////////////
void expression(symset fsys)
{
int addop;
symset set;
set = uniteset(fsys, createset(SYM_PLUS, SYM_MINUS, SYM_NULL));
if (sym == SYM_PLUS || sym == SYM_MINUS)
{
addop = sym;
getsym();
term(set);
if (addop == SYM_MINUS)
{
gen(OPR, 0, OPR_NEG);
}
}
else
{
term(set);
}
while (sym == SYM_PLUS || sym == SYM_MINUS)
{
addop = sym;
getsym();
term(set);
if (addop == SYM_PLUS)
{
gen(OPR, 0, OPR_ADD);
}
else
{
gen(OPR, 0, OPR_MIN);
}
} // while
destroyset(set);
} // expression
//////////////////////////////////////////////////////////////////////
void condition(symset fsys)
{
int relop;
symset set;
if (sym == SYM_ODD)
{
getsym();
expression(fsys);
gen(OPR, 0, 6);
}
else
{
set = uniteset(relset, fsys);
expression(set);
destroyset(set);
if (! inset(sym, relset))
{
error(20);
}
else
{
relop = sym;
getsym();
expression(fsys);
switch (relop)
{
case SYM_EQU:
gen(OPR, 0, OPR_EQU);
break;
case SYM_NEQ:
gen(OPR, 0, OPR_NEQ);
break;
case SYM_LES:
gen(OPR, 0, OPR_LES);
break;
case SYM_GEQ:
gen(OPR, 0, OPR_GEQ);
break;
case SYM_GTR:
gen(OPR, 0, OPR_GTR);
break;
case SYM_LEQ:
gen(OPR, 0, OPR_LEQ);
break;
} // switch
} // else
} // else
} // condition
//////////////////////////////////////////////////////////////////////
void statement(symset fsys)
{
int i, cx1, cx2;
symset set1, set;
if (sym == SYM_IDENTIFIER)
{ // variable assignment
mask* mk;
if (! (i = position(id)))
{
error(11); // Undeclared identifier.
}
else if (table[i].kind != ID_VARIABLE)
{
error(12); // Illegal assignment.
i = 0;
}
getsym();
if (sym == SYM_BECOMES)
{
getsym();
}
else
{
error(13); // ':=' expected.
}
expression(fsys);
mk = (mask*) &table[i];
if (i)
{
gen(STO, level - mk->level, mk->address);
}
}
else if (sym == SYM_CALL)
{ // procere call
getsym();
if (sym != SYM_IDENTIFIER)
{
error(14); // There must be an identifier to follow the 'call'.
}
else
{
if (! (i = position(id)))
{
error(11); // Undeclared identifier.
}
else if (table[i].kind == ID_PROCEDURE)
{
mask* mk;
mk = (mask*) &table[i];
gen(CAL, level - mk->level, mk->address);
}
else
{
error(15); // A constant or variable can not be called.
}
getsym();
} // else
}
else if (sym == SYM_IF)
{ // if statement
getsym();
set1 = createset(SYM_THEN, SYM_DO, SYM_NULL);
set = uniteset(set1, fsys);
condition(set);
destroyset(set1);
destroyset(set);
if (sym == SYM_THEN)
{
getsym();
}
else
{
error(16); // 'then' expected.
}
cx1 = cx;
gen(JPC, 0, 0);
statement(fsys);
code[cx1].a = cx;
}
else if (sym == SYM_BEGIN)
{ // block
getsym();
set1 = createset(SYM_SEMICOLON, SYM_END, SYM_NULL);
set = uniteset(set1, fsys);
statement(set);
while (sym == SYM_SEMICOLON || inset(sym, statbegsys))
{
if (sym == SYM_SEMICOLON)
{
getsym();
}
else
{
error(10);
}
statement(set);
} // while
destroyset(set1);
destroyset(set);
if (sym == SYM_END)
{
getsym();
}
else
{
error(17); // ';' or 'end' expected.
}
}
else if (sym == SYM_WHILE)
{ // while statement
cx1 = cx;
getsym();
set1 = createset(SYM_DO, SYM_NULL);
set = uniteset(set1, fsys);
condition(set);
destroyset(set1);
destroyset(set);
cx2 = cx;
gen(JPC, 0, 0);
if (sym == SYM_DO)
{
getsym();
}
else
{
error(18); // 'do' expected.
}
statement(fsys);
gen(JMP, 0, cx1);
code[cx2].a = cx;
}
else //added by yzhang 02-02-28
test(fsys, phi, 19);
} // statement

//////////////////////////////////////////////////////////////////////
void block(symset fsys)
{
int cx0; // initial code index
mask* mk;
int block_dx;
int savedTx;
symset set1, set;
dx = 3;
block_dx = dx;
mk = (mask*) &table[tx];
mk->address = cx;
gen(JMP, 0, 0);
if (level > MAXLEVEL)
{
error(32); // There are too many levels.
}
do
{
if (sym == SYM_CONST)
{ // constant declarations
getsym();
do
{
constdeclaration();
while (sym == SYM_COMMA)
{
getsym();
constdeclaration();
}
if (sym == SYM_SEMICOLON)
{
getsym();
}
else
{
error(5); // Missing ',' or ';'.
}
}
while (sym == SYM_IDENTIFIER);
} // if
if (sym == SYM_VAR)
{ // variable declarations
getsym();
do
{
vardeclaration();
while (sym == SYM_COMMA)
{
getsym();
vardeclaration();
}
if (sym == SYM_SEMICOLON)
{
getsym();
}
else
{
error(5); // Missing ',' or ';'.
}
}
while (sym == SYM_IDENTIFIER);
block_dx = dx; // modified by yzhang 02-03-15
} // if
while (sym == SYM_PROCEDURE)
{ // procere declarations
getsym();
if (sym == SYM_IDENTIFIER)
{
enter(ID_PROCEDURE);
getsym();
}
else
{
error(4); // There must be an identifier to follow 'const', 'var', or 'procere'.
}
if (sym == SYM_SEMICOLON)
{
getsym();
}
else
{
error(5); // Missing ',' or ';'.
}
level++;
savedTx = tx;
set1 = createset(SYM_SEMICOLON, SYM_NULL);
set = uniteset(set1, fsys);
block(set);
destroyset(set1);
destroyset(set);
tx = savedTx;
level--;
if (sym == SYM_SEMICOLON)
{
getsym();
set1 = createset(SYM_IDENTIFIER, SYM_PROCEDURE, SYM_NULL);
set = uniteset(statbegsys, set1);
test(set, fsys, 6);
destroyset(set1);
destroyset(set);
}
else
{
error(5); // Missing ',' or ';'.
}
} // while
set1 = createset(SYM_IDENTIFIER, SYM_NULL);
set = uniteset(statbegsys, set1);
test(set, declbegsys, 7);
destroyset(set1);
destroyset(set);
}
while (inset(sym, declbegsys));
code[mk->address].a = cx;
mk->address = cx;
cx0 = cx;
gen(INT, 0, block_dx);
set1 = createset(SYM_SEMICOLON, SYM_END, SYM_NULL);
set = uniteset(set1, fsys);
statement(set);
destroyset(set1);
destroyset(set);
gen(OPR, 0, OPR_RET); // return
test(fsys, phi, 8); // test for error: Follow the statement is an incorrect symbol.
listcode(cx0, cx);
} // block
//////////////////////////////////////////////////////////////////////
int base(int stack[], int currentLevel, int levelDiff)
{
int b = currentLevel;

while (levelDiff--)
b = stack[b];
return b;
} // base
//////////////////////////////////////////////////////////////////////
// interprets and executes codes.
void interpret()
{
int pc; // program counter
int stack[STACKSIZE];
int top; // top of stack
int b; // program, base, and top-stack register
instruction i; // instruction register
printf("Begin executing PL/0 program.\n");
fprintf(outfile, "Begin executing PL/0 program.\n");
pc = 0;
b = 1;
top = 3;
stack[1] = stack[2] = stack[3] = 0;
do
{
i = code[pc++];
switch (i.f)
{
case LIT:
stack[++top] = i.a;
break;
case OPR:
switch (i.a) // operator
{
case OPR_RET:
top = b - 1;
pc = stack[top + 3];
b = stack[top + 2];
break;
case OPR_NEG:
stack[top] = -stack[top];
break;
case OPR_ADD:
top--;
stack[top] += stack[top + 1];
break;
case OPR_MIN:
top--;
stack[top] -= stack[top + 1];
break;
case OPR_MUL:
top--;
stack[top] *= stack[top + 1];
break;
case OPR_DIV:
top--;
if (stack[top + 1] == 0)
{
fprintf(stderr, "Runtime Error: Divided by zero.\n");
fprintf(stderr, "Program terminated.\n");
continue;
}
stack[top] /= stack[top + 1];
break;
case OPR_ODD:
stack[top] %= 2;
break;
case OPR_EQU:
top--;
stack[top] = stack[top] == stack[top + 1];
break;
case OPR_NEQ:
top--;
stack[top] = stack[top] != stack[top + 1];
case OPR_LES:
top--;
stack[top] = stack[top] < stack[top + 1];
break;
case OPR_GEQ:
top--;
stack[top] = stack[top] >= stack[top + 1];
case OPR_GTR:
top--;
stack[top] = stack[top] > stack[top + 1];
break;
case OPR_LEQ:
top--;
stack[top] = stack[top] <= stack[top + 1];
} // switch
break;
case LOD:
stack[++top] = stack[base(stack, b, i.l) + i.a];
break;
case STO:
stack[base(stack, b, i.l) + i.a] = stack[top];
//printf("%d\n", stack[top]);
fprintf(outfile, "%d\n", stack[top]);
top--;
break;
case CAL:
stack[top + 1] = base(stack, b, i.l);
// generate new block mark
stack[top + 2] = b;
stack[top + 3] = pc;
b = top + 1;
pc = i.a;
break;
case INT:
top += i.a;
break;
case JMP:
pc = i.a;
break;
case JPC:
if (stack[top] == 0)
pc = i.a;
top--;
break;
} // switch
}
while (pc);
//printf("End executing PL/0 program.\n");
fprintf(outfile, "End executing PL/0 program.\n");
} // interpret
//////////////////////////////////////////////////////////////////////
void main ()
{
FILE* hbin;
char s[80],*finddot;
int i;
symset set, set1, set2;
printf("Please input source file name: "); // get file name to be compiled
scanf("%s", s);
if ((infile = fopen(s, "r")) == NULL)
{
printf("File %s can't be opened.\n", s);
exit(1);
}
#if 1 // added by yzhang 02-02-28
// open the output file
finddot = strchr(s,'.');
if (finddot!=NULL){
strcpy(finddot, ".out");
}else{
strcat(s, ".out");
printf("%s\n", s);
}
printf("Output File is %s\n", s);
if ((outfile = fopen(s, "w")) == NULL)
{
printf("File %s can't be opened.\n", s);
exit(1);
}
#endif

phi = createset(SYM_NULL);
relset = createset(SYM_EQU, SYM_NEQ, SYM_LES, SYM_LEQ, SYM_GTR, SYM_GEQ, SYM_NULL);

// create begin symbol sets
declbegsys = createset(SYM_CONST, SYM_VAR, SYM_PROCEDURE, SYM_NULL);
statbegsys = createset(SYM_BEGIN, SYM_CALL, SYM_IF, SYM_WHILE, SYM_NULL);
facbegsys = createset(SYM_IDENTIFIER, SYM_NUMBER, SYM_LPAREN, SYM_NULL);
err = cc = cx = ll = 0; // initialize global variables
ch = ' ';
kk = MAXIDLEN;
getsym();
set1 = createset(SYM_PERIOD, SYM_NULL);
set2 = uniteset(declbegsys, statbegsys);
set = uniteset(set1, set2);
block(set);
destroyset(set1);
destroyset(set2);
destroyset(set);
destroyset(phi);
destroyset(relset);
destroyset(declbegsys);
destroyset(statbegsys);
destroyset(facbegsys);
if (sym != SYM_PERIOD)
error(9); // '.' expected.
if (err == 0)
{
hbin = fopen("hbin.txt", "w");
for (i = 0; i < cx; i++)
fwrite(&code[i], sizeof(instruction), 1, hbin);
fclose(hbin);
}
if (err == 0)
interpret();
else
printf("There are %d error(s) in PL/0 program.\n", err);
listcode(0, cx);

// close all files, added by yzhang, 02-02-28
fclose(infile);
fclose(outfile);
} // main
//////////////////////////////////////////////////////////////////////
// eof pl0.c

② C語言編譯器是什麼

C語言是一門面向過程的計算機編程語言,與C++、Java等面向對象編程語言有所不同。C語言的設計目標是提供一種能以簡易的方式編譯、處理低級存儲器、僅產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。C語言描述問題比匯編語言迅速,工作量小、可讀性好,易於調試、修改和移植,而代碼質量與匯編語言相當。C語言一般只比匯編語言代碼生成的目標程序效率低10%~20%。因此,C語言可以編寫系統軟體。[2]
二十世紀八十年代,美國國家標准局為了避免各開發廠商用的C語言語法產生差異,給C語言制定了一套完整的美國國家標准語法,稱為ANSI C。作為C語言最初的標准。[3]2011年12月8日,國際標准化組織(ISO)和國際電工委員會(IEC)發布的C11標準是C語言的第三個官方標准,也是C語言的最新標准,該標准更好的支持了漢字函數名和漢字標識符,一定程度上實現了漢字編程。
C語言編譯器普遍存在於各種不同的操作系統中,例如Microsoft Windows, Mac OS X, Linux, Unix等。C語言的設計影響了眾多後來的編程語言,例如C++、Objective-C、Java、C#等。

例:
#include <stdio.h>

int main() {
printf("Hello,world!");

return 0;
}

編譯運行將輸出: Hello,world!

③ c語言剛開始學,win7系統32位求編譯器一個,簡單明了容易上手,筆記本上裝。

W7就DEV就行,我也是用的這個。對於咱們這樣的初學者用WTC或者DEV就夠用了,小巧簡便不佔內存,否則用高端的不僅不能增添能力,相反還會因為復雜的操作流程把本身簡單的問題弄復雜了,反而自造麻煩了。說白了 C編輯器只不過就是個工具罷了 把C知識學會了才是最關鍵的 就好比開車 只要把駕駛技術掌握了 拿到駕駛證了 至於是開寶馬 還是賓士 那就看個人喜好了,我是看視頻學的,我現在正在看的是夏老師的,感覺還不錯,比較適合像我這樣0基礎的。這個比較吸引我的地方就是講的一聽就能聽懂。而且很多概念都有形象的比喻,例如把變數比如成盒子。把變數賦值比喻成往盒子里放東西等等很多這樣的比喻。感覺特別容易理解。

④ 怎樣去寫一個編譯器(用C語言寫C語言編譯器),需要哪些知識做鋪墊,可以給一下相關網站和書籍的推薦嗎

寫編譯器重點就是設計並實現一些數據結構和演算法,語言特點太多的話,代碼寫起來不容易,建議你找一個小語言嘗試下,不要一開始就去嘗試成熟語言。否則你會在寫完語法分析程序以後,遭遇到很大的困難。多數人都是在寫語義分析程序的時候,突然發現自己設計的數據結構很爛,後邊越寫越要命。
如果你想入門編譯器的話,那麼可以看《編譯原理與實踐》,整本書先將編譯器理論,然後後邊教你一步步實現c-miuns(c的子集)的編譯器,包括lex,yacc,都在幾千行代碼左右。這本書講的比較簡單易懂一點
也可以學學斯坦福大學的編譯器設計公開課(aiken設計了一個叫cool的語言,專門用來教人寫編譯器),課程地址上面有人給了:Compilers。這門課以前有個實驗環境(據說已經給了,我以前寫的時候還是用的網上一個不完整的實驗環境),把和編譯器知識無關的內容都給你寫好了,你只需要在固定的地方填上你的內容就可以寫出你的編譯器(不要覺得很簡單哦,人家的代碼寫的很精巧的,讀完就發現寫個好編譯器還是很費腦子的),另外,這個實驗環境有個特點,就是在每一步都提供標准程序做對比,你可以在寫完一部分以後就同標准程序對比,及時發現錯誤。這種方式為寫編譯器又提供了很多幫助
先找個小的,慢慢研究,弄懂了整體的結構再說

⑤ c語言編程

C語言編程如何快速實現

在我們初次學習C語言的時候,總想著快速的實現編譯過程。那麼C語言編程究竟是如何實現的呢,當然是要通過自己喜歡的編譯器來編譯完成,那麼今天就為大家介紹C語言編程是如何快速的實現。

1. 首先我們下載一款適合C語言的編譯器,今天為大家講解的C語言編譯器為CodeBlocks,該編譯器沒有太過復雜,很符合初學者,簡單上手快。

⑥ 我想先用C語言做個C編譯器,然後再編譯其他C程序

可以採用自展的方法。當年的PASCAL語言編譯器就是這樣被創造出來的。
具體方法是:首先用其它任何一門語言寫一個非常精簡的C語言內核,可以只具備基本的功能。再用這個內核本身來編寫更大一點的內核。不斷重復以上的步驟就可以得到一個完整的C語言編譯環境,只是這樣做的難度太高了,做起來恐怕有困難。

⑦ c語言編譯器有哪些

C語言編譯器目前主要有VC++、dev-C++、C-Free、win-TC、TC 2.0等等。

其中比較經典的VC++,微軟的產品,編譯器,鏈接器,運行,調試等功能於一體的強大開肆數發工具,特點是功能十分強大,對於新手來說需要一段時間去摸索。
dev-C++是windows下一款開發c/c++的開發環境,使用gcc為編譯器,遵循標准,功能比較強大,語法高量,可以進行單步調試(這對排除錯誤很重要),進行斷點設置等功能,遵循C標准,是一款很強大的開發工具。
C-Free是一款支持多種編譯器的專業化C/C++集成開發環境(IDE)。利用C-Free,使用者可以輕松地編輯、編譯、連接、運行、調試C/C++程序。
TC 2.0:Borland公司的產品,在dos界面下編譯運裂搜首行,小巧、靈活,但是不能使用滑鼠。
win-TC:在tc2.0的基礎上加上了界面,能夠使用滑鼠,具有語法高量,可以嵌入匯編等特點,對新手一些,拜託了不能用滑鼠的困難。

編譯器,簡單講,漏嫌就是將「一種語言(通常為高級語言)」翻譯為「另一種語言(通常為低級語言)」的程序。一個現代編譯器的主要工作流程:源代碼 (source code) → 預處理器 (preprocessor) → 編譯器 (compiler) → 目標代碼 (object code) → 鏈接器(Linker) → 可執行程序 (executables)。

⑧ 求一個最簡單的適合初學者的C語言編譯器

c-free和vc++6.0都可以,比較推薦c-free吧,畢竟是有中文的,VC也有中文,不過是漢化過的,這兩者也沒啥區別,主要是VC不太兼容win7和win8,畢竟較老了,而C-free可以兼容win7,win8我不知道,沒在那裡用過,可以試一下C-free,這兩者都要在創建C文件的之後加後綴.c才能保存為C文件

熱點內容
c語言編程圖書 發布:2025-02-04 19:01:52 瀏覽:894
在哪裡開啟密碼顯示 發布:2025-02-04 18:38:30 瀏覽:787
怎麼查詢qq密碼 發布:2025-02-04 18:20:10 瀏覽:513
python編寫介面 發布:2025-02-04 18:08:30 瀏覽:78
怎麼給游戲設置密碼 發布:2025-02-04 18:03:08 瀏覽:926
商品存儲規劃 發布:2025-02-04 17:45:24 瀏覽:567
ios訪問共享 發布:2025-02-04 17:36:33 瀏覽:335
javabuild 發布:2025-02-04 17:30:19 瀏覽:592
gnulinux編譯 發布:2025-02-04 17:30:18 瀏覽:132
蘇州阿里雲伺服器專網 發布:2025-02-04 17:21:05 瀏覽:526