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
59 views

Improvement for parsing LTL grammer

I'm new here. I wrote the following code to parse the linear temporal logic(LTL) formula and evaluate it with respect to a trace. But I'm totally not happy with my code because I think the complexity ...
Jahid Chowdhury Choton's user avatar
-2 votes
1 answer
154 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 ...
Corey Hodges's user avatar
3 votes
0 answers
39 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, ...
Fedor Kotov's user avatar
4 votes
1 answer
305 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 ...
kwinkunks's user avatar
  • 141
10 votes
3 answers
2k 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) ...
Hugo's user avatar
  • 232
3 votes
2 answers
126 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 ...
ndrwnaguib's user avatar
3 votes
1 answer
259 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 ...
tejas's user avatar
  • 311
4 votes
0 answers
494 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 ...
Alex Konrad's user avatar
4 votes
0 answers
52 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. ...
MaiaVictor's user avatar
  • 1,101
4 votes
0 answers
63 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 ...
Håkon Hægland's user avatar
2 votes
0 answers
35 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 ...
Dair's user avatar
  • 5,824
3 votes
1 answer
103 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 ...
JamesMac's user avatar
0 votes
2 answers
2k 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, ...
g_p's user avatar
  • 101
10 votes
1 answer
608 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: ...
Logarytm Całkowy's user avatar
2 votes
1 answer
66 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 ...
isaacg's user avatar
  • 123
5 votes
1 answer
96 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 ...
Nathan Merrill's 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,...
Herman Tam's user avatar
3 votes
1 answer
252 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): ...
Sam Estep's user avatar
  • 1,757
6 votes
1 answer
80 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 ...
jk.'s user avatar
  • 163
1 vote
1 answer
545 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 ...
Hedron's user avatar
  • 115
2 votes
1 answer
203 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 ...
mostsquares's 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 ...
Gabriel's user avatar
  • 1,053
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 ...
Tobia Tesan's user avatar
4 votes
1 answer
233 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 ...
Anish Silwal's 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 ...
user202953's user avatar
10 votes
1 answer
582 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 ...
Rossco's user avatar
  • 448
11 votes
1 answer
259 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 ...
Joshua Snider's user avatar
4 votes
1 answer
405 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: ...
rgchris's user avatar
  • 489
3 votes
2 answers
211 views

Perl 6: Grammar issues (simple defines)

My goal is to parse defines in Objective-C code: ...
gaussblurinc's 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 ...
sqykly's user avatar
  • 930
2 votes
1 answer
179 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 ...
Erel Segal-Halevi's user avatar
8 votes
1 answer
484 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 ...
Sam Bloomberg's user avatar