Execution

Graphal GUI

GUI application doesn't parse any parameters, it shows the main application window with integrated development environment.

[woq@evm graphal]$ make RPATH_ORIGIN=yes dist
...
[woq@evm graphal]$ cd build/dist/
[woq@evm dist]$ ./graphal_gui

Graphal GUI

Graphal CLI

Usage

Application that is executed without parameters shows usage and exits.

[woq@evm graphal]$ make RPATH_ORIGIN=yes dist
...
[woq@evm graphal]$ cd build/dist/
[woq@evm dist]$ ./graphal_cli
Graph Algorithms Interpreter - Graphal

About:
	Version:     1.0.0
	Author:      Michal Turek
	Website:     http://graphal.sourceforge.net/

License:
	libGraphal:  GNU LGPL v3
	Graphal CLI: GNU  GPL v3
	Graphal GUI: GNU  GPL v3

Usage:
	./graphal_cli [-h | --help] [-I<directory>] [-u | --unit-tests] [-a | --ast-dump] [-b | --enable-breakpoints] <filename> [parameters]

	-h | --help
		Show this help and exit.

	-v | --version
		Show version and exit.

	-I<directory>
		Specify include directories (relative to the current working directory).
		-I<directory_1> -I<directory_2> ... -I<directory_N>

	-u | --unit-tests
		Run unit tests.

	-a | --ast-dump
		Dump abstract syntax tree of the script.

	-b | --breakpoints
		Enable breakpoints.

	filename
		File to be executed.

	parameters
		Script parameters.

[woq@evm dist]$

Script Execution

Pass a path as the last parameter to execute the script.

[woq@evm graphal]$ make RPATH_ORIGIN=yes dist
...
[woq@evm graphal]$ cd build/dist/
[woq@evm dist]$ ./graphal_cli ../samples/01_factorial.txt
[i] *** ENTERING SCRIPT MAIN ***
Factorial of 0 is 1
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 6
Factorial of 4 is 24
Factorial of 5 is 120
Factorial of 6 is 720
Factorial of 7 is 5040
Factorial of 8 is 40320
Factorial of 9 is 362880
[i] *** EXITING SCRIPT MAIN, OK ***
[i] Return value: 0
[i] *** EXITING MAIN, OK ***
[woq@evm dist]$

Unit Tests

Unit test mode is suitable to check that the application was compiled and works correctly.

[woq@evm graphal]$ make RPATH_ORIGIN=yes dist
...
[woq@evm graphal]$ cd build/dist/
[woq@evm dist]$ valgrind ./graphal_cli --unit-tests ../samples/tests.txt
==13023== Memcheck, a memory error detector
==13023== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==13023== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==13023== Command: ./graphal_cli --unit-tests ../samples/tests.txt
==13023==
[i] [ OK ]     testDoubleDispatching
[i] [ OK ]     testValueStruct
[i] [ OK ]     testValueString
[i] [ OK ]     testValueReference
[i] [ OK ]     testValueIdentifier
[i] [ OK ]     testValueArray
[i] [ OK ]     testGraph
[i] [ OK ]     testGraphSet
[i] [ OK ]     testGraphInvertEdgesOrientation
[i] [ OK ]     testLexanTerminalSymbols
[i] [ OK ]     testLexanInt
[i] [ OK ]     testLexanFloat
[i] [ OK ]     testLexanString
[i] [ OK ]     testLexanComments
[i] [ OK ]     testLexanSourceCode
[i] [ OK ]     testNodeUnary
[i] [ OK ]     testNodeBinary
[i] [ OK ]     testNodeBlock
[i] [ OK ]     testNodeVariable
[i] [ OK ]     testStringTable
[i] [ OK ]     testCountPtr
[i] [ OK ]     testNodeFunction
[i] [ OK ]     testValueArrayIterator
[i] [ OK ]     testValueSet
[i] [ OK ]     testValueSetOperations
[i] [ OK ]     testValueSetRemove
[i] Number of failed tests: 0
[i] *** ENTERING SCRIPT MAIN ***
Executing unit tests...
[ OK ]     testFactorial
[ OK ]     testArray
[ OK ]     testStruct
[ OK ]     testGraph
[ OK ]     testMemberAccess
[ OK ]     testForeach
[ OK ]     testGlobal
[ OK ]     testUnionIntersectionDifference
[ OK ]     testTypeChecks
[ OK ]     testStackQueue
[ OK ]     testNotReferences
[ OK ]     testReferences
[ OK ]     testAdjacencyMatrix
[ OK ]     testSetPropertyToAll
Number of failed tests: 0
[i] *** EXITING SCRIPT MAIN, OK ***
[i] Return value: NULL
[i] *** EXITING MAIN, OK ***
==13023==
==13023== HEAP SUMMARY:
==13023==     in use at exit: 0 bytes in 0 blocks
==13023==   total heap usage: 20,768 allocs, 20,768 frees, 393,222 bytes allocated
==13023==
==13023== All heap blocks were freed -- no leaks are possible
==13023==
==13023== For counts of detected and suppressed errors, rerun with: -v
==13023== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 20 from 7)
[woq@evm dist]$

Dump of AST

Dump of Abstract Syntax Tree is mainly for debugging purposes to check that the script's source code was parsed and stored to the internal form correctly.

/*
 * Copyright 2008 Michal Turek
 *
 * This file is part of Graphal.
 * http://graphal.sourceforge.net/
 *
 * Graphal is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * Graphal is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Graphal.  If not, see <http://www.gnu.org/licenses/>.
 */


function factorial(number)
{
	if(number < 2)
		return 1;
	else
		return number * factorial(number - 1);
}

// Enter to program
function main(argv)
{
	for(i = 0; i < 10; i++)
		println("Factorial of " + i + " is " + factorial(i));

	return 0;
}
[woq@evm graphal]$ make RPATH_ORIGIN=yes dist
...
[woq@evm graphal]$ cd build/dist/
[woq@evm dist]$ ./graphal_cli --ast-dump ../samples/01_factorial.txt
<Context>
    <BuiltinFunction name="echo" id="7" />
    <BuiltinFunction name="print" id="8" />
    ...
    <BuiltinFunction name="visGetGraph" id="74" />
    <Function name="factorial" id="77">
	<Parameter name="number" id="78" />
	<If>
	    <Condition>
		<NodeBinaryLt>
		    <ValueIdentifier name="number" id="78">
			<NoValue />
		    </ValueIdentifier>
		    <ValueInt value="2" />
		</NodeBinaryLt>
	    </Condition>
	    <IfSection>
		<NodeUnaryReturn>
		    <ValueInt value="1" />
		</NodeUnaryReturn>
	    </IfSection>
	    <ElseSection>
		<NodeUnaryReturn>
		    <NodeBinaryMult>
			<ValueIdentifier name="number" id="78">
			    <NoValue />
			</ValueIdentifier>
			<FunctionCall name="factorial" id="77">
			    <NodeBinarySub>
				<ValueIdentifier name="number" id="78">
				    <NoValue />
				</ValueIdentifier>
				<ValueInt value="1" />
			    </NodeBinarySub>
			</FunctionCall>
		    </NodeBinaryMult>
		</NodeUnaryReturn>
	    </ElseSection>
	</If>
    </Function>
    <Function name="main" id="79">
	<Parameter name="argv" id="80" />
	<Loop>
	    <Init>
		<NodeBinaryAss>
		    <ValueIdentifier name="i" id="81">
			<NoValue />
		    </ValueIdentifier>
		    <ValueInt value="0" />
		</NodeBinaryAss>
	    </Init>
	    <Condition>
		<NodeBinaryLt>
		    <ValueIdentifier name="i" id="81">
			<NoValue />
		    </ValueIdentifier>
		    <ValueInt value="10" />
		</NodeBinaryLt>
	    </Condition>
	    <Inc>
		<NodeUnaryIncPost>
		    <ValueIdentifier name="i" id="81">
			<NoValue />
		    </ValueIdentifier>
		</NodeUnaryIncPost>
	    </Inc>
	    <Body>
		<FunctionCall name="println" id="9">
		    <NodeBinaryAdd>
			<NodeBinaryAdd>
			    <NodeBinaryAdd>
				<ValueString value="Factorial of " />
				<ValueIdentifier name="i" id="81">
				    <NoValue />
				</ValueIdentifier>
			    </NodeBinaryAdd>
			    <ValueString value=" is " />
			</NodeBinaryAdd>
			<FunctionCall name="factorial" id="77">
			    <ValueIdentifier name="i" id="81">
				<NoValue />
			    </ValueIdentifier>
			</FunctionCall>
		    </NodeBinaryAdd>
		</FunctionCall>
	    </Body>
	</Loop>
	<NodeUnaryReturn>
	    <ValueInt value="0" />
	</NodeUnaryReturn>
    </Function>
    <StringTable>
	<string id="0">built-in function</string>
	<string id="1">a</string>
	<string id="2">b</string>
	<string id="3">c</string>
	<string id="4">d</string>
	<string id="5">e</string>
	<string id="6">f</string>
	<string id="7">echo</string>
	<string id="8">print</string>
	...
	<string id="79">main</string>
	<string id="80">argv</string>
	<string id="81">i</string>
    </StringTable>
</Context>
[i] *** ENTERING SCRIPT MAIN ***
Factorial of 0 is 1
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 6
Factorial of 4 is 24
Factorial of 5 is 120
Factorial of 6 is 720
Factorial of 7 is 5040
Factorial of 8 is 40320
Factorial of 9 is 362880
[i] *** EXITING SCRIPT MAIN, OK ***
[i] Return value: 0
[i] *** EXITING MAIN, OK ***
[woq@evm dist]$