Questions tagged [grammar]
A formal grammar is a set of production rules that describe how to form strings of valid syntax. Formal Grammars are most often used to specify the syntax of a programming language.
3,101
questions
1
vote
1
answer
24
views
SLR(1) and LALR(1) grammar conflicts
Suppose you have a grammar G and we find an LR(1) automaton for it. We can transform it into a LALR(1) or SLR(1) parser by doing state-merging and transforming rules but conflicts may appear.
My ...
0
votes
0
answers
10
views
How to import a local grammar in tree-sitter node?
I am currently trying to import my own created grammar in a typescript node project in the following way:
import Parser = require('tree-sitter');
import Language = require('tree-sitter-own');
This ...
-2
votes
0
answers
12
views
Design grammar for the following language over {0, 1} L={ a^n b^m c^m d^2n | n>=0; m >0 }
I am searching for the grammar for the language -
L={ a^n b^m c^m d^2n | n>=0; m >0 }
I have tried this but I think this is wrong
R-> aSbPcQ, P
S->aS,epsilon
P->bPc,epsilon
Q->Qdd,...
0
votes
0
answers
5
views
How can I write semantic tagging in grxml with some prefix number?
I am building a GRXML grammar for a software that will use nuance for voice recognition. The tags must follow the tag-format "swi-semantics/1.0"
following are the logic
7 digits or
4 digit ...
0
votes
0
answers
33
views
Compare String Grammatically In C# .Net Framework 4.6.1 [closed]
I want to compare 2 strings grammatically, not just character comparison. I've tried F23.StringSimilarity library but I don't think it can do what I want.
Here's some sample code and what I expect as ...
0
votes
1
answer
16
views
Classify the grammar according to the Chomsky hierarchy
S ->bA|aB A ->a|aS|bAA B ->b|bS|aBB
I thought this is the type of context-free grammar type, but I am not sure why it's not unrestricted grammar or context-sensitive grammar. In my ...
1
vote
0
answers
35
views
Custom errors messages with Bison
With Bison, I generate custom error messages with the function: int yyreport_syntax_error (const yypcontext_t *ctx) by specifying %define parse.error custom.
I am looking for a feature to display also ...
0
votes
0
answers
8
views
Tips for creating CFG
I need to complete the following context-free grammar:
G = (V, Σ, R, S
0
)
V = {S₀, M, S, Z}
Σ = {·, +, (, ) , 1, 2, 3, 4, 5, 6, 7, 8, 9} ,
so that the language
L = {w | w is a product of sums of one-...
0
votes
1
answer
34
views
How can I parse the code that is conforming to a grammar expressed using ANTLR4 and then generate XML tags
I have specified a grammar using ANTLR4 using VScode and the extension by Mike Lischke. I am wondering if there is a way to parse the code of the program that is conforming to the grammar and generate ...
0
votes
0
answers
26
views
NLTK Grammar Parsing Error ValueError: Unable to parse line 24
I'm working through Natural Language Processing with Python – Analyzing Text with the Natural Language Toolkit and I'm on chapter 10, Exercise 1:
>Select three or four contiguous sentences from ...
0
votes
0
answers
12
views
Parse left associative operators using a greedy parser
This seems to be a pretty fundamental flaw of greedy parsers that you cannot parse left associative operators because infinite recursion will always occur. Is there a way to prevent this from ...
0
votes
0
answers
33
views
is their any grammar file of flex/bison input file in flex/bison format?
i would like to write a flex and bison which will generate pure-cpp header file so that can platform independ.
actually i have written some code of them.
i parse the flex and bison input file using ...
0
votes
0
answers
29
views
raise ModuleNotFoundError('No java install detected. Please install java to use language-tool-python.')
I'm trying to install language-tool-python in a virtual environment on Windows 10, and it gets me this error.
raise ModuleNotFoundError('No java install detected. Please install java to use language-...
0
votes
1
answer
41
views
Unordered result because of an ambiguous grammar using Flex and Bison
I'm trying to create a section for variable declaration (a bit similar to HTML) using Flex and Bison, my grammar is correct (no lexical or syntax errors), but the displayed result isn't ordered.
...
0
votes
1
answer
26
views
Mixing non-overlapping everygrams in order
I'm looking for a method to generate sequences from every-grams up to length n that match an input sentence:
Given a sentence: "Break this into sequences" and n = 3
I want to create the ...
0
votes
0
answers
26
views
Tree-sitter: Problem with optional tokens which has special meaning but their characters can also appear elsewhere
I'm working on tree-sitter grammar for https://xit.jotaen.net/ but I'm stuck on a strange problem. I was able to create a stripped down version of it:
module.exports = grammar({
name: 'xit',
...
3
votes
1
answer
84
views
How do I mutate captures in a Grammar object?
I'm trying to modify the values in a parsed Grammar object with this:
method mutate(Match:D $match --> Match:D) {
for $match.values -> $line {
when $line<content><header-toc&...
0
votes
1
answer
61
views
How many BNF-like grammar specifications does Python have?
There are at least 3 grammar-like specifications within the Python 3.9.1 reference documents 'library-3.9.1.pdf' and 'reference-3.9.1.pdf' (aka https://docs.python.org/3.9/library/ast.html and https://...
-2
votes
1
answer
45
views
How to get an abstract syntax tree in python?
I have a grammar defined. For sake of example expr = a | expr *expr.
I want to get an ast.
Is it possible to do this in python?
I have looked at ast module in python, but I believe it works only for ...
0
votes
0
answers
39
views
LALR Grammar desambiguation for function calls statements (as in Python grammar)
I'm trying to write a simple LALR parser for a custom DSL. My grammar looks like this :
main : stmts
stmts : expr stmts
|
expr : arithmetics
| function_call
| VARNAME
| INT
...
0
votes
1
answer
47
views
The exponential operator in Matlab grammar using ANTLR4 does not work correctly
I have been using matlab grammar from this source. I came across an error to the following input
a = 2^2*3
b = 3*2^2
Result in both cases should be 12, but it is not, because the exponential operator ...
0
votes
0
answers
27
views
Antlr4: access variable name in type annotation context (access grandparent's sibling rule context)
I need to parse variable declaration using Antlr4.
variableDeclaration
: name ':' type
;
name
: Name
;
type is top-level rule for type expressions. So there are some simple types parsed via ...
5
votes
1
answer
69
views
Is there a way to run an action on a grammar that's already been parsed?
If I do:
my $parsed_grammar = PG.parse( $some_string );
Is there any way to to do something like the pseudo code below?
$parsed_grammar.run_action( $action_class.new );
0
votes
0
answers
8
views
Prover9 theorem prover grammar
I've been searching for the grammar for this theorem prover but I found none. There are only bits and pieces on their site. Does anyone by any chance in in possesion of the grammar for this thing or ...
0
votes
1
answer
50
views
VSCode language extension: can a language be embedded into another through code?
The extension adds support for Renpy language, a language very similar to Python. In this language, it's possible to embed Python code in different ways.
Single line statement:
define e = Character(&...
4
votes
2
answers
85
views
Using a grammar to parse a string without lookahead?
Got this text:
Want this || Not this
The line may also look like this:
Want this | Not this
with a single pipe.
I'm using this grammar to parse it:
grammar HC {
token TOP { <pre> <...
5
votes
1
answer
62
views
Grammar not parsing as expected with negative lookaround assertion
OK, this is either a bug or I'm going to look like a total idiot and I'm using a lookaround assertion completely wrong. I don't care about the latter so here we go.
Got this grammar I'm testing:
our ...
5
votes
2
answers
74
views
Substitution in grammar action code throwing bizarre "P6opaque" error
I have this action which overrides an action in another action class:
method taskwiki-prefix($/ is copy) {
my $prefix = $/.Str;
$prefix ~~ s:g!'|'!!;
make $...
0
votes
1
answer
30
views
Is there a Tatsu or any PEG-format grammar available for the [g]awk language syntax?
As the subject asks, does anyone know of an existing Tatsu grammar (or at least a PEG-format grammar) for the [g]awk language?
I did already browse all existing Tatsu examples that I could find, and ...
4
votes
2
answers
94
views
How do I match a newline or the end of a file in a Raku grammar?
I have run into headaches trying to coerce a grammar to match the last line of a file if it is not followed by a newline:
Line 1
Line 2 EOF
This attempted solution, which makes the newline optional, ...
6
votes
2
answers
72
views
Raku grammar action throwing "Cannot bind attributes in a Nil type object. Did you forget a '.new'?" error when using "make"
I have this method in a class that's throwing a Cannot bind attributes in a Nil type object. Did you forget a '.new'?
method parse() {
grammar FindHeaders {
token TOP { [<not-header> ...
2
votes
1
answer
186
views
NLP: check if a detected sentence is a complete sentence
In my NLP project I build my own model to identify sentences in a PDF document. Now I would like to check if my extracted sentences are complete sentences. During my research I have already come ...
0
votes
1
answer
67
views
How to write an Antlr4 grammar that matches X number of characters
I want to use Antlr4 to parse a format that stores the length of segments in the serialised form
For example, to parse:
"6,Hello 5,World"
I tried to create a grammar like this
grammar ...
0
votes
0
answers
10
views
Multi-line regex only matches if begin & end are on the same line
I'm trying to add a bit of grammar for the Liquid language to my custom extension. Here is the bit of code in question:
{% if type == "record"
or type == "record2"
...
0
votes
0
answers
18
views
How to use other grammars in your grammar?
I would like to use Liquid grammar inside a specific block in my grammar:
https://github.com/Shopify/liquid-tm-grammar
but I can't figure out how to add it or whether it's even possible?
5
votes
2
answers
114
views
Alternate version of grammar not working as I'd prefer
This code parses $string as I'd like:
#! /usr/bin/env raku
my $string = q:to/END/;
aaa bbb # this has trailing spaces which I want to keep
kjkjsdf
kjkdsf
END
grammar Markdown {
token ...
1
vote
1
answer
31
views
Ruby EBNF COMPSTMT iteration misunderstanding
Here is a basic Ruby program:
puts 1
puts 1
puts 1
puts 1
puts 1
puts 1
puts 1
Here are the top rules of the BNF syntax for Ruby (shortened):
source: https://github.com/goruby/goruby/blob/master/...
0
votes
0
answers
37
views
Antlr4 generated files contain errors when moved from the gen to the src directory on INTELLIJ
I have tested a small project with a hello world grammar on intellij (windows) and moved the antlr4 generated files from gen to src to be able to create a "Mylistener" class and everything ...
0
votes
0
answers
33
views
Delete subtree in AST after testing that it exists in ANTLRv4
I have an AST from an ANTLR grammar "Mygrammar" and i want to delete the node (with its children) corresponding to the rule "myrule" after testing that "myrule" exists in ...
1
vote
0
answers
43
views
How to remove ambiguity of this grammar using lark
I have build a grammar for propositional formulas, however I have found that it is ambiguous, i.e., there is more than one derivation tree for my input formulas.
This is the smallest ambiguous grammar ...
0
votes
0
answers
35
views
Grammar for SPASS and Prover9 first order logic provers
I am trying to make a translator from one of the provers to another, but I can't find any grammar for any of the provers, so I wanted to ask if anybody, by any chance, knows where I can find it. If ...
0
votes
0
answers
21
views
Grammar for SPASS and Prover9 first order logic theorem provers
I am trying to make a translator from one of the provers to another, but I can't find any grammar for any of the provers, so I wanted to ask if anybody, by any chance, knows where I can find it. If ...
0
votes
0
answers
30
views
Irony: How to make BNF Grammar Shift-Reduce Parsing for expressions, but with flat list levels for operators of the same priority? (picture attached)
I'm trying to create a Grammar in Irony.NET (code attached below), which would parse simple expressions like this one:
"a + b * c - d" , but in a more flat tree format, where operators of ...
0
votes
1
answer
51
views
ANTLR4 parse tree doesn't contain rule names
ANTLR4 doesn't show rule names in parse tree.
For example, 1 + 2 is printed as:
Code in main:
std::string test = "1 + 2";
ANTLRInputStream input(test);
GrammarLexer lexer(&...
1
vote
0
answers
25
views
Unrestricted grammar for L = WW common solution question
I found this solution on a forum, it seems right to me and I can understand most of it, however I think it is incomplete since C -> CP can generate infinite P's. There's the possibility that there ...
1
vote
1
answer
43
views
Is it possible to count the number of times an element appears when parsing?
I am trying to find a way to keep track of the number of times an element appears when building a parse tree. Let's say my grammar looks something like this:
grammar sample;
@members {
private ...
-1
votes
1
answer
32
views
How can I make an ANTLR rule that matches a line of characters containing a specific character only once, at any position in the line?
I am new to writing grammar in ANTLR, and I am not sure how to make the rule I want here.
Suppose a line of characters could possibly be something like:
a b c 1 e : d g e 3 s 5 b 7 d r : f : 2 v ...
0
votes
0
answers
63
views
parse error in Happy with a simple attributed grammar
I'm trying to learn attributed grammars in Happy. I wrote a simple grammar in BNFC (the only rule I have is:
Num. E ::= Integer;
So I added the attribute "parseTree" to the parser, which ...
1
vote
1
answer
18
views
Is there a specific way to define language grammar?
If I were to want to create a new programming language, is there a specific file format or extension used to define the grammar of this new language? Or should I just use a plain text file?
6
votes
5
answers
225
views
Python: grammar correct in a loop
"I was doing the follow exercise:
A gymnast can earn a score between 1 and 10 from each judge.
Print out a series of sentences, "A judge can give a gymnast _ points."
Don't worry if ...