Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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
votes
2answers
82 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 ...
2
votes
1answer
74 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 ...
3
votes
0answers
121 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 ...
4
votes
0answers
46 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. ...
1
vote
0answers
29 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 ...
2
votes
0answers
32 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 ...
3
votes
1answer
87 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 ...
0
votes
2answers
457 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, ...
6
votes
0answers
194 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: ...
2
votes
1answer
58 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 ...
5
votes
1answer
76 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 ...
2
votes
1answer
655 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,...
3
votes
1answer
105 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): ...
6
votes
1answer
63 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 ...
1
vote
1answer
298 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 ...
2
votes
1answer
97 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 ...
8
votes
2answers
4k 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 ...
2
votes
1answer
831 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 ...
4
votes
1answer
169 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 ...
6
votes
3answers
1k 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 ...
10
votes
1answer
344 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 ...
11
votes
1answer
208 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 ...
4
votes
1answer
295 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: ...
3
votes
2answers
184 views

Perl 6: Grammar issues (simple defines)

My goal is to parse defines in Objective-C code: ...
4
votes
1answer
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 ...
2
votes
1answer
164 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 ...
8
votes
1answer
358 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 ...