Questions tagged [syntax]

The tag has no usage guidance.

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

Why are ] and } not considered special characters?

Reading the manual for GNU grep, the special characters (with -E option) are .?*+{|()[\^$. This is a somewhat pedantic question, but why are ...
Eric Auld's user avatar
  • 115
2 votes
1 answer
38 views

What is the proper way to write logic formula, say concerning graph theory?

Say for example I'd like to state that there exists a pair of vertices such that they form an edge in one graph but not some other graph. I'd go about it as follows: $$ \exists u, v \in V, (u,v) \in G,...
J. Schmidt's user avatar
0 votes
0 answers
51 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 ...
StackMachine's user avatar
2 votes
1 answer
120 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, ...
Toothpick Anemone's user avatar
0 votes
1 answer
117 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 {[...
Mtuo's user avatar
  • 3
19 votes
4 answers
11k 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 ...
Jonte YH's user avatar
  • 423
0 votes
1 answer
306 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 ...
gust's user avatar
  • 155
1 vote
2 answers
94 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$...
Abhishek Ghosh's user avatar
1 vote
1 answer
59 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/...
Giorgi Tsiklauri's user avatar
5 votes
2 answers
925 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 ...
Buddhika Chathuranga's user avatar
3 votes
1 answer
81 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/...
digilante's user avatar
1 vote
1 answer
485 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, ...
master_of_privates's user avatar
3 votes
0 answers
87 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 ...
phipsgabler's user avatar
3 votes
2 answers
2k 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 ...
Foad's user avatar
  • 201
2 votes
1 answer
1k 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 ...
Foad's user avatar
  • 201
-2 votes
1 answer
630 views

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

...
bletectijkl's user avatar
4 votes
2 answers
144 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. ...
Alasdair McLeay's user avatar
3 votes
3 answers
955 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 (...
user56834's user avatar
  • 3,652
0 votes
0 answers
156 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
58 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 ...
Turing101's user avatar
  • 1,190
0 votes
1 answer
123 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 ...
Tim's user avatar
  • 4,845
13 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 ...
halloleo's user avatar
  • 257
3 votes
1 answer
109 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 ...
user56834's user avatar
  • 3,652
1 vote
1 answer
172 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 ...
user101144's user avatar
1 vote
1 answer
42 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. ...
Shiny_and_Chrome's user avatar
0 votes
1 answer
37 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? ...
Chrismo16's user avatar
5 votes
1 answer
329 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 ...
urbanspr1nter's user avatar
3 votes
1 answer
180 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 ...
TomR's user avatar
  • 1,381
0 votes
1 answer
855 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 ...
ice1000's user avatar
  • 928
2 votes
1 answer
178 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 (...
MarkokraM's user avatar
  • 385
5 votes
0 answers
349 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 ...
Paul J. Lucas's user avatar
3 votes
1 answer
127 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. ...
盛安安's user avatar
  • 934
1 vote
1 answer
444 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.
aurelien's user avatar
  • 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 ...
Dave's user avatar
  • 495
0 votes
1 answer
32 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 ...
tsp216's user avatar
  • 101
1 vote
1 answer
88 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. ...
user1868607's user avatar
  • 2,184
1 vote
1 answer
551 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" ...
fronthem's user avatar
  • 285
-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 ...
Display Name is missing's user avatar
8 votes
2 answers
576 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 ...
NlightNFotis's user avatar
5 votes
1 answer
776 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 ...
tedd's user avatar
  • 53
1 vote
3 answers
2k 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: ...
Jack's user avatar
  • 153
-1 votes
1 answer
837 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 ...
mavavilj's user avatar
  • 567
7 votes
2 answers
1k 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 ...
François's user avatar
  • 659
2 votes
2 answers
3k 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 ...
daltonfury42's user avatar
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, ...
babou's user avatar
  • 19.4k
1 vote
2 answers
291 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 ...
it's scientific's user avatar
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 ...
Chirac's user avatar
  • 133
3 votes
2 answers
119 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 ...
Adam-Morgan's user avatar
0 votes
2 answers
284 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\...
ka8512's user avatar
  • 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 ...
Eng_Boody's user avatar
  • 175