Ditutup

Working with FLEX++ & BISON++

Lexical Analysis

Syntax of a mini programming language is described by the following grammar (upper case is used to show variables in the grammar):

Grammar G

PROGRAM  program DECLARATIONS ; STATEMENTS end

DECLARATIONS  DECLARATION | DECLARATION; DECLARATIONS

DECLARATION  VARIABLES_LIST : TYPE

TYPE  real | integer

VARIABLES_LIST  VARIABLE | VARIABLES_LIST , VARIABLE

VARIABLE  id | id [int_number]

STATEMENTS  STATEMENT | STATEMENT; STATEMENTS

STATEMENT  RECEIVER = EXPRESSION

|

if CONDITION then STATEMENTS else STATEMENTS end_if

|

loop STATEMENTS until CONDITION end_loop

|

start DECLARATIONS ; STATEMENTS end

RECEIVER  id | id[EXPRESSION]

EXPRESSION  number | id | id[EXPRESSION] |

id ar_op EXPRESSION

CONDITION  EXPRESSION rel_op EXPRESSION

Groups of tokens:

keywords: are shown in bold

ar_op : arithmetic operations - addition (+) or multiplication (*)

rel_op : comparison operations < , <= , == , != , > , >=

id : - may contain letters (lower and upper case) and digits

- can start only with letter

- may contain underscores (קו תחתון) for example: ab_cd_ef;

- several underscores can not appear one after another (for example ab___cd is

not a legal id)

- id can not end with underscore (for example ab_ is illegal)

int_number : - unsigned integer (e.g. 123)

number : - can be integer (e.g. 123) or real fixed point (e.g. 12.345)

- can be only unsigned

separation signs: colon , semicolon, brackets: [ ]

Comments

At every place in the program, a comment can be placed:

- comment starts with /*

- comment ends with */

Tasks

1. Implement lexical analyzer (using FLEX), as follows:

- Lexical analyzer will read text from the input file and identify tokens. This

happens when function Next_Token is called.

- When a token is identified in the input text, it should be stored in a data

structure. For each token, the following attributes are saved:

* token type

* token lexeme

* number of the line in the input text in which this token was found.

- Comments, blanks, tabs, new lines – are not tokens, and should be ignored

- For each token, print (on a separate line) its type and lexeme

2. Error handling:

- Lexical errors: when the lexical analyzer finds a symbol that doesn't start

any legal token, it prints an appropriate message

- Each error message includes information on the relevant line number (so that

the user can easily localize the place in input where the error occurs).

3. Structure of implementation:

- a file with FLEX definitions (from which the tool will generate LEXYY.c);

it contains:

* regular expressions that describe tokens of the language;

* actions that lexical analyzer should perform when it identifies tokens in the

input text

- .H file containing token definitions (token structure, list of token types)

- .C and .H files (module) that provides services related to creation and storage

of tokens; it should provide the following services:

create_and_store_token

next_token

back_token

Kemahiran: Pengaturcaraan C, Pengaturcaraan C++, Flex

Lihat lagi: variables in programming, using regular expressions, using regular expression, unsigned integer, types of programming language, types of programming errors, types data structure, type of data structure in c, syntax programming, syntax in programming, regular expression using, regular expression starts with, regular expressions list, regular expressions in c, regular expressions example, regular expressions c, regular expression or example, regular expression integer, regular expression function, regular expression for integer

Tentang Majikan:
( 2 ulasan ) tel aviv, Israel

ID Projek: #10115141

3 pekerja bebas membida secara purata $317 untuk pekerjaan ini

hbxfnzwpf

I am very proficient in c and c++. I have 16 years c++ developing experience now, and have worked for more than 6 years. My work is online game developing, and mainly focus on server side, using c++ under linux environ Lagi

$250 USD dalam 2 hari
(85 Ulasan)
6.5
andreygrodzovsky

אשמח לעזור המון נסיון מעשי - [login to view URL] _________________________________________________

$200 USD dalam 10 hari
(3 Ulasan)
2.8
christos95

At pm

$500 USD dalam 30 hari
(0 Ulasan)
0.0