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,251
questions
0
votes
0
answers
7
views
How to make ANTLR parser strict?
Below is a simple ANTLR grammar:
grammar EXAMPLE;
document
: Name+ EOF ;
Name
: 'k'+ ;
The generated antlr parser accepts any string that contains substring 'k'.
However, I ...
0
votes
2
answers
27
views
Autocapitalize each sentence beginning after a period
I'm trying to make it so that when a user is entering text in an input field, their sentences will autocapitalize. Some people are already bad enough with proper grammar and punctualization, so this ...
-4
votes
1
answer
257
views
What is the precedence and associativity of operators?
What is the precedence and associativity of operators in C++?
Who defines operator precedence and associativity, and how does it relate to order of evaluation? explains how those properties emerge ...
1
vote
0
answers
18
views
Rewrite sentences from first person to third person and vice versa using python packages
Are there any packages in python that can rewrite large content from Person's point of view i.e first person to third person and Third person to First person
I ate apple yesterday
He ate apple ...
0
votes
0
answers
13
views
Ambiguous grammar definition
i'm trying to make a parser for a progrming language that have already his grammar fully specified on an standard, but the almost first rule of the spec is this one:
WS : ( ' ' | '\t' | '\r' | '\n' ) {...
0
votes
1
answer
32
views
ANTLR Grammar for Recognizing Exponential Notation Numbers and Identifiers
I'm designing an ANTLR grammar that needs to at least recognize numbers in exponential notation, variable identifiers, and strings. I'm running into an issue where the grammar recognizes 1E4 as if E ...
1
vote
1
answer
25
views
antlr error message seems self-contradictory? What am I doing wrong?
I have the following antlr4 grammar in file xbf.g4
grammar xbf;
prog: ( struct_def )* ;
type: ( type_uint | type_float | type_string ) ;
type_uint: U8 | U16 | U32 | U64 ;
type_float: F32 | F64 ;
...
0
votes
0
answers
17
views
How can I convert a .sublime-syntax definition to a .tmGrammar.json file to use in VSCode(Monaco)?
I need to convert a .sublime-syntax definition to a .tmGrammar.json definition to use in VSCode. If this is possible then I would like to use it in an embedded Monaco Editor. The definition I'm trying ...
-2
votes
1
answer
39
views
ANTLR4 an optional symbol at begining of a rule
I'm learning how ANTLR4 works. I don't understand how to deal with optional symbol at the very beginning of a rule.
I have this simple grammar:
genericRule: optional otherPart ;
optional: ( 'A' | 'B' ...
8
votes
1
answer
104
views
How to pin a Raku Grammar token to only match when at the end of a string
I have written this - it works fine:
use Grammar::Tracer;
my grammar Lambda {
token TOP { <signature> <body> ' as ' <r-type> }
rule signature { '|' <a-sig> [','...
0
votes
1
answer
130
views
Why are curly braces {} NOT considered an operator in C++? [closed]
I've checked official operator list, but didn't see {} appear in any list of operator (either redefinable or non-redefinable).
As far as I know, {} is used to specify a block of code, and also used to ...
0
votes
0
answers
49
views
Using Tree Sitter, How to disable extras in string literal?
I am writing a Tree-Sitter grammar, I want to include escape sequences as child nodes within string literals, but I also want to avoid matching comments as extras within string literals.
The input &...
1
vote
0
answers
27
views
pyPeg2 recursive grammar rules
I'm trying to make a propositional logic parser, that can take in an input like 'and(P(),not P())' and and convert it to And(Predicate(P),Negation(Predicate(P))). I'm doing this in python, using the ...
1
vote
2
answers
63
views
c function pointer, another syntax
In C, when we want to define a function pointer for the following type of functions:
int f(int x, int y);
we define a function pointer variable as
int (*fp)(int, int);
My question is, what is the ...
1
vote
1
answer
58
views
Capturing a group with a generic SQL dialect
I would like to define an expression of the grammar:
=expr + #native(...)
expr can be any valid expression in our grammar, and this currently works. However, #native(...) is a valid SQL statement in ...
0
votes
0
answers
42
views
Gingerit vs PySpellChecker
what's the difference between Gingerit and pyspellchecker and what are their advantages and disadvantages?
Gingerit example:
from gingerit.gingerit import GingerIt
text = "Hello world!"
...
1
vote
1
answer
28
views
SQL 4-valued logic table
What are the truth tables for the proposed 4-value logic in SQL that has both an A-value null and an I-value null? From here.
Using AND for this, 3VL looks like this:
How would the following table ...
0
votes
1
answer
41
views
ANTLR4: Need assistance with conditional handling of whitespace within grammar files
I am new to ANTLR, but have composed a largely-functional (4.13.0) parser/lexer for a particular access control syntax.
Introduction
Just for context, the end goal for this grammar implementation is ...
-2
votes
1
answer
38
views
How to define multi type as one type in golang [closed]
func GetFailedReasonAndErr (xxx) (string, error){
...
}
func AnyFailed (args ...(string, error)) {
for _, arg := range args {
if arg.error != nil {
return arg
}
}
}
func ...
0
votes
1
answer
24
views
antlr4 grammar how to specify parameters in any order
Suppose I wish to implement a call to a function that can take a number of different parameters:
graph(style=line, theme=dark, x=time, y=height)
In this example there are 4 parameters, identified by ...
0
votes
0
answers
8
views
Order-independency of Nonterminals in EBNF Grammar Spec
I have created a simple markup language that consists of simpe tags to write my blog texts. I write my blog post in that language and convert them into Html by a compiler.
User can specify the ...
0
votes
0
answers
16
views
gramEvol package Error in 1:possible.choices : argument of length 0
I am trying to write a grammar but i get an error
Error in 1:possible.choices : argument of length 0
here is my grammar
library(gramEvol)
rules <- list(
For = gsrule("for(i in ...
1
vote
1
answer
75
views
PyParsing: Conditional parsing, depending on value
I need to parse Touchstone files (version 1.1, and version 2.0), but these have a strange rule in the syntax (see page 11 in the 1.1 spec, the top paragraph starting with Note.
So, I need to change ...
0
votes
0
answers
14
views
resolving parsing ambiguity for syntactic lists
I am working on parsing promela code using kframework and encountered with ambiguity in the following grammar: (i.e. both Sequence and DeclLst is a syntactic list with separator ;)
Sequence ::= Step ; ...
0
votes
1
answer
65
views
How to check if a grammar is LL(1) and not ambigious
This is my first attempt of writing a grammar for a new (python-like) language I'm trying to parse using a Recursive Descent parser. I have no background on EBNF, context-free grammar and parsing and ...
0
votes
0
answers
10
views
VS-code personal grammar extension : add cross-theme custom styling
I am in the process of writing a VS-Code syntax extension for a small language of mine. So far, so good, but I wonder whether it is possible to style certain elements in a cross-theme fashion.
This ...
-1
votes
3
answers
255
views
Why is int*& used to declare a reference to a pointer instead of int&*
I thought & and * were just syntactical conventions to declare pointers and references, but when trying to declare a reference to an int*, I have to use int*& otherwise I get this error:
...
1
vote
3
answers
95
views
gcc no error with extra comma in array initializer
Here's an example:
int main ()
{
int a[] = {1, 2, 3,};
}
Note the extra , after 3. There is no warning even with -Wall and everything. I noticed this while reading some coreutils code that seemed ...
0
votes
0
answers
35
views
Python define simple expression language (bash like)
I want to define my own simple language for evaluating literals.
Requirements:
Based on python to allow easy use/addition of Python functions (not shown in the example)
Token should be iterpreted as ...
0
votes
2
answers
41
views
How to know if two words are the same base?
I want to make an app where a user inputs some word, and then that word is detected and highlighted on the page. The difficult part is that I want all forms of the word to be detected. This would ...
0
votes
0
answers
15
views
CFGs for languages L1 and L2 where #a's > #b's and #a's >= #b's
Regarding the language L2 where the #a's >= #b's I thought of the following:
S -> SaSbS
S -> SbSaS
S -> SaS
S -> ε
When it comes to L1 I thought of utilising L2 in the following way ...
0
votes
0
answers
28
views
What are the criteria for determining if a language can be parsed using recursive descent parsing?
How do i know if a language can be parsed by recursive descent parsing?
For example, how would i go about determining whether this language can be parsed in that manner:
Language = { s^p r^q | p > ...
0
votes
1
answer
87
views
ANTLR Grammar not
I started writing another C-like language a few days ago and I've gotten stuck here.
The "pointers" rule seems to be colliding with the * operator in the OP token and making the * operator ...
1
vote
0
answers
37
views
Create a NFA from BNF grammar
How do I create an NFA from BNF grammar?
What I am specifically stuck on is the fact when we have two cases of recursion in the grammar such as in:
< case > ::= < case > < int > 'b' |...
0
votes
1
answer
16
views
How to check the grammar of time series name to avoid reporting "empty set" when querying in Apache IoTDB?
I used the "select * from root.jj.1#_10#.*" statement to query data in Apache IoTDB Version 1.0.0, but it reported an empty set when this time series has data in it. I checked the official ...
0
votes
2
answers
54
views
Bison %nonassoc vs %token?
I've read a lot of sources, but yet can't understand what's the difference between: %nonassoc and %token?
I understand the difference between %left and %right but for me the first two sound the same.
...
0
votes
0
answers
105
views
How can I define bracket pair colorization for brackets inside comments for a VS Code language extension?
I'm making the TextMate grammar for a language to get syntax highlighting. This is the rule for @link tags in doc comments:
"scopeName": "source.amx.pawn",
"patterns": [...
0
votes
0
answers
36
views
Why does the .exe fail after I enter text?
I do not know how to code, but I found code for a simple grammar editor and I plugged it into pycharm it works, but is perhaps too simple for what I need, but it's something workable. I made it into a ...
0
votes
1
answer
45
views
Grammars, parsers and infinite loops
I'm not very familiarized with parsers and grammars, so I needed assistance understand correclty the subject.
Let's say I have a grammar and I want to define a parser for said grammar. Looking in ...
0
votes
0
answers
38
views
Is it possible to write an ANTLR grammar which allows a separator character to appear in an identifier?
Is it possible to write an ANTLR grammar such that:
foo:bar:baz
would be tokenized as foo, :, bar:baz?
The actual use case here is that we have a construct where we reference an object using the form &...
0
votes
0
answers
33
views
Is there a way to implicitly cast as a subtype in the method that returns itself?
public class Main {
public static class SuperClass {
public SuperClass returnThis () {
return this;
}
}
public static class ...
0
votes
0
answers
71
views
concatenation of a context-free language
If A is a language over {1,2,3}. Using A and the string variables p and q, we mathematically define the language B over {0,1,2,3}:
B = { p0q1 | p is empty or is a string in A, and q consists of one or ...
-1
votes
1
answer
40
views
Can epsilon production be assumed in a left recursive grammar
I have a grammar:
S->Sa|Sb
I want to know if I can assume S->e as a production in the grammar?
I.e.,
Is S->Sa|Sb is the same as S->Sa|Sb|e ?
e = null string (epsilon)
I am trying to ...
0
votes
1
answer
104
views
Converting the regular expression to a grammar [closed]
I have the following regular expression:
(12)*[34]+(5[67])*
How can I convert the expression to a grammar that is left recursive?
I came up with this. I did not follow any methods or anything...
G --&...
1
vote
1
answer
52
views
Method to prevent token splitting with Flex lexical analyser?
Currently using Flex to scan a grammar that defines a subset of C. Here is the .l file.
/*definitions*/
%{
#include <stdio.h>
int yylex(void);
%}
/*rules*/
%%
"int" ...
4
votes
1
answer
106
views
Trying to solve dangling else for a Mini-C grammar
I have this grammar:
translation_unit
::= external_declaration
| translation_unit external_declaration
external_declaration
::= function_definition
| declaration
...
0
votes
2
answers
53
views
mismatched input in ANTLR4
I'm new to ANTLR. I don't see any problem with my grammar, but when I run the parse tree, ANTLR gives me mismatched input message. Could anyone help me explain why I get that?
Here is my lexer
lexer ...
1
vote
1
answer
94
views
Match anything until end tag (generic text) in simple lexer/parser using ANTLR4
I want to make a simple parser for a simple scripting language, it has text blocks and script blocks, inside those scriptblocks, I want to be able to define a function, as well as execute generic ...
0
votes
2
answers
149
views
Type theory with an Any/Variant type
Let's say I have a type system that has has three primitive types in addition to the null value:
null
bool
num
string
Additionally, there is a typed array for each of the types, so we now have: null,...
0
votes
1
answer
30
views
What is the Julia MethodError?
I am trying to create a function that corrects the grammar of a string, but it generates a MethodError saying no method matching ::Colon. Is there some problem with the package or am I using it wrong? ...