Turing Machine support - finite-automata

I have a language:
(XF*X|F)*
over the alphabet:
{X,F}
How can I get/design a Turing machine to recognize that language?
Any guidance or advice would be much appreciated

That's trivial:
digraph _ {
_ [ shape=none, label="" ]
1 [ shape=doublecircle ]
2 [ shape=circle ]
_ -> 1
1 -> 1 [ label="F" ]
1 -> 2 [ label="X" ]
2 -> 2 [ label="F" ]
2 -> 1 [ label="X" ]
}

Related

Where does the SELECT clause start/end

Perhaps this is a pedantic distinction, but if we take the SQL grammar, in the following case from BigQuery:
query_statement:
query_expr
query_expr:
[ WITH [ RECURSIVE ] { non_recursive_cte | recursive_cte }[, ...] ]
{ select | ( query_expr ) | set_operation }
[ ORDER BY expression [{ ASC | DESC }] [, ...] ]
[ LIMIT count [ OFFSET skip_rows ] ]
select:
SELECT
[ { ALL | DISTINCT } ]
[ AS { STRUCT | VALUE } ]
select_list
[ FROM from_clause[, ...] ]
[ WHERE bool_expression ]
[ GROUP BY { expression [, ...] | ROLLUP ( expression [, ...] ) } ]
[ HAVING bool_expression ]
[ QUALIFY bool_expression ]
[ WINDOW window_clause ]
It is easy to see, for example, that the WHERE clause would be the section:
[ WHERE bool_expression ]
However, what is considere the "select clause". Is it the wrapper that contains everything? Or is it just the part that goes from SELECT up until the FROM section? Is there a way to distinguish the two?
For a specific example, how would the following be defined:
SELECT 1
FROM x
UNION ALL
SELECT 2
With the three components labeled with:
[ (full)
{ (SELECT until end or set/op)
< (SELECT until FROM):
[
{<SELECT 1> FROM x}
UNION ALL
{<SELECT 2>}
]
The SELECT statement is the whole statement from the word SELECT until the end.
The SELECT clause is from the word SELECT until the word FROM

Customizing the visible vuetify pagination buttons

I'm using the vuetify pagination and the code looks something like this:
<v-pagination
v-model="page"
:length="n"
total-visible="7"
></v-pagination>
Where n is greater than 7, if you're on the first few pages, it'll show the first few pages and the last few pages. I don't want it to show the last few pages.
Also, say you're on page 14 of n, it'll show the first page, pages 13-15, and the nth page. I want it to show +/- some range of pages around page 14 (range of 2 would mean 12-16 are visible). At a min, I'd want to show just the next and previous buttons.
What it does:
< [ 1 ] [ 2 ] [ 3 ] ... [ n -2 ] [ n-1 ] [ n ] >
< [ 1 ] ... [ k-1 ] [ k ] [ k+1 ] ... [ n ] >
What I want:
< [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] ... >
< ... [ k-1 ] [ k ] [ k+1 ] ... >
~OR~
< >
I added the following to the component and it "worked":
<style scoped>
/deep/ .v-pagination__item{
display: none;
}
/deep/ .v-pagination__more{
display: none;
}
</style>
...where "worked" means only the next/previous arrows are visible.

Text and caret in VID or R3-Gui

A simple example:
If I type #"w" in style "area" how do I get an #"z"? (ex. "qwerty ww" -> "qzerty zz")
As you want the conversion on the fly, you can either modify R3-GUI before loading. So load r3-gui.r3 down to your local directory. Then you add the line if key == #"w" [key: #"z"] to the function do-text-key, so it looks like
do-text-key: funct [
"Process text face keyboard events."
face [object!]
event [event! object!]
key
] [
text-key-map/face: face
text-key-map/shift?: find event/flags 'shift
if no-edit: not tag-face? face 'edit [
key: any [select/skip text-key-map/no-edit key 2 key]
]
either char? key [
if key == #"w" [key: #"z"]
text-key-map/key: key
switch/default key bind text-key-map/chars 'event [
unless no-edit [
insert-text-face face key
]
]
] [
if find event/flags 'control [
key: any [select text-key-map/control key key]
]
text-key-map/key: key
switch/default key text-key-map/words [return event]
]
none
]
Probably the official way would be to use on-key wih Rebol3
load-gui
view [
a: area on-key [ ; arg: event
if arg/type = 'key [
if arg/key == #"w" [arg/key: #"z"]
]
do-actor/style face 'on-key arg face/style
]
]
And finally a way to do this with Rebol2 on the fly
key-event: func [face event] [
if event/type = 'key [
if all [event/key = #"w" ] [
append a/text #"z"
focus a
view w
return false
]
]
event
]
insert-event-func :key-event
view w: layout [
a: area
]
After reading some files of r3-gui (text-caret.r3, text-cursor.r3, text-edit.r3, text-keys.r3, text.r3) and the editor, I found a solution that allows me to insert not only a character but also string:
do %r3-gui.r3
insertText-moveCursor-updateFace: func [
face
string
n-move
][
insert-text-face face string
move-cursor face 'left n-move false
update-text-caret face
see-caret face
show-later face
]
i-m-u: :insertText-moveCursor-updateFace
view [
area on-key [
either arg/type = 'key [
switch/default arg/key [
#"w" [i-m-u face/names/text-box "z" 0]
#"[" [i-m-u face/names/text-box "[]" 1]
#"$" [i-m-u face/names/text-box "func [] []" 4]
] [
;switch/default
do-actor/style face 'on-key arg face/style
]
] [
;arg/type != 'key
do-actor/style face 'on-key arg face/style
]
]
]
Area is a compound styles. It is composed of a text-box and a scroller. They are contained in face/names.

How to properly read SQL Server syntax?

In the MSDN Library or the Technet website, Microsoft tend to use a pseudo syntax in explaining how to use T-SQL statements with all available options. Here is a sample taking from the Technet page on UPDATE STATISTICS :
UPDATE STATISTICS table_or_indexed_view_name
[
{
{ index_or_statistics__name }
| ( { index_or_statistics_name } [ ,...n ] )
}
]
[ WITH
[
FULLSCAN
| SAMPLE number { PERCENT | ROWS }
| RESAMPLE
| <update_stats_stream_option> [ ,...n ]
]
[ [ , ] [ ALL | COLUMNS | INDEX ]
[ [ , ] NORECOMPUTE ]
] ;
<update_stats_stream_option> ::=
[ STATS_STREAM = stats_stream ]
[ ROWCOUNT = numeric_constant ]
[ PAGECOUNT = numeric_contant ]
How to properly read such description and quickly figure out what is required and what is optional and a clean way to write your query?
You should refer to this Transact-SQL Syntax Conventions
The first table in that article explains pretty much everything.
In your example we can see the following:
UPDATE STATISTICS table_or_indexed_view_name
UPDATE STATISTICS is the keyword used
table_or_indexed_view_name is the name of the table or the view to update statistics for
[
{
{ index_or_statistics__name }
| ( { index_or_statistics_name } [ ,...n ] )
}
]
This is optional [], but if supplied, you have to put a statistic name {index_or_statistics__name}, or | a list of statistic names separated by commas { index_or_statistics_name } [ ,...n ]
[ WITH
[
FULLSCAN
| SAMPLE number { PERCENT | ROWS }
| RESAMPLE
| <update_stats_stream_option> [ ,...n ]
]
[ [ , ] [ ALL | COLUMNS | INDEX ]
[ [ , ] NORECOMPUTE ]
] ;
This is optional too []. If used then you must begin with a WITH and you have 4 options that you must choose from.
Your options are
FULLSCAN
SAMPLE number { PERCENT | ROWS }, where you have to define the number and you must choose from PERCENT or | ROWS
RESAMPLE
` [ ,...n ]' which is a list separated by commas
Then you have to choose either ALL, COLUMNS or INDEX and preside that with a comma if you have used the WITH.
Lastly you have another option to use the NORECOMPUTE and put a comma before it if you have used any other option before it.
<update_stats_stream_option> ::=
[ STATS_STREAM = stats_stream ]
[ ROWCOUNT = numeric_constant ]
[ PAGECOUNT = numeric_contant ]
These are the list of predefined options you may use where <update_stats_stream_option> is used before (in 4).
Any thing between Square Brackets [...] are Optional
Any thing seperated by the pipe | symbol is a one or the other option.
In your above example, you could read it as
UPDATE STATISTICS table_or_indexed_view_name
[ optionally specify an index as well]
[ optionally specify options using **WITH**
If you use WITH then you can follow it with one of the following keywords
FULLSCAN
OR SAMPLE number { PERCENT | ROWS }
OR RESAMPLE
].. and so on

How to dynamically use compose/only?

I tried to generate the actions block dynamically in the code below (from static version here Extending Build-markup with repeat refinement) but It doesn't work why ?
build-markup: func [
{Return markup text replacing <%tags%> with their evaluated results.}
content [string! file! url!]
/repeat block-fields block-values
/quiet "Do not show errors in the output."
/local out eval value
][
out: make string! 126
either not repeat [
content: either string? content [copy content] [read content]
eval: func [val /local tmp] [
either error? set/any 'tmp try [do val] [
if not quiet [
tmp: disarm :tmp
append out reform ["***ERROR" tmp/id "in:" val]
]
] [
if not unset? get/any 'tmp [append out :tmp]
]
]
parse/all content [
any [
end break
| "<%" [copy value to "%>" 2 skip | copy value to end] (eval value)
| copy value [to "<%" | to end] (append out value)
]
]
][
actions: copy []
n: length? block-fields
repeat i n [
append actions compose/only [
set in system/words (to-lit-word pick (block-fields) (i)) get pick (block-fields) (i)
]
]
append actions compose/only [
append out build-markup content
]
foreach :block-fields block-values actions
]
out
]
template1: { <td><%a%></td><td><%b%></td>
}
template2: { <tr>
<%build-markup/repeat template1 [a b] [1 2 3 4]%>
</tr>
}
template3: {<table>
<%build-markup/repeat template2 [a b] [1 2 3 4 5 6]%>
</table>}
build-markup template3
Output error:
>> build-markup template3
== {<table>
***ERROR no-value in: build-markup/repeat template2 [a b] [1 2 3 4 5 6]
</table>}
>>
It looks like a binding problem.
I changed this line:
either error? set/any 'tmp try [do val] [
to
either error? set/any 'tmp e: try [do val] [
e holds the error,
>> e
** Script Error: i has no value
** Where: build-markup
** Near: i n [