infinite parentheses

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

infinite parentheses

Steffen Gaede
I've following definition:

%tokens%
...
LEFT_PAREN =  "("
RIGHT_PAREN = ")"
...

%productions%
...
W1 = ("(" W1 ")") | ....
...


It's running with something like this:
(bla) => "(" bla ")"

But if I've more then one parenthesis, i've got the error, although it
should be interpreted like this:
((bla)) => "(" (bla) ")" => "(" bla ")"




Steffen Gaede.

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

Re: infinite parentheses

Steffen Gaede
Ok, sorry my fault...
somewhere I've an error ;)

Steffen.

> I've following definition:
>
> %tokens%
> ...
> LEFT_PAREN =  "("
> RIGHT_PAREN = ")"
> ...
>
> %productions%
> ...
> W1 = ("(" W1 ")") | ....
> ...
>
>
> It's running with something like this:
> (bla) => "(" bla ")"
>
> But if I've more then one parenthesis, i've got the error, although it
> should be interpreted like this:
> ((bla)) => "(" (bla) ")" => "(" bla ")"
>
>
>
>
> Steffen Gaede.
>
> _______________________________________________
> Grammatica-users mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/grammatica-users



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

tokinze and parse results

Steffen Gaede
What is the difference between both results, if I've the same input,
same grammar - but the parser fails, should the tokenizer not fails, too?

if I have following stupid example:
SELECT *
FROM room_price R1, Accommodation A1
WHERE
        (R1.regular_price > 8) or ((R1.regular_price > 8) and (R1.regular_price
> 8))


the parser fails with "((R1.regular_price" but not with "((regular_price "

the tokenizer has no errors.


The grammar is attached.

--------------------------------
Tokinzier output:

Tokens from ../my/sfwtest10b.txt:
selectToken(1012): "SELECT", line: 1, col: 1
ASTERISK(1043): "*", line: 1, col: 8
fromToken(1013): "FROM", line: 2, col: 1
ID(1048): "room_price", line: 2, col: 6
ID(1048): "R1", line: 2, col: 17
KOMMA(1034): ",", line: 2, col: 19
ID(1048): "Accommodation", line: 2, col: 21
ID(1048): "A1", line: 2, col: 35
whereToken(1014): "WHERE", line: 3, col: 1
LEFT_PAREN(1032): "(", line: 4, col: 3
ID(1048): "R1", line: 4, col: 4
DOT(1042): ".", line: 4, col: 6
ID(1048): "regular_price", line: 4, col: 7
GREATER(1038): ">", line: 4, col: 21
NUMBER(1047): "8", line: 4, col: 23
RIGHT_PAREN(1033): ")", line: 4, col: 24
OR(1009): "or", line: 4, col: 26
LEFT_PAREN(1032): "(", line: 4, col: 29
LEFT_PAREN(1032): "(", line: 4, col: 30
ID(1048): "R1", line: 4, col: 31
DOT(1042): ".", line: 4, col: 33
ID(1048): "regular_price", line: 4, col: 34
GREATER(1038): ">", line: 4, col: 48
NUMBER(1047): "8", line: 4, col: 50
RIGHT_PAREN(1033): ")", line: 4, col: 51
AND(1008): "and", line: 4, col: 53
LEFT_PAREN(1032): "(", line: 4, col: 57
ID(1048): "R1", line: 4, col: 58
DOT(1042): ".", line: 4, col: 60
ID(1048): "regular_price", line: 4, col: 61
GREATER(1038): ">", line: 4, col: 75
NUMBER(1047): "8", line: 4, col: 77
RIGHT_PAREN(1033): ")", line: 4, col: 78
RIGHT_PAREN(1033): ")", line: 4, col: 79

--------------------------------
Parser output (cutout)

    WT(2011)
      whereToken(1014): "WHERE", line: 3, col: 1
      W1(2012)
        LEFT_PAREN(1032): "(", line: 4, col: 3
        W1(2012)
          W3W2(2013)
            W3(2015)
              Reference(2025)
                ID(1048): "R1", line: 4, col: 4
                DOT(1042): ".", line: 4, col: 6
                ID(1048): "regular_price", line: 4, col: 7
            W2(2014)
              COMP1(2029)
                GREATER(1038): ">", line: 4, col: 21
              W3(2015)
                NUMBER(1047): "8", line: 4, col: 23
        RIGHT_PAREN(1033): ")", line: 4, col: 24
        COMP2(2030)
          OR(1009): "or", line: 4, col: 26
        W1(2012)
Error: in ../my/sfwtest10b.txt: line 4:
    unexpected token ".", expected one of "and", "or", ")", "=", "!=",
    ">=", ">", "<=", "<", "<>", "like", "between", "not", or "in"

                (R1.regular_price > 8) or ((R1.regular_price > 8) and
(R1.regular_price > 8))
                                              ^
Error: in ../my/sfwtest10b.txt: line 4:
    unexpected token ")", expected <EOF>

                (R1.regular_price > 8) or ((R1.regular_price > 8) and
(R1.regular_price > 8))
--------------------------------

Steffen.

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

sfw.grammar (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: tokinze and parse results

Steffen Gaede
Ok, I've re-engined the where-part as like mathparse example (the
()-part) with regardness of violation SQL-rules. So now all (correct
SQL-syntax-like) tests are successful...



changes:
WT = whereToken W1;
W1 = W2 [W1comb];
W1comb = AND W1 | OR W1;
W2 = [WEX] W3;
W3 = ((SFWGOH|Reference|AID|NUMBER) [C1] [COMP1 W3]) | "(" W1 ")";
WEX = [NOT] EXISTS;

// W1 = ("(" W1 ")" | W3W2 | WEX)[COMP2 W1];
// W3W2 = W3 W2;
// W2 = (COMP1 W3) | C1;
// W3 = "(" (SFWGOH | ReferenceList) ")" | Reference | AID | NUMBER;
// WEX = [NOT] EXISTS "(" SFWGOH ")";

Reference = (ID | ID"."ID) ["," Reference];
//ReferenceAll = Reference | ID"."ASTERISK;
ReferenceAll = ID | ID"."(ID|ASTERISK);
//ReferenceList = Reference [","ReferenceList];



... but now it's possible for some stupid SFW-queries (it's not a
programmers style).


Steffen.

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