الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مساعدة في بناء Lexical Analayser المحل المفرداتي

بدأه wimaxmax في 3 أبريل 2008 · 8 رد · 1,414 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

تحية طيبة اخواني الأعضاء الكرام

طلب منا الدكتور مشروع بناء المحلل المفراداتي lexical analyser بلغة # C

بحيث يخرج جدول ال Symobl table ويعطينا ال token ورقم ال id تبعها

فياريت تساعدوني بالأفكار حتى لوكانت بلغة اخرى غير ال #C بس المطلوب شرح الفكرة حتى استطيع برمجتها بلغة # C والأكواد اذا تستطيعون ذلك ولكم مني كل الشكر والأحترام والتقدير

تحياتي

#3

وعليكم السلام ورحمة الله وبركاته

مشكورة على المرور

بالنسبة للبرنامج الأول انا وجدته من زمان حاولت افصل ال Lexical ماقدرت

تحياتي

تم تعديل هذه المشاركة بواسطة wimaxmax في 3 أبريل 2008 في 03:16

#4

up

#5

طيب مين يعدلي هذا الكود عشان يشتغل

هذا الكود يعطين 15 خطأ

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;



namespace ConsoleApplication1

{

public class Token

{

int code;

int attr;

}

public class SymbT

{

public string lexeme;

public int code;

}

public class LexicalA

{

SymbT[] SymbolTable = new SymbT[20];

char Inputbuff;

static bool WhiteSpace(char c1)

{

if(c1==' ')

return true;

else

return false;



}

static bool letter(char c1)

{

if ((c1 >= 'A' && c1 <= 'Z') || (c1 >= 'a' && c1 <= 'z'))

return true;

else

return false;

}

static bool digit(char c1)

{

if (c1 >= '0' && c1 <= '9')

return true;

else

return false;

}

public int lookup(string lexe)

{



for (int i = 0; i < 20; i++)

{

if (lexe == SymbolTable.lexeme)

return i;

}

return 0;

}

public int insert(string lexe, int tcode)

{



SymbolTable[tcode].lexeme = lexe;

SymbolTable[tcode].code = tcode;

return tcode;

}

public int twoChar(string s)

{

if (s == "aa") return token.code;

else if (s = "//"|| s="/*") return -1;

else return 0;

}

static Token LexAn()

{

Token token = new Token();

int ID1=256;

int NUM=257;

int NONE=-1;

int state=0;

string lexbuf="";

char c;



do

{ 

switch(state)

{

case 0:



if( WhiteSpace©);

if(letter©)

{lexbuf+=c; state=1;}

else if(digit©)

{lexbuf+=c; state=2;}

else

{lexbuf+=c; state=3;}

break;

case 1:

if(letter©||(digit©))

{

lexbuf+=c;

}

else

{

int p=lookup(lexbuf);

if(p==0) insert(lexbuf,ID1);

token.code=SymbolTableبسم الله الرحمن الرحيم.code;

token.attr=p;

return token;

}

break;

case 2:

if(digit©)

lexbuf+=c;

else

{

token.code=NUM;

token.attr=Int32.Parse(lexbuf);

return token;

}

break;

case 3:

lexbuf+=c;

int tc=twoChar(lexbuf);

token.attr=NONE;

if(tc==0)

{

token.code=ASCII_of_First_Char(lexbuf);

return token;

}

}

}

while(Inputbuff!=0);

}

//private static int lookup(string lexbuf)

//{

// throw new Exception("The method or operation is not implemented.");

//}

static void Main()

{

LexAn();



}

}

}

تم تعديل هذه المشاركة بواسطة wimaxmax في 4 أبريل 2008 في 00:08

#6

UP

#7

up

up

#8

UP

#9

يوجد أيضاً GoldenParser يمكنه انتاج C# Parser

http://www.devincook.com/goldparser/

Sr. Software Development Engineer
Hulu, LLC
My Blogs

مواضيع مشابهة