File RunningXcom.html    Author McKeeman    Copyright © 2007    index

Running Xcom

The MATLAB Command Line

The MATLAB command line serves both as a command interpreter (like a shell) and a place to write programs (complex syntax). The command line interpreter figures out what you are doing each time it looks at its line of input. If the MATLAB command line interpreter decides you are using it like a shell, it will interpret the characters as blank-separated strings; if it decides otherwise, it will interpret the characters according to the MATLAB language syntax. These two modes are called command syntax and function syntax, respectively (Actually, command line interpretation is a bit more complicated than that, but the fine details are not important for this presentation.)

Running xcom

The normal way to run xcom is using the command syntax.

>> xcom x:=y+1

The above command syntax calls the function xcom.m and gives it a single argument, the string 'x:=y+1'. This usage is exactly the same as function syntax

>> xcom('x:=y+1')

The command syntax is convenient but has some hidden features that can lead to confusing results. The xcom call is so simple that you will rarely get into trouble using command syntax. Of course, you cannot put white space in the program text above.

>> xcom x := y+1

will start to work on 'x' as a whole program, and immediately discover that there is no := (which is syntactically required). You get a parse error. It is OK, however, to write

>> xcom 'x := y+1'

since one of the MATLAB command line features is to obey quotation marks.

xcom also has two ways to interpret its input strings. The examples above were all interpreted as X language. The effect is to compile&go. If the input argument had happened to end exactly in the characters '.x', the whole argument would be taken as a file name. Thus

>> xcom x/pi.x

runs the file pi.x in the x directory.

xcom has no memory. Each run starts from a clean slate. There is no global frame or any other holdover from run to run.

Multiple X Programs in One Run

Since X programs can call each other, they need a way to find each other. In fact, all of them have to be listed on the command line.

>> xcom x/pi.x x/callpi.x

compiles two programs, and calls the last one on the list. Every other program on the command line is available to the main program and each other.

xcom Flags

xcom has a lot of flags controlling its behavior. Most of them trigger off informative diagnostics designed to ease the task of learning how to change the compiler. All of the flags start with '-', which can never start a valid X program. The whole list of flags can be displayed by running

>> help xcom

which uses the standard MATLAB help facility to display the first comment in the file xcom.m.

Some of the flags are specific to the following command line argument; some are global to the whole compile. For example, using a global flag,

>> xcom -noExecute x:=y+1

compiles the program but does not execute it. Try adding a local flag

>> xcom -noExecute -asmDump x:=y+1

to see the dump final compiled form of 'x:=y+1' without the user having to respond to the interactive input and output.