2022 Developer Survey is open! Take survey.

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.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
82 views

A Rough(bad) Example of a Recursive Descent Parser in Java [closed]

I have written a program that parses this code but it doesn't use recursive descent. So I am starting over and need help. Just so everyone is on the same page: Using recursive descent it needs to ...
user avatar
3 votes
0 answers
33 views

ANTLR4 grammar for tags substitution

I want your criticism of the following ANTLR4 grammar intended for use in templating engine of sorts. Its task is to look through (presumably rather short) potentially multiline piece of plaintext, ...
user avatar
4 votes
1 answer
186 views

Is there a better way to parse this data file?

I have a text data file in SPWLA format; I cannot find a specification for it. It contains physical measurements and/or rock descriptions from wellbore core samples. It's fairly gross. The example ...
user avatar
  • 141
10 votes
3 answers
1k views

Recursive Descent Parser Implementation for a Recursive Language

I'm writing toy parsers for toy languages to understand how parsers work. Assuming a language as follows (in sketchy EBNF patois) ...
user avatar
  • 232
3 votes
2 answers
109 views

Removing commented dead code without removing the legitimate comments

This question is the real question asked on StackOverflow. I'm here to review my answer and see how can I optimize it. Here is the answer text: This is a basic approach, but it proposes a proof of ...
user avatar
3 votes
1 answer
194 views

Parsing a C++ function declaration with Perl 6 grammar

I wrote a Perl 6 grammar to parse a C++ function. My final goal would be to parse an entire header. The aim is not to correct C++ syntax errors, but to parse valid C++. Do you have some advice or ...
user avatar
  • 311
4 votes
0 answers
403 views

Eliminating chain rules from context-free grammars

I'm writing a small C program for elimination of chain rules from a context-free grammar. My idea is to rewrite the rules of the grammar in a specific useful order: making groups of productions that ...
user avatar
4 votes
0 answers
49 views

Parsing λ-terms using a very simple grammar

This is my first Rust program. It parses a string into a λ-term using a very simple grammar. Please evaluate style and use of ownerships / borrowing. ...
user avatar
  • 1,091
4 votes
0 answers
59 views

Correct user typos in a C source file using Perl 6 grammar

To learn about Perl 6 grammars, I created a simple parser for C source files. Note that this is a constructed example motivated by this question. The point is to parse a C source file and correct user ...
user avatar
2 votes
0 answers
33 views

dyon vim syntax plugin

I recently made vim-dyon which is a syntax highlighter and indenter for the dyon programming language. There are probably some issues with being absolutely correct (since I am not too familiar with ...
user avatar
  • 5,599
3 votes
1 answer
97 views

Syntax for a simple scripting language [closed]

I'm creating a small simple scripting language for fun and as a learning exercise. For the first iteration I want it to be very simple: C-style syntax Functions are defined globally as in C, no ...
user avatar
0 votes
2 answers
1k views

Regular expression to identify java function

I am trying to identify a java function block addition in a diff file (new line start with + in diff). For that I am using regular expression. It is working fine, ...
user avatar
  • 101
10 votes
1 answer
430 views

PEG.js grammar for a simple programming language

I'm trying my hand at developing a compiler and have written a peg.js grammar for a simple programming language. A sneak peak at the grammar: ...
user avatar
2 votes
1 answer
62 views

Overly large syntax highlighting function

I've written a text editor in Rust. make_highlights is responsible for syntax highlighting. It takes a Row, which is just a ...
user avatar
  • 123
5 votes
1 answer
93 views

Grammar for a custom language called Elegance

I'm working on my own custom language called Elegance. This is my first grammar, and I'm looking for help with: Readability Expressiveness/DRY code (Can I easily reuse rules/tokens?) Edge cases (Is ...
user avatar
2 votes
1 answer
1k views

Checking proper English sentences of user's input with grammar using C++

Write a program that checks if a sentence is correct according to the “English” grammar in §6.4.1. Assume that every sentence is terminated by a full stop (.) surrounded by whitespace. For example,...
user avatar
3 votes
1 answer
195 views

Converting to and from Roman numerals

I wrote a simple Boot script for converting to and from Roman numerals using instaparse. Here's my EBNF grammar (roman.bnf): ...
user avatar
  • 1,737
6 votes
1 answer
75 views

Haskell tool for find @SuppressWarnings in Java source code

I put together a little tool for finding where people have suppressed warnings, and to see if they have commented why. Its in Haskell for fun and some practice. Its split into two files, the thinking ...
user avatar
  • 163
1 vote
1 answer
464 views

Grammar lexer in C++

Here is a lexer for a grammar I'm designing. After benchmarking with 1MB files and having several iterations of the lexer, I found that coping the file being read into a buffer and lexing that buffer ...
user avatar
  • 115
2 votes
1 answer
187 views

L-Systems in OCaml

For reference: L-system I'm mostly looking for general style stuff here and in particular: if my type parameters are too crazy — I wanted two parameters so that variables and constants could have ...
user avatar
8 votes
2 answers
6k views

Yet another lexical analyser

The following program is a lexical analyser for a simple and small grammar. Please read my code and answer me these questions: Is my code easy to understand? Is my code well organized? Are there ...
user avatar
  • 993
2 votes
1 answer
1k views

FIRST and FOLLOW sets calculator in Haskell

I found myself wanting to brush up on some notions about parsers and grammars and, at the same time, to exercise my Haskell - I am a Haskell newbie; moreover, I haven't touched the language at all in ...
user avatar
4 votes
1 answer
229 views

Syntax highlighter for HTML and PHP

I've created a JavaScript application to highlight the syntax of HTML and PHP. I know a lot of syntax highlighter are available nowadays, I just created to extend my knowledge in JS and regular ...
user avatar
7 votes
3 answers
2k views

AST implementation

I'm new to C++, so I'm trying to learn the language by implementing all the type systems and languages in Pierce's Types and Programming Languages. My first attempt starts at the very beginning and ...
user avatar
10 votes
1 answer
497 views

Unit test code for Antlr Grammar

I'm working on a grammar for the Visual Basic for Applications (VBA) programming language. I've discovered a way to make assertions about how a parse tree should be generated by using the Antlr ...
user avatar
  • 448
11 votes
1 answer
244 views

Reference Implementation for Honey Badger programming language

I've been working on my own dynamically-typed, dynamically-scoped, imperative programming language called Honey Badger and feel that it's reached a stable enough state that I want someone else's eyes ...
user avatar
4 votes
1 answer
382 views

Expressing Rebol Dates in EBNF

I'm looking to define the Rebol date format in EBNF notation. I'd like as best as possible to only define valid dates—at least those that are valid in Rebol at the moment: ...
user avatar
  • 489
3 votes
2 answers
208 views

Perl 6: Grammar issues (simple defines)

My goal is to parse defines in Objective-C code: ...
user avatar
4 votes
1 answer
1k views

PEG.js grammar for parsing CSS selectors

I have a library that's parsing some expressions, part of which is a CSS selector. More accurately, it's a jQuery-compatible selector. The selector itself is opaque to my library - I don't need to ...
user avatar
  • 910
2 votes
1 answer
175 views

Expanding a synchronous grammar

Background: A synchronous grammar is a like two context-free grammars connected in parallel. It is used for translation. For example, here is a small synchronous grammar that can be used for ...
user avatar
8 votes
1 answer
463 views

Parsing a basic scripting language

I'm working on writing a scripting language with ANTLR and C++. This is my first actual move from ANTLR grammars into the C++ API, so I'd like to know if this would be a good way to structure the ...
user avatar