[Tex/LaTex] Parsing and programming in TikZ

parsingpgfkeysprogrammingtikz-pgf

Background: I'be been reading the PGF manual (keys section) and today the TeX Book just arrived in the mail and just started reading chapter 7 (How TeX reads what you type) — feeling like Mickey Mouse in "The Sorcerers Apprentice".

I want (but this is not the question) to do a routine that does something like that:

   input:   a,b ; c,d ; e,f.
   output:  a\nodepart{b} && c\nodepart{d} && e\nodepart{f}\\

My idea was to use the PGF parser to read the input. If I were using the languages I know (old Basic, Python, Maple script) I would save intermediary results in a variable but for what I understood so far LaTeX/TeX/ and TikZ/PGF do not work in this way. There is no string manipulation routines. I know we can store stuff into pgf keys. Before you stop reading I better ask my questions:

  1. Are there any examples of (LaTeX/TeX/ and TikZ/PGF) code that reads some input of variable lenght possibly more than ten and spits some other code?
  2. With the example above in mind, which references should I read to be able to implement the routine in an efficient way?

Post-script:

  1. Reading the suggested tags, I just learn about the LaTeX parse package, will check it also.
  2. @egreg: The ultimate goal will be to define a bimatrix environment in TikZ to display two-player games in normal form. The idea is to create outputs similar to this http://www.maths.lse.ac.uk/Personal/stengel/bimatrixgame/example.pdf but with the intuitive and human-like language we see in TikZ constructs.

Best Answer

This is an adaptation of the second answer of the question How do I split a string? to your problem. It is not exactly what you want, but it can help to get you on the way.

\documentclass[a4paper]{article}
\makeatletter
\def\processArg#1,#2{%
  #1 nodepart #2
}
\def\myutil@empty{}
\def\severalparts#1;#2\@nil{%
 \def\NextArg{#2}%
 \processArg#1%
 \ifx\myutil@empty\NextArg
     \let\next\@gobble
 \else XX
 \fi
 \next#2\@nil
}%
\def\ProcessString#1{%
   \let\next\severalparts
   \next#1;\@nil %
}%
\makeatother

\begin{document}
\ProcessString{a,b;c,d;e,f}
\end{document}

This the pdf output:

Result