Questions tagged [syntax]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
40 views

what are all the ways of delimiting blocks

To my knowledge, in block-structured programming languages, there are 2, maybe 3 main ways of delimiting a block. Using start and end tokens, this can be brackets or reserved words etc Using ...
2 votes
1 answer
56 views

What role does an asterisk serve in Backus–Naur Normal Form?

Suppose that you were reading some production rules for a context-free grammar in Backus–Naur Normal Form What does the asterisk (*) mean? In the example below, ...
0 votes
1 answer
66 views

find LR(1) items of the first state

I need to calculate the LR(1) items of the following grammar: S -> E E -> E + T E -> T T -> ID T -> ( E ) I can not even calculate the first group {[...
  • 3
18 votes
4 answers
9k views

Are modern programming languages context-free?

Which language class are today's modern programming languages like Java, JavaScript, and Python in? It appears (?) they are not context-free and not regular languages. Are these programming languages ...
  • 413
0 votes
1 answer
176 views

BNF syntax for a recursive function?

I'm to write a syntax that will allow for a recursive function, i.e. f(x) = if x == 0 then x else f(x+1) Here's one attempt at creating the grammar: But I don't ...
  • 155
1 vote
2 answers
77 views

Relation between programming languages requiring declaration of variables before use and using the token class $\text{id}$ while parsing

I was going through the text Compilers: Principles, Techniques and Tools by Ullman et. al. where I came across the following excerpt. Example 4.11. Consider the abstract language $L_1 = \text{ { $wcw$...
1 vote
1 answer
56 views

Reason behind declaring iteration variables on a method level

Lately, I have been in touch with some C++ snippets, and I have a very strange observation on the tiny detail: Most of the times, I see, that people declare iteration variables outside of the for/...
5 votes
2 answers
881 views

Break keyword outside a loop is syntax error or semantic error?

I am designing a simple compiler for my university project. In my programming language, the break keyword is allowed. I want to know whether break keyword occurs outside a loop should be a syntax ...
3 votes
1 answer
74 views

How is `y λx.x y` parsed using the standard pure untyped lambda calculus conventions?

How would the following term in the pure untyped lambda calculus be parsed: y λx.x y The relevant conventions listed on https://en.wikipedia.org/wiki/...
1 vote
1 answer
358 views

What does "lookahead" refer to?

I keep hearing about lookahead parsers, LL parsers, LR, LALR, etc... but no clear explanation behind the etymology of this word. What does "lookahead" refer to? How does this relate to LL, ...
3 votes
0 answers
77 views

Semantics of "write-once" variables for complex data structures

Question My use case for what is described below is not a language or compiler implementation, but finding a reasonable semantics for this feature in a an abstract calculus. Ideally, you give me a ...
2 votes
2 answers
1k views

What are the modern alternatives to Backus–Naur form and what are their advantages?

I am very new to the whole concept of context-free grammars to represent the syntax tree of formal languages (i.e., programming languages). It seems that the Backus–Naur form (BNF) is the oldest of ...
  • 191
2 votes
1 answer
910 views

What are the known ambiguities in C language grammar?

I have found this reference for the C syntax Backus-Naur Form (BNF). I was wondering if there are any other ambiguities in this grammar other than the infamous "dangling else"? Also how we ...
  • 191
-2 votes
1 answer
532 views

When setting a variable in python, why does the order matter? [closed]

...
4 votes
2 answers
140 views

Origin of using ">" to represent child in a tree

What are the earliest known uses of the "greater than"/"chevron" symbol (>) to denote a parent-child relationship in a tree structure? i.e. parent > child e.g. ...
3 votes
3 answers
684 views

Is type-checking "syntactic" or "semantic"?

On the wikipedia page on compilers, it says: Semantic analysis adds semantic information to the parse tree and builds the symbol table. This phase performs semantic checks such as type checking (...
  • 3,462
0 votes
0 answers
155 views

Was there an attempt to create a programming language aimed for maximal abstraction?

I am trying to understand if a programming language can have totally or almost totally the abstraction level shared between generally all human languages so that it would allow a human to code a ...
user avatar
0 votes
1 answer
57 views

What kind of error are these?

I was following a discussion on a forum where a person has asked whether the following generates lexical errors or not, (1) char p="gate; (2) int /* n; (3) printf("%d, n); When I tried ...
  • 1,170
0 votes
1 answer
112 views

Do the following concepts belong to syntax or semantics?

I am not very sure about the difference between syntax and semantics. Does each of the following concepts belong to syntax or semantics? terms values: terms that are possible final results of ...
  • 1
12 votes
3 answers
4k views

Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks? [closed]

Python quite famously uses indentation to syntactically define blocks of code. (See Compound statements in the Python Language Reference). After years of using Python I'm still intrigued by and very ...
  • 247
3 votes
1 answer
104 views

What is the relation between syntax and type theory?

Type theory and syntax are similar, in that they are inductive rules that determine whether a particular string of symbols is "correctly specified" in some sense. There is a difference between ...
  • 3,462
1 vote
1 answer
141 views

Why is the syntax of some programming languages very much not according to earlier conventions? [closed]

Looking at the syntax of the programming language C and others inspired by it, I cannot help but ask the question in the title. Mathematics, logic and other subjects have been existing for many ages ...
1 vote
1 answer
36 views

defining a programming language grammar for doing arithmetic

I'm studying programming language design, and I've been taught the grammar below which lets you write basic math expressions. ...
0 votes
1 answer
34 views

For Loop Range with Smaller Number on Right

Simple question from an algorithm noob... If $i=1$ then the inner loop will include what I believe to be an invalid range. Is this acceptable pseudocode? ...
4 votes
1 answer
205 views

Parser theory: How to systematically compute FOLLOW sets?

Forgive me for my ignorance as I am self-teaching myself some of this theory... I am having some trouble understanding how to systematically/algorithmically compute FOLLOW sets, given that I have ...
3 votes
1 answer
158 views

Simple example for Higher Order Abstract Syntax (λ-tree syntax)

I am reading https://www.cs.cmu.edu/~fp/papers/pldi88.pdf and https://en.wikipedia.org/wiki/Higher-order_abstract_syntax for trying to understand encoding of linear logic using HOAS into Coq. But I ...
  • 1,361
0 votes
1 answer
739 views

Why postfix arithmetic expression is not ambiguous?

A binary tree can be written as an expression, no matter prefix, postfix or infix. But why an infix expression needs brackets, while the others don't? Say, why postfix, prefix produce only one binary ...
  • 888
2 votes
1 answer
169 views

Is this DO LET sugar considered pure Lambda calculus and nullipotent / side-effect-free?

I'm thinking these familiar concepts of DO and LET/LET* in the context of Lambda Calculus (...
  • 385
6 votes
0 answers
313 views

Dennis Ritchie citation for "the C declarator syntax is an experiment that failed"?

I've often heard that the C declarator syntax described as "an experiment that failed." I've seen claims that this sentiment is also shared by its creator Dennis Ritchie. Does anybody have an actual ...
3 votes
1 answer
122 views

Is there a correspondence between the syntaxes and the type systems of programming languages?

I was reading the first chapter of Robert Harper's Practical Foundations for Programming Languages in which it introduced abstract binding trees, aka abt. It seems pretty like typed lambda calculus. ...
  • 914
1 vote
1 answer
443 views

Which part of Go(lang) is in Crystal(lang)? [closed]

Reading Crystal Programming Language They says it is inspired from many programming language and Go. I would like too know which part of Golang, since it is not its syntax.
  • 113
2 votes
0 answers
1k views

What is the importance of the empty string in CFG derivations?

NOTE: This question is NOT the same as this other nearly-identically worded question with some amazing answers. I learned a lot from it regarding the mathematical importance of the empty string, but ...
  • 485
0 votes
1 answer
30 views

Why does the following Backus-Naur form reflect the following syntax diagram?

The definition of the variable < number>::=< digit > | < digit >< number > where < digit > is defined as < digit > ::= 1|2|3|4|5 Apparently reflects the following syntax ...
  • 101
1 vote
1 answer
87 views

Implementing Do keyword in a compiler

I'm writting a compiler implementation for a language that you can see defined here. I having problems designing how the do keyword should be handled. You can find the code I'm referring to in here. ...
  • 2,230
1 vote
1 answer
522 views

Relation between "syntax" and "grammar" in CS

I do sure that "grammar" and "syntax" is two different thing in CS, e.g Syntax of Java language is defined by a context-free grammar. My question are What is different in definitions of "grammar" ...
  • 265
-1 votes
2 answers
8k views

In a bottom-up evaluation of a syntax directed definition, inherited attributes can

In a bottom-up evaluation of a syntax directed definition, inherited attributes can always be evaluated be evaluated only if the definition is L-attributed be evaluated only if the definition has ...
8 votes
2 answers
525 views

Why is BNF considered an unsatisfactory technique for describing a language?

I was reading the paper Fundamental Concepts in Programming Languages by C. Strachey the other day, wherein I read something that was quite strange to me. Quoting directly (with the strange part ...
5 votes
1 answer
731 views

Examples of context sensitive syntactic constructs (statements)

So, I am implementing a context sensitive syntactic analyzator. It's kind of an experimantal thing and one of the things I need are usable syntactical contructs to test it on. For example, the ...
  • 53
1 vote
3 answers
1k views

Does precedence matter in constructing parse trees of arithmetic expressions for postfix notation?

Table 4 in Problem Solving with Algorithms and Data Structures's chapter on Infix, Prefix and Postfix Expressions gives the following examples: ...
  • 153
-1 votes
1 answer
816 views

Programming Thompson's algorithm: How to represent a NFA?

I'm trying to create a small program that interprets a NFA to the corresponding regex using Thompson's algorithm. My question: What kind of notation can be used to express a NFA (e.g. in the form of ...
  • 559
7 votes
2 answers
984 views

Are syntax and semantic just 2 structures such that one is a model of the other?

The syntax of a language is a structure. The semantic of a language is a structure. The semantic of a language is a model of its syntax. And that's all ? The duality syntax/semantic is just model ...
  • 669
2 votes
2 answers
2k views

How to read BNF syntax of C?

Today I heard of BNF which is a language for languages. Also heard that it specifies the entire syntax of C in four pages. So I thought of checking it out. After reading through this page, I got a ...
3 votes
0 answers
51 views

A syntactic property of computing systems: is non-coding DNA universal?

One of the surprising aspect of the genome for lay-people is that it contains important non-coding DNA parts, which does not mean that they are all useless. I never paid so much attention to the fact, ...
  • 19.2k
1 vote
2 answers
278 views

Terminology - the reason for symbol reuse in programming languages

What is the term in programming language creation that is the rationale for symbol reuse? Though potentially confused with overloading, it is not so much the application of symbol reuse, but the ...
2 votes
2 answers
1k views

Why are syntax trees used in genetic programming?

Reading a course on genetic programming, the first chapter describes the syntax tree as the basic representation of programs in genetic programming. What are the reasons leading to the choice of a ...
  • 133
3 votes
2 answers
118 views

Differences in Postfix Syntax

A question about postfix/RPN came up in my class due to the current ACSL competition. Is it a rule or convention that 4 + (5 * 6) in infix is written 4 5 6 * + in postfix, as opposed to 5 6 * 4 + in ...
0 votes
2 answers
263 views

generating recursive descent parser

I have a grammar, $L \to A \langle A \rangle^*$ $A \to () \mid (L)$ but I am not sure how to generate parser for $\langle A \rangle$. I know in other case, for example, if $E \to T \langle^*T\...
  • 5
2 votes
2 answers
1k views

What do I need to study in order to understand and design a programming language? [closed]

What do I need to read in in order to : understand the specs of an already made programming language Design a programming language Design a compiler and assembler for that language make an ...
  • 175