Grammar with single-quoted stings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Grammar with single-quoted stings

Schilha, Matthias
Hi,
 
i want to write a grammar to accept strings like this: a = 'b'
 
To do that, I write this grammar:

%header%

GRAMMARTYPE = "LL"

%tokens%

EQ = "="

S_QUOTE = "'"

NUMBER                       = <<[0-9]+>>
IDENTIFIER                   = <<'[A-Za-z§][A-Za-z0-9_§]*>>
WHITESPACE                   = <<[ \t\n\r]+'>> %ignore%


%productions%


Expression = IDENTIFIER AtomComparisonTail;

AtomComparisonTail = Comparison Atom
                | Comparison "'" Atom "'";
     
Comparison = "=";
     
Atom = NUMBER
     | IDENTIFIER;


But it doesn't work. I get the message: unexpected character ''', on line: 1 column: 3

In this way I changed my grammar to

%header%

GRAMMARTYPE = "LL"

%tokens%

EQ = "="

S_QUOTE = "'"

QUOTED_STRING                = <<('[^']*')>>
NUMBER                       = <<[0-9]+>>
IDENTIFIER                   = <<'[A-Za-z§][A-Za-z0-9_§]*>>
WHITESPACE                   = <<[ \t\n\r]+'>> %ignore%


%productions%


Expression = IDENTIFIER AtomComparisonTail;

AtomComparisonTail = Comparison Atom
                | Comparison QUOTED_STRING Atom QUOTED_STRING;
     
Comparison = "=";
     
Atom = NUMBER
     | IDENTIFIER;

But it is still not working.

Have someone another idea to solve this problem.

Thank you very much.
Matthias

_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Grammar with single-quoted stings

Per Cederberg
Your regex for whitespace seems to include an accidental extra char at the end.

Cheers,

/Per

On Wednesday, March 23, 2011, Schilha, Matthias
<[hidden email]> wrote:

> Hi,
>
> i want to write a grammar to accept strings like this: a = 'b'
>
> To do that, I write this grammar:
>
> %header%
>
> GRAMMARTYPE = "LL"
>
> %tokens%
>
> EQ                                                       = "="
>
> S_QUOTE                                          = "'"
>
> NUMBER                       = <<[0-9]+>>
> IDENTIFIER                   = <<'[A-Za-z§][A-Za-z0-9_§]*>>
> WHITESPACE                   = <<[ \t\n\r]+'>> %ignore%
>
>
> %productions%
>
>
> Expression = IDENTIFIER AtomComparisonTail;
>
> AtomComparisonTail = Comparison Atom
>                 | Comparison "'" Atom "'";
>
> Comparison = "=";
>
> Atom = NUMBER
>      | IDENTIFIER;
>
>
> But it doesn't work. I get the message: unexpected character ''', on line: 1 column: 3
>
> In this way I changed my grammar to
>
> %header%
>
> GRAMMARTYPE = "LL"
>
> %tokens%
>
> EQ                                                       = "="
>
> S_QUOTE                                          = "'"
>
> QUOTED_STRING                = <<('[^']*')>>
> NUMBER                       = <<[0-9]+>>
> IDENTIFIER                   = <<'[A-Za-z§][A-Za-z0-9_§]*>>
> WHITESPACE                   = <<[ \t\n\r]+'>> %ignore%
>
>
> %productions%
>
>
> Expression = IDENTIFIER AtomComparisonTail;
>
> AtomComparisonTail = Comparison Atom
>                 | Comparison QUOTED_STRING Atom QUOTED_STRING;
>
> Comparison = "=";
>
> Atom = NUMBER
>      | IDENTIFIER;
>
> But it is still not working.
>
> Have someone another idea to solve this problem.
>
> Thank you very much.
> Matthias
>
> _______________________________________________
> Grammatica-users mailing list
> [hidden email]
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
>

_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users