My purpose (it is not evaluated, and I get nothing from its solution) is to write lexer / scanner / tokenizer (however you want to call it). flex is used for this class. The lexer is written for Object Object Oriented Language or COOL.
In this language, multi-line comments begin and end as follows:
(* line 1
line 2
line 3 *)
These comments may be nested. In other words, the following is true:
(* comment1 start (* comment 2 start (* comment 3 *) comemnt 2 end *) comment 1 end *)
Strings in this language are regular quotation marks, as in C. Here is an example:
"This is a string"
"This is another string"
There is also an additional rule that says that there can be no EOF in a comment or line. For example, the following is not valid:
(* comment <EOF>
"My string <EOF>
. , \n.
, :
lexer EOF , 1, , EOF , .
, lexer
Line 1: (* this is a comment <EOF>
:
`# 2 "EOF "
, :
Line 1: "This is a string <EOF>
:
`# 1 ERROR " EOF"
, ( ). , . , , .
<BLOCK_COMMENT>{
[^\n*)(]+ ;
")" ;
"(" ;
"*" ;
\n curr_lineno++;
}
<BLOCK_COMMENT><<EOF>> {
cool_yylval.error_msg = "EOF in comment";
BEGIN(INITIAL);
return ERROR;
}
<STRING>\\\n|\n {
curr_lineno++;
}
<STRING><<EOF>> {
cool_yylval.error_msg = "String contains EOF character";
BEGIN(INITIAL);
return ERROR;
}
, :
, ?
.
source
share