grammatica-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Grammatica-users] Grammar with single-quoted stings


From: Schilha, Matthias
Subject: [Grammatica-users] Grammar with single-quoted stings
Date: Wed, 23 Mar 2011 15:08:01 +0100

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]