Search results
Top results related to what are procedural languages in programming
Top Answer
Answered Jan 13, 2016 · 6 votes
What are Invariants
Invariants in any field - are values (usually numbers) that allow you to distinguish "objects" if those invariants are not the same.
For example if you have a mathematical term say
(x+3)²+1-
and you want to transform that term one invariant would be to substitute a random number for x, my rng chose x=0 - so the invariant would be
(0+3)²+1 = 9+1 = 10-
then if I transform the term incorrectly
x²+6x+3 + 1 = x² + 6x +4-
testing again with x = 0 I see 0²+0+4 = 4 which is different from 10 therefore I know there had to be a mistake. But if on the other hand I had transformed the term to
x²+3x+9 +1 = x²+3x+10-
the invariant for x=0 would be 10 again - so we see
Why are they useful?
- different invariants => different objects
- same invariants => maybe same objects
why has this become interesting in (functional) programming - one expression you will hear in this context is equational reasoning and this means just the procedure I did above if you can transform an algorithm/function/term into another one without loosing equality. This is often true for languages like haskell, by restriction of immutability, no side effects etc. whereas in oo this is often not true. Equational reasoning allows you to shrink the area where errors turned up quite good so debugging/bug finding is comparatively more easily done.
Another field where invariants are common is property based testing: here the standard example for this reverse :: [a] -> [a], i.e. the reverse function on (linked) lists, has the property of reverse . reverse == id, i.e. reversing twice is the same as doing nothing. If you put this in a Quickcheck test - the test generator generates arbitrary lists and checks this property - if one of these (potentially) thousands of tests fail you know, where to improve your code.
Some properties also can used to make optimizations of your code for example if for all functions fmap f . fmap g == fmap (f . g) and the left hand side traverses a data structure twice, where the right hand side only does one traversal, the compiler can substitute them and make your code twice as fast.
1/5
Top Answer
Answered Aug 10, 2020 · 1 votes
This is more a artifact of the language, rather than a programmer oriented feature.
For python and javascript, the new variable means allocate an entry in the name dictionary, until you actually create an object and assign it. In C++ there is no name dictionary in the run-time, the definition needs to actually allocate memory for the object (and it could be a 10MB array for all we know).
This does allow C++ to fit into smaller memory footprint if you really need that. Otherwise there's no much reason to think about it.
From the developer's perspective you have a bug. Your x has 2 meanings. Programming is hard enough as it is without having variables change meaning on you, so I would avoid as much as possible. I think C++ would give you a warning in some such a cases.
In practice you would get used to either setup.
2/5
Top Answer
Answered Aug 02, 2010 · 4 votes
So, the how part for languages like SQL is specified by the language itself, is it?
Not strictly by the language (ie. SQL), but normally by the database and its optimiser. As such, even where the same data is being queried from tables with the same structures and the same indexes, some databases will build the resultset in a different way to others.
Suppose I want to change the way a SELECT is handled. Is that possible?
To some degree, yes. You can either:
- Rewrite the query, to achieve the same result a different way, or
- Use hinting - http://en.wikipedia.org/wiki/Hint_%28SQL%29
Neither of these directly instruct the database engine which approach to use, but both of them will affect how the resultset is returned - this is likely to vary between databases.
Additionally, I understand that some databases have additional interfaces that allow more low-level interaction with the database engine, enabling greater control over how a query is built than is possible from plain SQL. (However, your question did specify SQL.)
3/5
Top Answer
Answered May 22, 2009 · 49 votes
The set of programs that are syntactically correct is context-free for almost all languages.
The set of programs that compile is not context-free for almost all languages. For example, if the set of all compiling C programs were context free, then by intersecting with a regular language (also known as a regex), the set of all compiling C programs that match
^int main\(void\) { int a+; a+ = a+; return 0; }$
would be context-free, but this is clearly isomorphic to the language a^kba^kba^k, which is well-known not to be context-free.
Other Answers
Answered Dec 18, 2021 · 71 votes
What programming languages are context-free? [...]
My gut tells me that functional languages might be context-free [...]
The short version: There are hardly any real-world programming languages that are context-free in any meaning of the word. Whether a language is context-free or not has nothing to do with it being functional. It is simply a matter of how complex the syntax is.
Here's a CFG for the imperative language Brainfuck:
Program → Instr Program | εInstr → '+' | '-' | '>' | '<' | ',' | '.' | '[' Program ']'
And here's a CFG for the functional SKI combinator calculus:
Program → EE → 'S' E E EE → 'K' E EE → 'I'E → '(' E ')'
These CFGs recognize all valid programs of the two languages because they're so simple.
The longer version: Usually, context-free grammars (CFGs) are only used to roughly specify the syntax of a language. One must distinguish between syntactically correct programs and programs that compile/evaluate correctly. Most commonly, compilers split language analysis into syntax analysis that builds and verifies the general structure of a piece of code, and semantic analysis that verifies the meaning of the program.
If by "context-free language" you mean "... for which all programs compile", then the answer is: hardly any. Languages that fit this bill hardly have any rules or complicated features, like the existence of variables, whitespace-sensitivity, a type system, or any other context: Information defined in one place and relied upon in another.
If, on the other hand, "context-free language" only means "... for which all programs pass syntax analysis", the answer is a matter of how complex the syntax alone is. There are many syntactic features that are hard or impossible to describe with a CFG alone. Some of these are overcome by adding additional state to parsers for keeping track of counters, lookup tables, and so on.
Examples of syntactic features that are not possible to express with a CFG:
typedef int my_int; my_int x;
E → E ^ E E → E × E E → E + E E → (E) E → num
E₀ → EA E₁ EA → E₁ + EA EA → ε E₁ → EM E₂ EM → E₂ × EM EM → ε E₂ → E₃ EP EP → ^ E₃ EP E₃ → num E₃ → (E₀)
- ["Indentation- and whitespace-sensitive languages like Python and Haskell. Keeping track of arbitrarily nested indentation levels is essentially context-sensitive and requires separate counters for the indentation level; both how many spaces that are used for each level and how many levels there are.","","Allowing only a fixed level of indentation using a fixed amount of spaces would work by duplicating the grammar for each level of indentation, but in practice this is inconvenient.","",""]
- ["The C Typedef Parsing Problem says that C programs are ambiguous during lexical analysis because it cannot know from the grammar alone if something is a regular identifier or a typedef alias for an existing type.","","The example is:","","","",""," typedef int my_int;"," my_int x;"," ","","","","","At the semicolon, the type environment needs to be updated with an entry for my_int. But if the lexer has already looked ahead to my_int, it will have lexed it as an identifier rather than a type name.","","","In context-free grammar terms, the X → ... rule that would trigger on my_int is ambiguous: It could be either one that produces an identifier, or one that produces a typedef 'ed type; knowing which one relies on a lookup table (context) beyond the grammar itself.","",""]
- ["Macro- and template-based languages like Lisp, C++, Template Haskell, Nim, and so on. Since the syntax changes as it is being parsed, one solution is to make the parser into a self-modifying program. See also Is C++ context-free or context-sensitive?","",""]
- ["Often, operator precedence and associativity are not expressed directly in CFGs even though it is possible. For example, a CFG for a small expression grammar where ^ binds tighter than ×, and × binds tighter than +, might look like this:","",""," E → E ^ E"," E → E × E"," E → E + E"," E → (E)"," E → num"," ","","This CFG is ambiguous, however, and is often accompanied by a precedence / associativity table saying e.g. that ^ binds tightest, × binds tighter than +, that ^ is right-associative, and that × and + are left-associative.","","Precedence and associativity can be encoded into a CFG in a mechanical way such that it is unambiguous and only produces syntax trees where the operators behave correctly. An example of this for the grammar above:","",""," E₀ → EA E₁"," EA → E₁ + EA"," EA → ε"," E₁ → EM E₂"," EM → E₂ × EM"," EM → ε"," E₂ → E₃ EP"," EP → ^ E₃ EP"," E₃ → num"," E₃ → (E₀)"," ","","But ambiguous CFGs + precedence / associativity tables are common because they're more readable and because various types of LR parser generator libraries can produce more efficient parsers by eliminating shift/reduce conflicts instead of dealing with an unambiguous, transformed grammar of a larger size.","",""]
In theory, all finite sets of strings are regular languages, and so all legal programs of bounded size are regular. Since regular languages are a subset of context-free languages, all programs of bounded size are context-free. The argument continues,
While it can be argued that it would be an acceptable limitation for a language to allow only programs of less than a million lines, it is not practical to describe a programming language as a regular language: The description would be far too large. — Torben Morgensen's Basics of Compiler Design, ch. 2.10.2
The same goes for CFGs. To address your sub-question a little differently,
Which programming languages are defined by a context-free grammar?
Most real-world programming languages are defined by their implementations, and most parsers for real-world programming languages are either hand-written or uses a parser generator that extends context-free parsing. It is unfortunately not that common to find an exact CFG for your favourite language. When you do, it's usually in Backus-Naur form (BNF), or a parser specification that most likely isn't purely context-free.
Examples of grammar specifications from the wild:
- BNF for Standard ML
- BNF-like for Haskell
- BNF for SQL
- Yacc grammar for PHP
Other Answers
Answered Aug 02, 2011 · 8 votes
Depending on how you understand the question, the answer changes. But IMNSHO, the proper answer is that all modern programming languages are in fact context sensitive. For example there is no context free grammar that accepts only syntactically correct C programs. People who point to yacc/bison context free grammars for C are missing the point.
4/5
Top Answer
Answered Feb 04, 2010 · 52 votes
No contest -- R as the main implementation of S (and one that happens to be proper Open Source and a GNU project as well).
Not only as the S language designed precisely for this purpose (see the books by John Chambers), but the rather rich support of domain-specific packages at CRAN is second to none: over 2000 packages with proper quality control, often authored by experts in the field.
The ACM sees it the same way when it gave the ACM Software Systems Award to John Chambers in 1998 with the following citation
John M. Chambers
For The S system, which has forever altered how people analyze, visualize, and manipulate data.
For reference, other winners of this award were TeX, Smalltalk, Postscript, RPC, 'the web', Mosaic, Tcl/Tk, Java, Make, ... Not a bad company to be in.
Now, if you 'only' want to collect and summarize some data just about any procedural or functional language will do. But if you want something that was designed for programming with data then R as the main S implementation it is.
Other Answers
Answered Dec 18, 2021 · 71 votes
What programming languages are context-free? [...]
My gut tells me that functional languages might be context-free [...]
The short version: There are hardly any real-world programming languages that are context-free in any meaning of the word. Whether a language is context-free or not has nothing to do with it being functional. It is simply a matter of how complex the syntax is.
Here's a CFG for the imperative language Brainfuck:
Program → Instr Program | εInstr → '+' | '-' | '>' | '<' | ',' | '.' | '[' Program ']'
And here's a CFG for the functional SKI combinator calculus:
Program → EE → 'S' E E EE → 'K' E EE → 'I'E → '(' E ')'
These CFGs recognize all valid programs of the two languages because they're so simple.
The longer version: Usually, context-free grammars (CFGs) are only used to roughly specify the syntax of a language. One must distinguish between syntactically correct programs and programs that compile/evaluate correctly. Most commonly, compilers split language analysis into syntax analysis that builds and verifies the general structure of a piece of code, and semantic analysis that verifies the meaning of the program.
If by "context-free language" you mean "... for which all programs compile", then the answer is: hardly any. Languages that fit this bill hardly have any rules or complicated features, like the existence of variables, whitespace-sensitivity, a type system, or any other context: Information defined in one place and relied upon in another.
If, on the other hand, "context-free language" only means "... for which all programs pass syntax analysis", the answer is a matter of how complex the syntax alone is. There are many syntactic features that are hard or impossible to describe with a CFG alone. Some of these are overcome by adding additional state to parsers for keeping track of counters, lookup tables, and so on.
Examples of syntactic features that are not possible to express with a CFG:
typedef int my_int; my_int x;
E → E ^ E E → E × E E → E + E E → (E) E → num
E₀ → EA E₁ EA → E₁ + EA EA → ε E₁ → EM E₂ EM → E₂ × EM EM → ε E₂ → E₃ EP EP → ^ E₃ EP E₃ → num E₃ → (E₀)
- ["Indentation- and whitespace-sensitive languages like Python and Haskell. Keeping track of arbitrarily nested indentation levels is essentially context-sensitive and requires separate counters for the indentation level; both how many spaces that are used for each level and how many levels there are.","","Allowing only a fixed level of indentation using a fixed amount of spaces would work by duplicating the grammar for each level of indentation, but in practice this is inconvenient.","",""]
- ["The C Typedef Parsing Problem says that C programs are ambiguous during lexical analysis because it cannot know from the grammar alone if something is a regular identifier or a typedef alias for an existing type.","","The example is:","","","",""," typedef int my_int;"," my_int x;"," ","","","","","At the semicolon, the type environment needs to be updated with an entry for my_int. But if the lexer has already looked ahead to my_int, it will have lexed it as an identifier rather than a type name.","","","In context-free grammar terms, the X → ... rule that would trigger on my_int is ambiguous: It could be either one that produces an identifier, or one that produces a typedef 'ed type; knowing which one relies on a lookup table (context) beyond the grammar itself.","",""]
- ["Macro- and template-based languages like Lisp, C++, Template Haskell, Nim, and so on. Since the syntax changes as it is being parsed, one solution is to make the parser into a self-modifying program. See also Is C++ context-free or context-sensitive?","",""]
- ["Often, operator precedence and associativity are not expressed directly in CFGs even though it is possible. For example, a CFG for a small expression grammar where ^ binds tighter than ×, and × binds tighter than +, might look like this:","",""," E → E ^ E"," E → E × E"," E → E + E"," E → (E)"," E → num"," ","","This CFG is ambiguous, however, and is often accompanied by a precedence / associativity table saying e.g. that ^ binds tightest, × binds tighter than +, that ^ is right-associative, and that × and + are left-associative.","","Precedence and associativity can be encoded into a CFG in a mechanical way such that it is unambiguous and only produces syntax trees where the operators behave correctly. An example of this for the grammar above:","",""," E₀ → EA E₁"," EA → E₁ + EA"," EA → ε"," E₁ → EM E₂"," EM → E₂ × EM"," EM → ε"," E₂ → E₃ EP"," EP → ^ E₃ EP"," E₃ → num"," E₃ → (E₀)"," ","","But ambiguous CFGs + precedence / associativity tables are common because they're more readable and because various types of LR parser generator libraries can produce more efficient parsers by eliminating shift/reduce conflicts instead of dealing with an unambiguous, transformed grammar of a larger size.","",""]
In theory, all finite sets of strings are regular languages, and so all legal programs of bounded size are regular. Since regular languages are a subset of context-free languages, all programs of bounded size are context-free. The argument continues,
While it can be argued that it would be an acceptable limitation for a language to allow only programs of less than a million lines, it is not practical to describe a programming language as a regular language: The description would be far too large. — Torben Morgensen's Basics of Compiler Design, ch. 2.10.2
The same goes for CFGs. To address your sub-question a little differently,
Which programming languages are defined by a context-free grammar?
Most real-world programming languages are defined by their implementations, and most parsers for real-world programming languages are either hand-written or uses a parser generator that extends context-free parsing. It is unfortunately not that common to find an exact CFG for your favourite language. When you do, it's usually in Backus-Naur form (BNF), or a parser specification that most likely isn't purely context-free.
Examples of grammar specifications from the wild:
- BNF for Standard ML
- BNF-like for Haskell
- BNF for SQL
- Yacc grammar for PHP
Other Answers
Answered Aug 02, 2011 · 8 votes
Depending on how you understand the question, the answer changes. But IMNSHO, the proper answer is that all modern programming languages are in fact context sensitive. For example there is no context free grammar that accepts only syntactically correct C programs. People who point to yacc/bison context free grammars for C are missing the point.
5/5
www.geeksforgeeks.org › what-is-procedural-languageWhat is Procedural Language? - GeeksforGeeks
www.geeksforgeeks.org › what-is-procedural-languageMay 6, 2024 · Procedural Language is also known as 3GL which means third generation language. It is a type of programming language that follows a procedure; set of commands or guidelines that must be followed for smooth execution of the program. It works on step by step basis.
en.wikipedia.org › wiki › Procedural_programmingProcedural programming - Wikipedia
en.wikipedia.org › wiki › Procedural_programmingProcedural programming is a programming paradigm, classified as imperative programming, that involves implementing the behavior of a computer program as procedures (a.k.a. functions, subroutines) that call each other. The resulting program is a series of steps that forms a hierarchy of calls to its constituent procedures.
People also ask
What is procedural language?
- Procedural Language is also known as 3GL which means third generation language. It is a type of programming language that follows a procedure; set of commands or guidelines that must be followed for smooth execution of the program. It works on step by step basis.
What is Procedural Language? - GeeksforGeeks
www.geeksforgeeks.org/what-is-procedural-language/What are some examples of procedural languages?
- Common examples of procedural languages include: C++ is a great programming language to learn if you're also interested in learning more about how computers function. While it may not be as readable as other high-level programming languages like Python, it can still be beginner-friendly.
5 Types of Programming Languages | Coursera
www.coursera.org/articles/types-programming-languageWhat is a program written in procedural language?
- A program written in procedural language contains one or more procedures. Procedural language is one of the most common types of programming languages in use, with notable languages such as C/C++, Java, ColdFusion and PASCAL. Techopedia’s editorial policy is centered on delivering thoroughly researched, accurate, and unbiased content.
What is a Procedural Language? - Definition from Techopedia
www.techopedia.com/definition/8982/procedural-languageWhat are the different types of programming languages?
- Keep in mind that some languages may fall under more than one type: 1. Procedural programming languages A procedural language follows a sequence of statements or commands in order to achieve a desired output. Each series of steps is called a procedure, and a program written in one of these languages will have one or more procedures within it.
5 Types of Programming Languages | Coursera
www.coursera.org/articles/types-programming-languagehackr.io › blog › procedural-programmingWhat is Procedural Programming? [Definition] - Key Features
hackr.io › blog › procedural-programmingDec 13, 2022 · [Definition] Procedural Programming may be the first programming paradigm that a new developer will learn. Fundamentally, the procedural code is the one that directly instructs a device on how to finish a task in logical steps. This paradigm uses a linear top-down approach and treats data and procedures as two different entities.
- Sagar Bhatia
techplces.com › procedural-programmingWhat is Procedural Programming? A Beginner's Guide
techplces.com › procedural-programmingMar 20, 2024 · Procedural programming revolves around giving the computer a sequence of step-by-step instructions, much like following a recipe when cooking. These sequences are called procedures, and they form the backbone of this programming approach.
www.coursera.org › articles › types-programming-language5 Types of Programming Languages | Coursera
www.coursera.org › articles › types-programming-languageMar 29, 2024 · A procedural language follows a sequence of statements or commands in order to achieve a desired output. Each series of steps is called a procedure, and a program written in one of these languages will have one or more procedures within it. Common examples of procedural languages include: C and C++. Java. Pascal. BASIC.
careerkarma.com › blog › procedural-programmingWhat Is Procedural Programming & When to Use It | Career Karma
careerkarma.com › blog › procedural-programmingAug 25, 2020 · Procedural languages view data as separate from procedures, and that impacts how developers utilize it. Examples of procedural programming languages include C, Java, and Pascal. How to Use Procedural Languages to Build Programs. To build tasty apps, you need an equally tasty IDE.
www.techopedia.com › 8982 › procedural-languageWhat is a Procedural Language? - Definition from Techopedia
www.techopedia.com › 8982 › procedural-languageFeb 23, 2017 · A procedural language is a type of computer programming language that specifies a series of well-structured steps and procedures within its programming context to compose a program. It contains a systematic order of statements, functions and commands to complete a computational task or program. Advertisements.
Searches related to what are procedural languages in programming