E
E
Egor Nameles2020-09-21 13:06:54
C++ / C#
Egor Nameles, 2020-09-21 13:06:54

Problems in parser implementation?

Hello, I've been fighting for a few days now, I hope for help. The task is to implement a parser. The brief essence is this: there is a text file in which some program code is written, according to my grammar. It is checked by a lexical analyzer that extracts tokens. And then already syntactic for errors. If there are no errors, then everything is fine. And if there is (for example, there is no ";" at the end of the line), then a message is displayed that indicates where the error is and what kind of error it is, as in the compiler. Here I have such code, but not for my grammar. I can't get it to work correctly. It does not go further than lexical analysis.

<Программа> ::= <Объявление переменных> <Описание вычислений>
<Описание вычислений> ::= Begin <Список присваиваний> End
<О6ъявление переменных>::= <Тип переменных> <Список переменных>
<Тип переменных> ::= Integer|Long Integer
<Список переменных> ::= <Идент>| <Идент>,<Список переменных>
<Список присваиваний>::= <Присваивание>|<Присваивание> <Список присваиваний>
<Присваивание> ::= <Идент> = <Выражение> ;
<Выражение> ::= <Ун.оп.> <Подвыражение> | <Подвыражение>
<Подвыражение> :: = ( <Выражение> ) | <Операнд> |
 <Подвыражение> <Бин.оп.> <Подвыражение>
<Ун.оп.> ::= "-"
<Бин.оп.> ::= "-" | "+" | "*" | "/"
<Операнд> ::= <Идент> | <Константа>
<Идент> ::= <Буква> <Идент> | <Буква>
<Константа> ::= <Цифра> <Константа> | <Цифра>


I will give the program code in the comments, since it will not fit here.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Robur, 2020-09-21
@Robur

Do you want to change the work of a fellow student to fit your assignment or something?
If you want to learn how to write analyzer compilers, then you should understand that this is a fundamental topic and you first need to delve into the theory, and then write code. It won't work otherwise.
here you should start with the classics https://en.wikipedia.org/wiki/Compilers:_Principle...
well, or at least understand how parsers work, what they are, and so on. To disassemble the text into tokens is the simplest step, one might say primitive.
to take the code from one grammar and remake it for another without understanding what is happening in it at all - such an entertainment. And if there is an understanding, then you just take and write this code.
If you just need someone to "correct the code" for you, then this is not the right resource.

M
mayton2019, 2020-09-22
@mayton2019

Yes, this is not a question, but a whole task for freelance. I don’t know what the author is doing, whether reposting other people’s tasks or solving their own, but here you just need to prepare a cutlet of money.
Or greatly simplify the question so that it is at least tangible for the questionnaire.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question