Category Archives: programming

!!AB : Creating Compile Language : Part 1

!!AB

Per the original spec for my Nonalphabetic Programming Language –dubbedd !!AB or NOTAB– I have finally gotten around to trying to turn it into an actual usable product. First time around, I haven’t gotten used to Flex/Bison yet, so I didn’t get anywhere. But this time, I think I have a slightly better grasp, and have something that seems to work. I’ve read some tutorials, but still have a long way to fully understand the syntax and logical procedure and grand vision for Flex/Bison.

It’s still at a very early stage. The source code can be found at this git repository for NOTAB.

Strings

First area I started with is text output, so that I can see the results of the sample source code written in !!AB language. It will only accept double-quotes and not single-quotes/apostrophe to enclose strings–in order to not use up the limited number of nonalphanumeric characters, nor to use symbols in combinations that are not intuitive. (Like why do languages have comments and comment blocks delimited by // and /*? This makes no sense.) Per the specs of this new language, the early draft of my Flex code went something like this:

%%
%x MODE_STRING
%%
\"                { BEGIN(MODE_STRING); }
<MODE_STRING>\"   { BEGIN(INITIAL); }
<MODE_STRING>[^\"]*  { yylval.sval = strdup(yytext); return STRING; }

The program always begins in the INITIAL mode.
%x MODE_STRING
tells Flex this is a mode that the program will enter and leave when it encounters specific text in the source. In this case, this mode will try to capture a string of text between two double-quotes “”. This is an exclusive mode –signified by %x– which means only rules beginning with this code —
<MODE_STRING>
— will be processed while the lexer is under this mode. (The other type is inclusive mode, signified by %s.)

When it sees a double-quote while not in MODE_STRING mode, it will turn on this mode. While in this mode, any character besides the double-quote is considered part of the string, including newlines. That means a string can span multiple lines.

This mode will end when it meets the next double-quote. Caveat is that the !!AB spec desires that double-quotes within strings be escaped as \”. However, this is not possible yet, since my skill with Flex/Bison is still very lacking. Although one idea is to create a temporary string variable when it first enters this mode. Then create a new rule to additionally capture \”. Finally when it leaves this mode (but not before), the entire string will be returned.


Commentation

Also completed the comment system. Much simpler than strings concept. Allows both single- and multi-line comments. Single line comment begins with single-quote ‘, and will ignore the rest of the line. Multi-line comment blocks are enclosed within ‘[ and ‘].

Flex goes like this:

%%
%x MODE_COMMENT
%%
"'["		       { BEGIN(MODE_COMMENT); }
<MODE_COMMENT>{
	[^'\n]*      // ignore anything that's not a '
	'+[^'\]\n]*  // ignore ' not followed by ]
	\n           { ++line_num; }
	'+"]"        { BEGIN(INITIAL); }
}

'[^\[][^\n]*		; // comment, ignore rest of line

I designate a second mode for block comments. It initiates when it detects ‘[. It ignores pretty much every character while in this mode. The new line is to keep the line number for debugging, so you know the line number of the input source when you get an error.

There are two different checks during this mode. The comment mode exits when it meets ‘]. So you can have series of ‘ with or without a trailing ]. Therefore check both conditions to get the desired behaviour.

Also to ensure single line comments don’t interfere with multi-line, it must check against the opening bracket [ that starts multi-line mode.


Test Source

Here is the test source file written to the specs of the new language. It seems to work as expected.

$< "Hello Master " + "Xayvir."

$<
$< "What about
newlines?"
$<
$< "Or \n escaped newlines?"

$<
$< "!!AB is such a \"great\" programming language" ' aka NOTAB

$<
$< 890 + \
" beers on the wall."

$<
$< "I have " + 11.01 + " dollars." 'US dollars

'[
comment block
']

$<
$< "Flavor text with" + '[ this should not appear '] " inside comment block"

$<
$< "What about unclosed string?"

While writing this post but before completing, I went ahead and read more materials on getting Flex to do more complicated strings and comments. https://www.cs.virginia.edu/~cr4bd/flex-manual/Start-Conditions.html. So the strings section in final program is actually more advanced than what is posted in this post. (You can read that site rather than me repeat them here.)

TablesPlus plugin

TablesPlus plugin for WordPress

Alternative ways to create tables.
See Lightweight Markup for how to format tables.
For VSV format, read Versatile Separated Values

Examples:


CSV

Name Score 1 Score 2
BEAKL 8 104 132
BEAKL 9 120 144
BEAKL 10 44 99

VSV

Name Score 1 Score 2
BEAKL 8 104 132
BEAKL 9 120 144
BEAKL 10 44 99

Name Age Gender
Hammie 20.5 F
Chow, Vivian 40 F
Amuseum 25 M
Shena’Fu 18+5/12 F
Grndr-1245 21 months
Fairy Nuff 14 K N/A

Continue reading TablesPlus plugin

Layers of Computing

A theory that crossed my mind when pondering the relationship between functions and threads.

Layers of Computing
1: memory, storage
2: address
3: data, pointer, array, class (Turing)
4: instruction, operation, expression(2GL)
5: function, loop, routine (3GL)
6: thread, process (4GL)
7: algorithm, solution, library(5GL)
8: application, product
9: operating system, language, I/O
10: computer, brain
11: intelligence
12: universe

Nonalphabetic Programming Language

Nonalphabetic programming language
called !!AB

Programming language where common and simple operations and expressions (excluding variables) are typed with non-alphabetic symbols. Allows various programming paradigms, including procedural, object oriented, and functional.  Balanced ternary is the base for logic and digit operations. Decimal numbers are preferred for human readability. Array index starts at 1.

 Continue reading Nonalphabetic Programming Language 

PLURPS: Programming Language Using Role-Playing Syntax

PLURPS Programming Language Using Role-Playing Syntax

Just an idea to write code as if we are playing a RPG. Very initial brainstorm.

Terms:
Class – class
New instance – create
Delete instance – kill
If – attack
Then – hit
Else – miss
Function – skill
Parameters – targets
Return – result
Switch – menu
Case – option
Array – group
Add to array – join
Delete from array – leave
For – fight <stat> <value |number>
Next in loop – grind
Increment – up (<stat> up <optional number|default 1>)
Decrement – down (<stat> down <optional number|default 1>)
Break – flee
Continue – skip
Variable – stat
Integer – number
String – quote
Local – melee
Global – ranged
End block – done
True – yes
False – no
Output – say

The following examples may or may not be valid. Only to show what it could or should look like.

Example 1:
say "Hello World"

Example 2:

fight level 0
grind level < enemies.size
   attack goblin > 25
      hit
         enemies[level]
      miss
   done
   attack player.hp <= 0
      hit
        flee
   done
   level up
done

MTG Utilities: Mana

The code for inserting mana symbols is [ mana]cost[/mana]. Put the entire cost inside. Hybrid halves and Phyrexian mana should be separated by a slash ‘/’, in any order. Use 2 for monocolor hybrid and P for Phyrexian. Put a semicolon between the numbers if there are two consecutively, but want them to show up separately.

These are the valid letters, numbers, and hybrids that can be used within the mana tags:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
b c e g h i p q r s t u w x y z
w/u u/w u/b b/u b/r r/b r/g g/r w/b b/w u/r r/u b/g g/b r/w w/r g/u u/g
2/w w/2 2/u u/2 2/b b/2 2/r r/2 2/g g/2
p/w w/p p/u u/p p/b b/p p/r r/p p/g g/p

and their corresponding symbols:




Continue reading MTG Utilities: Mana

MTG Utilities: Overview

MTG Utilities is a plugin for WordPress that consists of three major functions to assist and enhance your blog:

  • Card links and images, using [ card ] [ /card ]
  • Deck lists, using [ deck ] [ /deck ]
  • Mana symbols, using [ mana ] [ /mana ]

Last updated 11-04-16 v2.0
DOWNLOAD Plugin from WordPress.org

Default URL to card database query:
http://magiccards.info/query?q=!
Default URL to card image query:
http://gatherer.wizards.com/Handlers/Image.ashx?type=card&name=

For more information, instructions, and examples about the MTG Utilities plugin for WordPress, please read the following posts:

MTG Utilities: Making of a WordPress Plugin

Since this is a blog, I shall blog about the process of the creation of a WordPress plugin that provides basic utilities for Magic: the Gathering blogs (such as the one you’re reading now). This plugin I shall dub “MTG Utilities”. There are a few MTG plugins out there and together they seem to work fine. But I want a single plugin that provides what I need and it should be somewhat customizable and flexible. The main code will be ported from my mod I made for Simple Machines forums.

Continue reading MTG Utilities: Making of a WordPress Plugin