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.

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.

A grammar is formally defined as a 4-tuple, consisting of a series of production rules, terminal symbols, nonterminal symbols, and a start symbol, which itself is a nonterminal. Any terminal cannot be a nonterminal and vice-versa.

Grammars prove very useful in parsers for programming languages. A grammar can be used to determine the syntactical correctness of a given string.

Parser generators such as JavaCC or ANTLR use a given grammar (usually one of a particular form, and free of ambiguities) to generate the parser.

3251 questions
1
vote
1 answer

Check for bound variables fails for K combinator

I recently got in possession of a copy of "Essentials of Programming Languages", second edition. At page 29, the book introduces the following Scheme-flavored grammar for lambda calculus: ::= ::= (lambda…
Ilio Catallo
  • 3,152
  • 2
  • 22
  • 40
1
vote
0 answers

Display word endings depend on gender (Polish language issue), PHP

This problem might not occure in English, but does really hurt in Polish language. I guess that my question is mostly for Polish users since they might already have a decent solution. What I mean, is that the verbs in Polish language, are different…
Zorann
  • 335
  • 2
  • 16
1
vote
0 answers

How to prove that the grammar G is not LL(1)

The grammar is: L => LE | E E => (C) | (F) | V | T C => ifEE | ifEEE F => +L | -L | *L | printL V => a | b | c | d T => 0 | 1 | 2 | 3 I think it is not LL(1) because of C => ifEE | ifEEE, but I am not sure if it is correct... Can anyone help me to…
seung
  • 53
  • 1
  • 7
1
vote
1 answer

What expression statements in ECMAScript actually are

Let's say that at some point of a parsing process, I've already traversed the following grammar derivation: Script -> ScriptBody -> StatementList -> ExpressionStatement -> Expression Here comes the trouble. According to the spec, an Expression…
WTEDST
  • 925
  • 5
  • 15
1
vote
1 answer

In Bison (or yacc for that matter), is there an order defined by a grammar?

I have the following grammar in a Bisone file: item : "ITEM" t_name t_type v_storage t_prefix t_tag ';' ; t_name : [$_A-Za-z][$_A-Z0-9a-z]* ; t_type : "BYTE" | "WORD" | "LONG" | "QUAD" ; v_storage : %empty …
JonBelanger
  • 150
  • 3
  • 12
1
vote
2 answers

Requiring matching parentheses in ANTLR

I know that in ANTLR4 I can use ? for 0 or 1 times. But For example for identifiers, the user may or may not use parentheses. But if I do this '('? identifier ')'? The parser will allow statements like : '(x' or 'y)' instead of requiring (x). Is…
Pape Traore
  • 83
  • 2
  • 9
1
vote
1 answer

How to get a control flow graph of a program?

I want to get a control flow graph of a code/program (be it any programming language and given its grammar). I have tried using lark library in python to parse a basic C sample program [I provided the grammar for basic c syntax to lark]. As a…
1
vote
1 answer

Can all ambiguous grammars be converted to unambiguous grammars?

There are grammars we convert to unambiguous by using left recursion. Are there grammars that cannot be converted to unambiguous grammars?
Mizu
  • 25
  • 3
1
vote
0 answers

ANTLR4 not able to parse normal text

I want to parse latex file so that i can convert it into html. I started with basic minimum text file. But the tree created by "grun Tex_grammar start -gui" is showing errors. I think there is some error in the code which i am not able to figure…
1
vote
1 answer

Extracting PostgreSQL grammar rules

I am trying to gather information with regards to the grammar of PostgreSQL (and, in the future, other database systems) to be used in a website (frontend Angular, backend Java). It seems that the grammar rules are contained in the file gram.y…
1
vote
2 answers

Expressions in a CoCo to ANTLR translator

I'm parsing CoCo/R grammars in a utility to automate CoCo -> ANTLR translation. The core ANTLR grammar is: rule '=' expression '.' ; expression : term ('|' term)* -> ^( OR_EXPR term term* ) ; term : (factor (factor)*)?…
J Evans
  • 1,090
  • 2
  • 16
  • 36
1
vote
1 answer

ANTLR/Grammar issue: calculator language

I'm attempting to create a boolean expression language/grammar for a personal project. The user will be able to write a string in a Java-like syntax, with provision for variables, which will be evaluated at a later time when the variables have been…
Trasvi
  • 1,207
  • 1
  • 15
  • 23
1
vote
1 answer

Can not provide for host variables in Antlr3 SQL grammar

I have a SQL grammar which do not have support for host variables. I want to provide support for host variables in that but a situation that I have encountered is tricky. There is SQL Identifier lexer rule in grammar, which supports alphanumeric…
Abhishek Tiwari
  • 332
  • 2
  • 16
1
vote
1 answer

ANTLR3 grammar does not match rule with predicate

I have a combined grammar where I need to provide for two identifier lexer rules. Both identifiers can be used at the same time. Identifier1 comes before Identifer2 in grammar. First identifier is static, whereas second identifier rule changes on…
Abhishek Tiwari
  • 332
  • 2
  • 16
1
vote
1 answer

ANTLR4 input grammar

How can I write this grammar expression for ANTLR4 input? Originally expression: = 0|(1 -9){0 -9} = ’( ESC |~( ’|\| LF | CR )) ’ = "{ ESC |~("|\| LF | CR )}" I tried the following…
1 2 3
99
100