Why mismatch?
#4263
Replies: 5 comments 32 replies
-
I think you need to take a step back and u Der stand how the rules work.
Read through sone of the tutorials. Your mistakes will make sense when you
understand how it works.
…On Wed, May 10, 2023 at 20:39 Nightmare0 ***@***.***> wrote:
Why tipBulevo: input 'boolean' doesn't match token value?? Periodically
stucks on it when complicating .
https://pastebin.com/g6TDXyGv
—
Reply to this email directly, view it on GitHub
<#4263>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7TMGHSS7UH3WXN4NCANLXFOD6TANCNFSM6AAAAAAX4V2HYI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
-
You are trying to write what you think it should do, and not what it does.
Take a step back and learn a little more. Start with the very simplest of
grammars to see how the lexer tokenizes everything, then the parser runs.
Only one lexer rule can win, and it isn’t influenced by the parser.
Also, put no ‘literals’ in the parser grammar.
…On Wed, May 10, 2023 at 23:21 Nightmare0 ***@***.***> wrote:
ehm, what exactly i'am doing wrong?
—
Reply to this email directly, view it on GitHub
<#4263 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7TMDEN2LW5JWR2XIX2HDXFOXAVANCNFSM6AAAAAAX4V2HYI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
10 replies
-
Because you are not making lexer tokens out of them, so ',' in the parser
is not the same ',' as it is in the lexer. I did say not use `literals` in
the parser. You want:
COMMA: ',' ;
DOT: '.' ;
In your lexer, and then use those tokens in your parser. Do not have any
literals in your parser:
parserRule: expression (COMMA expression)* ;
And so on.
…On Thu, May 11, 2023 at 3:06 PM Nightmare0 ***@***.***> wrote:
grammar StrokaFailovyPut;
import Oglavleniye;
fragmentputi: FRAGMENTPUTI rashireniyeFaila?;
rashireniyeFaila: Tochka fragmentputi;
failovyPut: SOBAKA DELITEL_PUTI? fragmentputi (DELITEL_PUTI fragmentputi)*;
SOBAKA: '@';
DELITEL_PUTI: '/';
EKRANIROVANNIY_DELITEL_PUTI: '\\ ';
FRAGMENTPUTI: (EKRANIROVANNIY_DELITEL_PUTI | ~(' ' | '/' | '.'))+;
why i can't use token defined in a set *~(' ' | '/' | '.')*? It seems
duplicates.
—
Reply to this email directly, view it on GitHub
<#4263 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7TMFWIWS7KQX6RSFVYCLXFSFXLANCNFSM6AAAAAAX4V2HYI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
-
I have already told you.
The lexer returns a token for '@' but you have '@' in your parser. So they
are two different tokens, despite the text being the same. You need to
define EVERYTHING in the lexer if you want a separate lexer and parser:
```antlr
myrule: rule1 AT rule2 ;
AT: '@' ;
```
The implicit definition warnings are also telling you that there is no
lexer rule OKONCHANIYA in the lexer, so you have referred to it in the
parser, but there is no such token. Get your lexer working first, then you
can build the parser.
I implore you to read the tutorials. This is ANTLR 101 stuff that you need
to know before trying to write a grammar of any complexity. You might find
it easier not to separate the lexer and parser grammars, but it is
essentially the same thing.
As it stands, your grammars just won't work. Maybe attach them to this
conversation. But we don't really have time to give you free individual
training over GitHub I am afraid.
…On Thu, May 11, 2023 at 3:58 PM Nightmare0 ***@***.***> wrote:
YapComplete::failovyPut:1:0: mismatched input '@' expecting '@'
—
Reply to this email directly, view it on GitHub
<#4263 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7TMAGONWUSQ7FNE35VITXFSL3RANCNFSM6AAAAAAX4V2HYI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
16 replies
-
I want to back Ken up here. Just put e Erin one file , get it working, then
worry about splitting it up if there is sone overriding reason.
I temper dealing with this in v3 and C and it was complicated, then nobody
used it.
…On Fri, May 12, 2023 at 19:09 Ken Domino ***@***.***> wrote:
I've updated https://github.com/kaby76/antlr4-4263 to include your
original set of grammars in t1
<https://github.com/kaby76/antlr4-4263/tree/0e93645e618a81341e4f219a90e76f5c769f7f0b/t1>
and the modified set of grammars (from single-line imports "import a, b, c,
d;" to sequential-line imports "import a; import b; import c; import d;")
in t2
<https://github.com/kaby76/antlr4-4263/tree/0e93645e618a81341e4f219a90e76f5c769f7f0b/t2>.
t1
<https://github.com/kaby76/antlr4-4263/tree/0e93645e618a81341e4f219a90e76f5c769f7f0b/t1>
builds (via dotnet build), t2
<https://github.com/kaby76/antlr4-4263/tree/0e93645e618a81341e4f219a90e76f5c769f7f0b/t2>
does not.
This means that the scoping of the symbols is not flat. The description of
import is in the Documentation here
<https://github.com/antlr/antlr4/blob/master/doc/grammars.md#grammar-imports>.
It says: Rules in the “main grammar” override rules from imported
grammars to implement inheritance. There seems to be an issue with an
import graph that is a partial order
<https://en.wikipedia.org/wiki/Partially_ordered_set#Partial_order>. As I
shown in the diagram here
<#4262 (comment)>,
grammar StrokaFailovyPut is imported on two paths, one directly from
grammar InstrukciyaImportirovat -> StrokaFailovyPut, and the other via
path InstrukciyaImportirovat -> Peremenniye -> Stroki -> StrokaFailovyPut.
It's likely you could refactor the grammar so that it's a total order
<https://en.wikipedia.org/wiki/Total_order>, and that will work.
However, you really should not be partitioning your grammar over 16 .g4
files. It is nearly impossible to read, and for sure requires an IDE to
keep track of which symbol is in which file. I have never seen a grammar
like this in my 40+ years of programming. And, there is nothing in the 300+
grammars of grammars-v4 <https://github.com/antlr/grammars-v4> remotely
similar.
To build, you will need to download Microsoft's NET SDK version 7.
Afterward, from a Bash shell prompt, "dotnet build".
The Eclipse, Intellij, and lab.antlr.org IDEs all uses an "interpretive"
Antlr. It is not identical to that from the Antlr tool. There are subtle
differences between "interpretive" and "compiled" Antlrs.
—
Reply to this email directly, view it on GitHub
<#4263 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7TMFZIR6FN4PHWUUDQO3XFYK6RANCNFSM6AAAAAAX4V2HYI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Why tipBulevo: input 'boolean' doesn't match token value?? Periodically stucks on it when complicating .
https://pastebin.com/g6TDXyGv
Beta Was this translation helpful? Give feedback.
All reactions