What is the term for an error where a space is missing? - language-agnostic

What is the name of/term for a coding error where you forgot a space?
Example
SELECT *
FROM public.employees
INNERJOIN public.departments ON employees.dept_id = departments.id
Notice the INNERJOIN should be INNER JOIN.

Syntax error.
Most programming languages or formal grammars have a very specific and deterministic syntax that must be meet before other phases of checking occur such as semantics and type checking.
While a syntax error can be thought of as a class of error and you are seeking something more specific, in my 30 years of coding and writing parsers and such the only way to make this more specific is to give the line number and column position of where the space was expected and the production rule(s) being evaluated at the time can help identify what was expected.

Related

How to identify "throw exceptions" in a Java program regarding Integer.parseInt method

I am new to Java and I am having trouble understanding a question. I am asked to select which of the following choices throws an exception. The options are:
1.) Integer.parseInt(" ")
2.) Integer.parseInt("54 ")
3.) Integer.parseInt("")
4.) Integer.parseInt("-54")
5.) Integer.parseInt("54n")
To answer this question, I need some explanations. What does the Integer.parseInt method do? Doesn't it turn an integer into a String? What sort of arguments are illegal to put inside this method. For example, are you allowed to include negative numbers? Strings? Or does it only accept integers?
I was also wondering if you could clarify what "throws an exception" means. I have a rough idea, I think it just means that if there is an error in your program, it gets terminated. Howevere, you can use the "try-catch-finally" method to try and predicate any errors your program would have and write a possible code to fix it?
Sorry for all the questions, I just want to understand this completely.

Ensuring that a predicate succeeds deterministically

This other question asks almost the same, but not quite. Rather, how do I demand that a goal succeeds deterministically (exactly once) and does not leave behind any choice points?
This is especially useful in the context of Prolog programs that are used as command-line tools: possibly read from standard input, take arguments, and write to standard output. In such a program, leaving a choice point after doing the work is invariably an error of the programmer.
SWI-Prolog offers deterministic/1, so one could write:
( deterministic(true)
-> true
; fail
)
Another, more portable way to achieve the same was suggested:
is_det(Goal, IsDet) :-
setup_call_cleanup(true, Goal, Det=true),
( Det == true
-> IsDet = true
; !,
IsDet = false
).
However, it seems useful to throw an error when this happens, but I don't know what this error would be. I looked quite carefully through the ISO error terms and I could not find an error that would obviously describe this situation.
Is it indeed better to throw an error, or should I just fail? If throwing an error is to be preferred, what would that error be?
EDIT: I am not sure what to because especially when side effects are involved, like writing something to standard output, it feels very wrong to have the side effect happen and then fail. It is almost necessary to rather throw an exception. This makes it also possible to decide that the remaining choice point is harmless (if not desirable) and just catch the exception, then write to standard error or return a different exit code.
But I really have no idea what describes the exception properly, so I don't know what term to throw.
Check out call_semidet/1 as proposed by Ulrich Neumerkel on the SWI-Prolog mailing list:
call_semidet/1 - clean removal of choice-points
In it, he proposes:
call_semidet(Goal) :-
( call_nth(Goal, 2)
-> throw(error(mode_error(semidet,Goal),_))
; once(Goal)
).
This proposed mode_error is a very good start.
In spirit, it follows the other errors: In this case, mode semidet is expected, and this is reflected in the thrown error term.

Regex conversion from Java to mysql for '?:'

I have this Expression
(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
that is working fine in java but when i am trying to use the same in mySql it is giving me
Error Code: 1139
Got error 'repetition-operator operand invalid' from regexp
So when i replace above Expression with this
(((^25[0-5])|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}((^25[0-5])|2[0-4][0-9]|[01]?[0-9][0-9]?)
This is giving me some additional Results?
Plz let me know what i am Doing Wrong , Thanks For your time
The construct ?: is a non-capturing group.
When refering to the current documentation of MySQL one can see that it
is aimed at conformance with POSIX 1003.2
and that
MySQL uses the extended version
In other words, it uses POSIX ERE and this flavor simply doesn't support non-capturing groups.
For a detailed listing on what constructs are available in Java and in POSIX ERE you can use regular-expressions.info as a reference, specifically this site for capturing groups (just be sure to choose Java and POSIX ERE in the two dropdowns).
As to why you get additional results:
Did you notice that your regexes aren't equal?
In the first and second half of your first regex you write (?:25[0-5]|, while in the second regex this becomes ((^25[0-5])|.
A ^ matches the beginning of a string (here's the documentation again), so at least the second occurence can never match if anything was matched before.
Perhaps you want to use this regex in MySQL, but i can only take a guess here as i don't know your data and what exactly you want to match.
((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
I just took your first regex and removed all ?:.

How do I know which is a function and which is an operator? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
MySQL have both functions and operators. However, it is not that clear for an arbitrary keyword whether it is a function or an operator.
For example, I believe ASCII() is a function (it appears in the string functions section of the manual). However, LIKE appears there as well, and it does not appear to be a function; for example, since the syntax does not force (...) after the LIKE keyword, and the docs mention that
By default, there must be no whitespace between a function name and the parenthesis following it.
In some cases it is that clear. For example, the IN keyword appears in the Comparison Functions and Operators section of the manual (a non-disclosing section name), and it appears there with the name IN() (as if it was a function), but the examples show SELECT 2 IN (0,3,5,7);, which hints that this is an operator (watch the space after the keyword).
In the same section there is INTERVAL(). Reading carefully shows the following line in the description of this keyword:
It is required that N1 < N2 < N3 < ... < Nn for this function to work correctly.
which hints that this is indeed a function, and not an operator. LEAST(), which also appears there, does not mention whether it is a function or an operator.
My questions are as follows:
Are there any internal differences between the concepts of function and of operator in MySQL?
Is there a way to figure out, given a keyword, whether it is a function of an operator?
Can a keyword be both, depending on context? I know that some keywords can both a function and a type, for example.
I wish to know that both in order to understand the abstract structure of MySQL, and in order to use it for syntax highlighting.
MySQL provides a list of "non-typed" operators here.
Basically, a function is followed by a list of arguments enclosed in parentheses. Even functions that don't take arguments, such as now() require the parentheses.
An operator, on the other hand, is part of the syntax of the MySQL query language. These are known to the parser, which recognizes them. Operators often use "infix" notation, where the operator appears between the arguments. However, this is not required (just consider the unary minus operator).
A cursory look at the list of operators shows that something can be both an operator and a function. An example is mod().
The most important difference to me is that users can define functions. But users cannot (yet) define operators. Unlike object oriented languages, SQL does not offer a way to provide additional definitions for operators.
And, for your purpose, you should peruse the manual pages to get the lists of things that you care about.

Types of Errors during Compilation and at Runtime

I have this question in a homework assignment for my Computer Languages class. I'm trying to figure out what each one means, but I'm getting stuck.
Errors in a computer program can be
classified according to when they are
detected and, if they are detected at
compile time, what part of the
compiler detects them. Using your
favorite programming language, give an
example of:
(a) A lexical error, detected by the
scanner.
(b) A syntax error, detected by the
parser.
(c) A static semantic error, detected
(at compile-time) by semantic
analysis.
(d) A dynamic semantic error, detected
(at run-time) by code generated by the
compiler.
For (a), I think this is would be correct: int char foo;
For (b), int foo (no semicolon)
For (c) and (d), I'm not sure what is being asked.
Thanks for the help.
I think it's important to understand what a scanner is, what a parser is and how they are involved in the compilation process.
(I'll try my best at a high-level explanation)
The scanner takes a sequence of characters (a source file) and converts it to a sequence of tokens. e.g., sees the text if 234 ) and converts to the tokens, IF INTEGER RPAREN (there's more to it but should be enough for the example).
Another way you can think of how the scanner works is that it takes the text and makes sure you use the correct keywords and not makes them up. It has to be able to convert the entire source file to the associated language's recognized tokens and this varies from language to language. In other words, "Does every piece of text correspond to a construct a language understands". Or better put with an example, "Do all these words found in a book, belong to the English language?"
The parser takes a sequence of tokens (usually from the scanner) and (among other things) sees if it is well formed. e.g., a C variable declaration is in the form Type Identifier SEMICOLON.
The parser checks "Does this sequence of tokens in this order make sense to me?" And similarly the analogy, "Does this sequence of English words (with punctuation) form complete sentences?"
C asks for errors that can be found when compiling the program. D asks for errors that you see when running the program after it compiled successfully. You should be able to distinguish these two by now hopefully.
I hope this helps you get a better understanding and make answering these easier.
I'll give it a shot. Here's what I think:
a. int foo+; (foo+ is an invalid identifier because + is not a valid char in identifiers)
b. foo int; (Syntax error is any error where the syntax is invalid - either due to misplacement of words, bad spelling, missing semicolons etc.)
c. Static semantic error are logical errors. for e.g passing float as index of an array - arr[1.5] should be a SSE.
d. I think exceptions like NullReferenceException might be an example of DME. Not completely sure but in covariant returns that raise an exception at compile time (in some languages) might also come in this category. Also, passing the wrong type of object in another object (like passing a Cat in a Person object at runtime might qualify for DME.) Simplest example would be trying to access an index that is out of bounds of the array.
Hope this helps.