Flex mag meine start condition nicht

marcellus

marcellus

Kaiser
Da ich auf diesen thread keine Antworten bekannt hab hab ich mich etwas weiter in flex reingetaucht.

Jetzt hab ich ein Problem, dass ich mir schwer erklären kann, ich will etwas in der art matchen:

Code:
#FIG (?<version>\d.\d).*?\n?
(?<orientation>Landscape|Portrait)

Wobei ich die Abfolge mit start conditions festleg. Nur ich schaffs nicht in der 2. Zeile die startcondition einzuschalten.

Ich teste die Programme mit:
Code:
#FIG 2.2 blubb
Landscape

Das Passt nicht:

Code:
 1         float version;
 2 
 3 %s      version_float
 4 %s      orientation
 5 
 6 DIGIT   [0-9]
 7 CHAR    [a-z|A-Z]
 8 FLOAT   {DIGIT}.{DIGIT}
 9 
10 VERSION "#FIG "
11 
12 %%
13 
14 {VERSION}                       {
15                                         BEGIN(version_float);
16                                 }
17 <version_float>FLOAT            {
18                                         version=atof(yytext);
19                                         printf("got version nr \"%f\"\n", version);
20                                         BEGIN(orientation);
21                                 }
22 <orientation>"Landscape"        {
23                                         printf("orientation is \"%s\"\n", yytext);
24                                 }
25 
26 {FLOAT}+                { printf("read float  :\"%s\"", yytext ); }
27 {DIGIT}+                { printf("read digit  :\"%s\"", yytext ); }
28 {CHAR}+                 { printf(" read char \"%s\"", yytext ); }
29 
30 %%
31 
32 main()
33         {
34                 yylex();
35         }

(ausgabe)
$ ./flextest < test.fig
read float :"2.2" read char "blubb"
read char "Landscape"

und das schon:

Code:
 1         float version;
 2 
 3 %s      version_float
 4 %s      orientation
 5 
 6 DIGIT   [0-9]
 7 CHAR    [a-z|A-Z]
 8 FLOAT   {DIGIT}.{DIGIT}
 9 
10 VERSION "#FIG "
11 
12 %%
13 
14 {VERSION}                       {
15                                         BEGIN(version_float);
16                                 }
17 <version_float>FLOAT            {
18                                         version=atof(yytext);
19                                         printf("got version nr \"%f\"\n", version);
20                                         BEGIN(orientation);
21                                 }
22 "Landscape"                {
23                                         printf("orientation is \"%s\"\n", yytext);
24                                 }
25 
26 {FLOAT}+                { printf("read float  :\"%s\"", yytext ); }
27 {DIGIT}+                { printf("read digit  :\"%s\"", yytext ); }
28 {CHAR}+                 { printf(" read char \"%s\"", yytext ); }
29 
30 %%
31 
32 main()
33         {
34                 yylex();
35         }

(augabe)
$ ./flextest < test.fig
read float :"2.2" read char "blubb"
orientation is "Landscape"

(diff)
Code:
22c22
< "Landscape" 			{
---
> <orientation>"Landscape" 	{

Die 2 Beispiele haben nur den Sinn, dass man sieht, dass die Startcondition nicht greift. Aber ich hab nix gefunden wie ich das ändern kann.

Ich bin für alle Vorschläge offen

Tia
.
.
.
EDIT (autom. Beitragszusammenführung) :
.

Ich hab den fehler gefunden, aus

Code:
17 <version_float>FLOAT            {

muss man nur

Code:
17 <version_float>{FLOAT}         {

machen, weils auf "FLOAT" gepasst hat und nicht auf "\d.\d".
 
Zuletzt bearbeitet:

Ähnliche Themen

Problem mit HSPA+ Modem Huawei E353 - Installation unmöglich?

Windows clients können nicht mehr auf lange laufendes System zugreifen

Falsche Rechte gesetzt beim Anlegen von Ordnern via Samba-Client

skript zum löschen doppelter dateien

Zugriff auf Samba-Server nur per IP möglich

Zurück
Oben