---------------------------------------------------------------- jflex.error ---------------------------------------------------------------- Reading "Source/grammar/Yylex.jflex" Constructing NFA : 339 states in NFA Converting NFA to DFA : ......................................................................................................................................... 147 states before minimization, 128 states in minimized DFA Writing code to "Source/grammar/Yylex.java" ---------------------------------------------------------------- parser.cup.error ---------------------------------------------------------------- Opening files... Parsing specification from standard input... Checking specification... Building parse tables... Computing non-terminal nullability... Computing first sets... Building state machine... Filling in tables... Checking for non-reduced productions... Writing parser... Closing files... ------- CUP v0.10k Parser Generation Summary ------- 0 errors and 0 warnings 55 terminals, 44 non-terminals, and 99 productions declared, producing 180 unique parse states. 0 terminals declared but not used. 0 non-terminals declared but not used. 0 productions never reduced. 0 conflicts detected (0 expected). Code written to "parser.java", and "sym.java". ---------------------------------------------------- (v0.10k) ---------------------------------------------------------------- javac.error ---------------------------------------------------------------- ---------------------------------------------------------------- Source/grammar/Yylex.jflex ---------------------------------------------------------------- package grammar; import text.*; import java_cup.runtime.*; import java.io.*; import java.util.*; %% %public %type Symbol %char %{ private int lineNumber = 1; public int lineNumber() { return lineNumber; } public Symbol token( int tokenType, String text ) { Print.error().debugln( "Obtain token " + sym.terminal_name( tokenType ) + " \"" + text + "\"" ); return new Symbol( tokenType, yychar, yychar + yytext().length(), text ); } public Symbol token( int tokenType ) { return token( tokenType, yytext() ); } %} %init{ yybegin( NORMALSTATE ); %init} binConst = 0[bB][01]+ decConst = [0-9]+ hexConst = 0[xX][0-9a-fA-F]+ ident = [A-Za-z][A-Za-z0-9]* space = [\ \t] newline = \r|\n|\r\n octEsc = \\[0-3][0-7][0-7] hexEsc = \\[xX][0-9a-fA-F][0-9a-fA-F] charEsc = \\[ntbrfva\\\'\"] schar = [^\'\"\\\r\n]|{octEsc}|{hexEsc}|{charEsc} strConst = \"{schar}*\" %state NORMALSTATE, COMMENT1STATE, COMMENT2STATE, LEXERRORSTATE %% { {newline} { lineNumber++; } {space} { } "(" { return token( sym.LEFT ); } ")" { return token( sym.RIGHT ); } "[" { return token( sym.LEFTSQ ); } "]" { return token( sym.RIGHTSQ ); } "{" { return token( sym.LEFTBRACE ); } "}" { return token( sym.RIGHTBRACE ); } ";" { return token( sym.SEMICOLON ); } "," { return token( sym.COMMA ); } "." { return token( sym.DOT ); } "@" { return token( sym.AT ); } "=" { return token( sym.ASSIGN ); } "?" { return token( sym.QUEST ); } ":" { return token( sym.COLON ); } "||" { return token( sym.OR ); } "&&" { return token( sym.AND ); } "<" { return token( sym.LT ); } ">" { return token( sym.GT ); } "<=" { return token( sym.LE ); } ">=" { return token( sym.GE ); } "==" { return token( sym.EQ ); } "!=" { return token( sym.NE ); } "<<" { return token( sym.LEFTSHIFT ); } ">>" { return token( sym.RIGHTSHIFT ); } "+" { return token( sym.PLUS ); } "-" { return token( sym.MINUS ); } "&" { return token( sym.AMPERSAND ); } "*" { return token( sym.TIMES ); } "/" { return token( sym.DIVIDE ); } "%" { return token( sym.MOD ); } "!" { return token( sym.NOT ); } include { return token( sym.INCLUDE ); } define { return token( sym.DEFINE ); } path { return token( sym.PATH ); } in { return token( sym.IN ); } out { return token( sym.OUT ); } component { return token( sym.COMPONENT ); } begin { return token( sym.BEGIN ); } end { return token( sym.END ); } if { return token( sym.IF ); } then { return token( sym.THEN ); } else { return token( sym.ELSE ); } elif { return token( sym.ELIF ); } for { return token( sym.FOR ); } from { return token( sym.FROM ); } upto { return token( sym.UPTO ); } do { return token( sym.DO ); } true { return token( sym.TRUE ); } false { return token( sym.FALSE ); } {binConst} { return token( sym.BINLITERAL ); } {decConst} { return token( sym.DECLITERAL ); } {hexConst} { return token( sym.HEXLITERAL ); } {strConst} { return token( sym.STRINGLITERAL ); } {ident} { return token( sym.IDENT ); } "//" { yybegin( COMMENT1STATE ); } "/*" { yybegin( COMMENT2STATE ); } . { yybegin( LEXERRORSTATE ); return token( sym.error ); } } { {newline} { lineNumber++; yybegin( NORMALSTATE ); return token( sym.error ); } . { } } { {newline} { lineNumber++; yybegin( NORMALSTATE ); } . { } } { "*/" { yybegin( NORMALSTATE ); } {newline} { lineNumber++; } . { } } <> { return token( sym.EOF ); } ---------------------------------------------------------------- Source/grammar/parser.cup ---------------------------------------------------------------- package grammar; import java.io.*; import java.util.*; import java_cup.runtime.*; import node.*; import node.declNode.*; import node.declNode.componentDeclNode.*; import node.declNode.pathDefnNode.*; import node.declNode.valueDefnNode.*; import node.stmtNode.*; import node.stmtNode.forStmtNode.*; import node.stmtNode.ifStmtNode.*; import node.stmtNode.ifStmtNode.elseOptNode.*; import node.stmtNode.invocationStmtNode.*; import node.stmtNode.includeStmtNode.*; import node.exprNode.*; import node.exprNode.binaryNode.*; import node.exprNode.binaryNode.arithNode.*; import node.exprNode.binaryNode.stringNode.*; import node.exprNode.binaryNode.relationNode.*; import node.exprNode.binaryNode.boolNode.*; import node.exprNode.prefixNode.*; import node.exprNode.valueNode.*; import node.pathNode.*; import node.pathNode.pathNameNode.*; import text.*; parser code {: private Yylex lexer; private File inputFile; public File inputFile() { return inputFile; }; public int lineNumber() { return lexer.lineNumber(); } public parser( File inputFile ) { this(); this.inputFile = inputFile; try { lexer = new Yylex( new FileReader( inputFile ) ); } catch ( IOException exception ) { throw new Error( "Unable to open file \"" + inputFile + "\"" ); } } public String terminal_name( int id ) { return sym.terminal_name( id ); } public String non_terminal_name( int id ) { return sym.non_terminal_name( id ); } public String rule_name( int id ) { return sym.rule_name( id ); } public void report_error( String message, Object info ) { Print.error().println( inputFile + " ( " + lexer.lineNumber() + " ): " + message ); try { if ( info instanceof Symbol ) { Symbol symbol = ( Symbol ) info; printText( symbol.left, symbol.right ); } } catch ( IOException e ) { } } private void printText( int left, int right ) throws IOException { Reader sourceReader = new FileReader( inputFile ); int veryLeft = Math.max( left - 50, 0 ), veryRight = Math.min( right + 20, ( int ) inputFile.length() ); char[] text = new char[ veryRight - veryLeft ]; char[] underline = new char[ veryRight - veryLeft ]; sourceReader.skip( veryLeft ); sourceReader.read( text ); for ( int i = 0; i < text.length; i++ ) { if ( text[ i ] < ' ' ) { text[ i ] = '|'; underline[ i ] = '|'; } else underline[ i ] = ' '; if ( left <= veryLeft + i && veryLeft + i < right ) underline[ i ] = '^'; } printLine( text ); printLine( underline ); } private static void printLine( char[] text ) { for ( int i = 0; i < text.length; i++ ) Print.error().print( text[ i ] ); Print.error().println(); } public void syntax_error( Symbol currToken ) { report_error( "Syntax Error", currToken ); } :}; scan with {: return lexer.yylex(); :}; /****************************************************************** Terminal Symbols ******************************************************************/ terminal INCLUDE, DEFINE, PATH, IN, OUT, COMPONENT, BEGIN, END, IF, THEN, ELSE, ELIF, FOR, FROM, UPTO, DO, LEFT, RIGHT, LEFTSQ, RIGHTSQ, AT, LEFTBRACE, RIGHTBRACE, SEMICOLON, COMMA, DOT, ASSIGN, QUEST, COLON, OR, AND, LT, GT, LE, GE, EQ, NE, LEFTSHIFT, RIGHTSHIFT, PLUS, MINUS, AMPERSAND, TIMES, DIVIDE, MOD, NOT, TRUE, FALSE; terminal String BINLITERAL, DECLITERAL, HEXLITERAL; terminal String STRINGLITERAL; terminal String IDENT; /****************************************************************** Nonterminal Symbols ******************************************************************/ nonterminal DeclStmtListNode GlobalDeclStmtList, LocalDeclStmtList; nonterminal DeclStmtNode GlobalDeclStmt, LocalDeclStmt, ComponentDecl, ValueDecl, PathDecl; nonterminal ValueDefnListNode InitValueDefnList, ValueParamDecl, ValueParamDefnList; nonterminal ValueDefnNode InitValueDefn, ValueParamDefn; nonterminal PathDefnListNode InputParamDecl, OutputParamDecl, PathDefnList; nonterminal PathDefnNode PathDefn; nonterminal BodyNode Body; nonterminal StmtNode IfStmt, ForStmt, InvocationStmt, IncludeStmt; nonterminal InvocListNode InvocList; nonterminal InvocNode Invoc; nonterminal ElseOptNode ElseOpt; nonterminal PathArrayListNode InputParams, OutputParams, PathArrayList; nonterminal PathArrayNode PathArray; nonterminal PathNameListNode PathNameList; nonterminal PathNameNode PathName; nonterminal ExprListNode ValueParams, ExprList; nonterminal ExprNode Expr, CondExpr, OrExpr, AndExpr, RelExpr, ShiftExpr, AddExpr, MulExpr, PrefixExpr, Primary, LiteralValue; /****************************************************************** The Grammar ******************************************************************/ start with GlobalDeclStmtList; /****************************************************************** Statements ******************************************************************/ GlobalDeclStmtList::= /* Empty */ {: RESULT = new DeclStmtListNode(); :} | GlobalDeclStmtList:declStmtList GlobalDeclStmt:declStmt {: declStmtList.addElement( declStmt ); RESULT = declStmtList; :} ; GlobalDeclStmt::= ComponentDecl:decl {: RESULT = decl; :} | IncludeStmt:stmt {: RESULT = stmt; :} | LocalDeclStmt:declStmt {: RESULT = declStmt; :} ; LocalDeclStmtList::= /* Empty */ {: RESULT = new DeclStmtListNode(); :} | LocalDeclStmtList:declStmtList LocalDeclStmt:declStmt {: declStmtList.addElement( declStmt ); RESULT = declStmtList; :} ; LocalDeclStmt::= ValueDecl:decl {: RESULT = decl; :} | PathDecl:decl {: RESULT = decl; :} | IfStmt:stmt {: RESULT = stmt; :} | ForStmt:stmt {: RESULT = stmt; :} | InvocationStmt:stmt {: RESULT = stmt; :} | error SEMICOLON {: RESULT = new ErrorStmtNode( "error;" ); :} | error END {: RESULT = new ErrorStmtNode( "error end" ); :} ; /****************************************************************** Init Value Declarations ******************************************************************/ ValueDecl::= DEFINE InitValueDefnList:initValueDefnList SEMICOLON {: RESULT = new ValueDeclNode( initValueDefnList ); :} ; InitValueDefnList::= InitValueDefn:initValueDefn {: RESULT = new ValueDefnListNode( initValueDefn ); :} | InitValueDefnList:initValueDefnList COMMA InitValueDefn:initValueDefn {: initValueDefnList.addElement( initValueDefn ); RESULT = initValueDefnList; :} ; InitValueDefn::= IDENT:ident ASSIGN Expr:expr {: RESULT = new InitValueDefnNode( ident, expr ); :} ; /****************************************************************** Value Parameter Declarations ******************************************************************/ ValueParamDecl::= LEFT ValueParamDefnList:valueParamDefnList RIGHT {: RESULT = valueParamDefnList; :} | /* Empty */ {: RESULT = new ValueDefnListNode(); :} ; ValueParamDefnList::= ValueParamDefn:valueParamDefn {: RESULT = new ValueDefnListNode( valueParamDefn ); :} | ValueParamDefnList:valueParamDefnList COMMA ValueParamDefn:valueParamDefn {: valueParamDefnList.addElement( valueParamDefn ); RESULT = valueParamDefnList; :} ; ValueParamDefn::= IDENT:ident {: RESULT = new ValueParamDefnNode( ident ); :} ; /****************************************************************** Path Declarations ******************************************************************/ PathDecl::= PATH PathDefnList:pathDefnList SEMICOLON {: RESULT = new PathDeclNode( pathDefnList ); :} ; PathDefnList::= PathDefn:pathDefn {: RESULT = new PathDefnListNode( pathDefn ); :} | PathDefnList:pathDefnList COMMA PathDefn:pathDefn {: pathDefnList.addElement( pathDefn ); RESULT = pathDefnList; :} ; PathDefn::= IDENT:ident {: RESULT = new SimplePathDefnNode( ident ); :} | IDENT:ident LEFTSQ Expr:size RIGHTSQ {: RESULT = new ArrayPathDefnNode( ident, size ); :} ; /****************************************************************** Path Parameter Declarations ******************************************************************/ InputParamDecl::= LEFTBRACE IN PathDefnList:pathDefnList RIGHTBRACE {: RESULT = pathDefnList; :} | /* Empty */ {: RESULT = new PathDefnListNode(); :} ; OutputParamDecl::= LEFTBRACE OUT PathDefnList:pathDefnList RIGHTBRACE {: RESULT = pathDefnList; :} | /* Empty */ {: RESULT = new PathDefnListNode(); :} ; /****************************************************************** Component Declarations ******************************************************************/ ComponentDecl::= COMPONENT InputParamDecl:inputParamDecl IDENT:ident ValueParamDecl:valueParamDecl OutputParamDecl:outputParamDecl Body:body {: RESULT = new ComponentDeclNode( inputParamDecl, ident, valueParamDecl, outputParamDecl, body ); :} ; Body::= BEGIN LocalDeclStmtList:declStmtList END {: RESULT = new NonEmptyBodyNode( declStmtList ); :} | SEMICOLON {: RESULT = new EmptyBodyNode(); :} ; /****************************************************************** Include Statements ******************************************************************/ IncludeStmt::= INCLUDE STRINGLITERAL:value SEMICOLON {: try { String includeFileName = Convert.parseString( value.substring( 1, value.length() - 1 ) ); File includeFile = new File( includeFileName ); parser p = new parser( includeFile ); DeclStmtListNode includeProgram = ( DeclStmtListNode ) ( p.parse().value ); RESULT = new IncludeStmtNode( includeFileName, includeProgram ); } catch ( IOException error ) { Print.error().println( "Can't open included file \"" + parser.inputFile() ); RESULT = new ErrorStmtNode( "include " + value + ";" ); } :} ; /****************************************************************** Control Statements ******************************************************************/ IfStmt::= IF Expr:expr THEN LocalDeclStmtList:thenPart ElseOpt:elsePart END {: RESULT = new IfStmtNode( expr, thenPart, elsePart ); :} ; ElseOpt::= {: RESULT = new ElseOpt0Node(); :} | ELSE LocalDeclStmtList:elsePart {: RESULT = new ElseOpt1Node( elsePart ); :} | ELIF Expr:expr THEN LocalDeclStmtList:thenPart ElseOpt:elsePart {: RESULT = new ElseOpt2Node( expr, thenPart, elsePart ); :} ; ForStmt::= FOR IDENT:ident FROM Expr:fromExpr UPTO Expr:toExpr DO LocalDeclStmtList:doPart END {: RESULT = new ForStmtNode( ident, fromExpr, toExpr, doPart ); :} ; /****************************************************************** Invocations ******************************************************************/ InvocationStmt::= InputParams:inputParams InvocList:invocList OutputParams:outputParams SEMICOLON {: RESULT = new InvocationStmtNode( inputParams, invocList, outputParams ); :} ; InvocList::= Invoc:invoc {: RESULT = new InvocListNode( invoc ); :} | InvocList:invocList DOT Invoc:invoc {: invocList.addElement( invoc ); RESULT = invocList; :} ; Invoc::= IDENT:ident ValueParams:valueParams {: RESULT = new InvocNode( ident, valueParams ); :} ; InputParams::= LEFTBRACE IN PathArrayList:pathArrayList RIGHTBRACE {: RESULT = pathArrayList; :} | /* Empty */ {: RESULT = new PathArrayListNode(); :} ; ValueParams::= LEFT ExprList:exprList RIGHT {: RESULT = exprList; :} | /* Empty */ {: RESULT = new ExprListNode(); :} ; OutputParams::= LEFTBRACE OUT PathArrayList:pathArrayList RIGHTBRACE {: RESULT = pathArrayList; :} | /* Empty */ {: RESULT = new PathArrayListNode(); :} ; /****************************************************************** Paths ******************************************************************/ PathArrayList::= PathArray:pathArray {: RESULT = new PathArrayListNode( pathArray ); :} | PathArrayList:pathArrayList COMMA PathArray:pathArray {: pathArrayList.addElement( pathArray ); RESULT = pathArrayList; :} ; PathArray::= PathNameList:pathNameList {: RESULT = new PathArrayNode( pathNameList ); :} ; PathNameList::= /* Empty */ {: RESULT = new PathNameListNode(); :} | PathNameList:pathNameList PathName:pathName {: pathNameList.addElement( pathName ); RESULT = pathNameList; :} ; PathName::= IDENT:ident {: RESULT = new SimplePathNameNode( ident ); :} | IDENT:ident LEFTSQ Expr:index RIGHTSQ {: RESULT = new IndexPathNameNode( ident, index ); :} | IDENT:ident LEFTSQ Expr:size AT Expr:base RIGHTSQ {: RESULT = new SubArrayPathNameNode( ident, size, base ); :} ; /****************************************************************** Expressions ******************************************************************/ ExprList::= Expr:expr {: RESULT = new ExprListNode( expr ); :} | ExprList:exprList COMMA Expr:expr {: exprList.addElement( expr ); RESULT = exprList; :} ; Expr::= CondExpr:expr {: RESULT = expr; :} ; CondExpr::= OrExpr:cond QUEST Expr:expr1 COLON Expr:expr2 {: RESULT = new CondNode( cond, expr1, expr2 ); :} | OrExpr:expr {: RESULT = expr; :} ; OrExpr::= OrExpr:expr1 OR AndExpr:expr2 {: RESULT = new OrNode( expr1, expr2 ); :} | AndExpr:expr {: RESULT = expr; :} ; AndExpr::= AndExpr:expr1 AND RelExpr:expr2 {: RESULT = new AndNode( expr1, expr2 ); :} | RelExpr:expr {: RESULT = expr; :} ; RelExpr::= ShiftExpr:expr1 LT ShiftExpr:expr2 {: RESULT = new LessThanNode( expr1, expr2 ); :} | ShiftExpr:expr1 GT ShiftExpr:expr2 {: RESULT = new GreaterThanNode( expr1, expr2 ); :} | ShiftExpr:expr1 LE ShiftExpr:expr2 {: RESULT = new LessEqualNode( expr1, expr2 ); :} | ShiftExpr:expr1 GE ShiftExpr:expr2 {: RESULT = new GreaterEqualNode( expr1, expr2 ); :} | ShiftExpr:expr1 EQ ShiftExpr:expr2 {: RESULT = new EqualNode( expr1, expr2 ); :} | ShiftExpr:expr1 NE ShiftExpr:expr2 {: RESULT = new NotEqualNode( expr1, expr2 ); :} | ShiftExpr:expr {: RESULT = expr; :} ; ShiftExpr::= ShiftExpr:expr1 LEFTSHIFT AddExpr:expr2 {: RESULT = new LeftShiftNode( expr1, expr2 ); :} | ShiftExpr:expr1 RIGHTSHIFT AddExpr:expr2 {: RESULT = new RightShiftNode( expr1, expr2 ); :} | AddExpr:expr {: RESULT = expr; :} ; AddExpr::= AddExpr:expr1 PLUS MulExpr:expr2 {: RESULT = new PlusNode( expr1, expr2 ); :} | AddExpr:expr1 MINUS MulExpr:expr2 {: RESULT = new MinusNode( expr1, expr2 ); :} | AddExpr:expr1 AMPERSAND MulExpr:expr2 {: RESULT = new ConcatStringNode( expr1, expr2 ); :} | MulExpr:expr {: RESULT = expr; :} ; MulExpr::= MulExpr:expr1 TIMES PrefixExpr:expr2 {: RESULT = new TimesNode( expr1, expr2 ); :} | MulExpr:expr1 DIVIDE PrefixExpr:expr2 {: RESULT = new DivideNode( expr1, expr2 ); :} | MulExpr:expr1 MOD PrefixExpr:expr2 {: RESULT = new ModNode( expr1, expr2 ); :} | PrefixExpr:expr {: RESULT = expr; :} ; PrefixExpr::= MINUS PrefixExpr:expr {: RESULT = new NegateNode( expr ); :} | NOT PrefixExpr:expr {: RESULT = new NotNode( expr ); :} | Primary:expr {: RESULT = expr; :} ; Primary::= LEFT Expr:expr RIGHT {: RESULT = expr; :} | IDENT:ident {: RESULT = new NameNode( ident ); :} | LiteralValue:value {: RESULT = value; :} ; LiteralValue::= BINLITERAL:value {: RESULT = new IntValueNode( 2, Integer.valueOf( value.substring( 2 ), 2 ).intValue() ); :} | DECLITERAL:value {: RESULT = new IntValueNode( 10, Integer.valueOf( value, 10 ).intValue() ); :} | HEXLITERAL:value {: RESULT = new IntValueNode( 16, Integer.valueOf( value.substring( 2 ), 16 ).intValue() ); :} | TRUE {: RESULT = new BoolValueNode( true ); :} | FALSE {: RESULT = new BoolValueNode( false ); :} | STRINGLITERAL:value {: RESULT = new StringValueNode( Convert.parseString( value.substring( 1, value.length() - 1 ) ) ); :} ; ---------------------------------------------------------------- Source/node/exprNode/valueNode/IntValueNode.java ---------------------------------------------------------------- package node.exprNode.valueNode; import node.*; import node.exprNode.*; import runEnv.*; import runEnv.basicValue.*; public class IntValueNode extends ValueNode { private int base; private int value; public IntValueNode( int base, int value ) { this.base = base; this.value = value; } public String toString() { switch ( base ) { case 2: return "0b" + Integer.toBinaryString( value ); case 10: return "" + value; case 16: return "0x" + Integer.toHexString( value ); default: throw new Error( "Invalid base of " + base ); } } public RunValue eval( RunEnv runEnv ) { return new IntValue( value ); } } ---------------------------------------------------------------- Source/node/declNode/ValueDeclNode.java ---------------------------------------------------------------- package node.declNode; import node.declNode.valueDefnNode.*; import runEnv.*; public class ValueDeclNode extends DeclNode { private ValueDefnListNode defnList; public ValueDeclNode( ValueDefnListNode defnList ) { this.defnList = defnList; } public String toString() { return "define " + defnList + ";"; } public void eval( RunEnv runEnv ) { defnList.eval( RunDecl.VALUE, runEnv, new RunValue[ defnList.size() ] ); } } ---------------------------------------------------------------- Source/node/declNode/valueDefnNode/InitValueDefnNode.java ---------------------------------------------------------------- package node.declNode.valueDefnNode; import node.*; import node.exprNode.*; import runEnv.*; public class InitValueDefnNode extends ValueDefnNode { private ExprNode expr; public InitValueDefnNode( String ident, ExprNode expr ) { this.ident = ident; this.expr = expr; } public String toString() { return ident + " = " + expr; } public void eval( int kind, RunEnv runEnv, RunValue value ) { runEnv.declare( kind, ident, expr.eval( runEnv ) ); } } ---------------------------------------------------------------- Source/node/declNode/valueDefnNode/ValueDefnListNode.java ---------------------------------------------------------------- package node.declNode.valueDefnNode; import node.*; import runEnv.*; public class ValueDefnListNode extends ListNode< ValueDefnNode > { public ValueDefnListNode() { super( ", " ); } public ValueDefnListNode( ValueDefnNode node ) { this(); addElement( node ); } public void eval( int kind, RunEnv runEnv, RunValue[] value ) { if ( value.length != size() ) throw new Error( "Incorrect number of parameters" ); for ( int i = 0; i < size(); i++ ) { ValueDefnNode element = elementAt( i ); element.eval( kind, runEnv, value[ i ] ); } } } ---------------------------------------------------------------- Source/node/declNode/valueDefnNode/ValueDefnNode.java ---------------------------------------------------------------- package node.declNode.valueDefnNode; import node.*; import node.exprNode.*; import runEnv.*; public abstract class ValueDefnNode extends Node { protected String ident; public String ident() { return ident; } public abstract void eval( int kind, RunEnv runEnv, RunValue value ); } ---------------------------------------------------------------- Source/node/declNode/valueDefnNode/ValueParamDefnNode.java ---------------------------------------------------------------- package node.declNode.valueDefnNode; import node.*; import runEnv.*; public class ValueParamDefnNode extends ValueDefnNode { public ValueParamDefnNode( String ident ) { this.ident = ident; } public String toString() { return ident; } public void eval( int kind, RunEnv runEnv, RunValue value ) { runEnv.declare( kind, ident, value ); } } ---------------------------------------------------------------- Source/node/declNode/PathDeclNode.java ---------------------------------------------------------------- package node.declNode; import node.declNode.pathDefnNode.*; import runEnv.*; public class PathDeclNode extends DeclNode { private PathDefnListNode pathDefnList; public PathDeclNode( PathDefnListNode pathDefnList ) { this.pathDefnList = pathDefnList; } public String toString() { return "path " + pathDefnList + ";"; } public void eval( RunEnv runEnv ) { pathDefnList.eval( RunDecl.PATH, runEnv, new PathArrayValue[ pathDefnList.size() ] ); } } ---------------------------------------------------------------- Source/node/declNode/pathDefnNode/ArrayPathDefnNode.java ---------------------------------------------------------------- package node.declNode.pathDefnNode; import node.exprNode.*; import runEnv.*; public class ArrayPathDefnNode extends PathDefnNode { private ExprNode size; public ArrayPathDefnNode( String ident, ExprNode size ) { this.ident = ident; this.size = size; } public String toString() { return ident + "[ " + size + " ]"; } public PathArrayValue eval( int kind, RunEnv runEnv, PathArrayValue value ) { int sizeValue = size.eval( runEnv ).intValue(); if ( value == null ) value = new PathArrayValue( sizeValue ); if ( value.size() != sizeValue ) throw new Error( "Incompatible parameter " + value + " for " + ident + "[ " + sizeValue + " ]" ); runEnv.declare( kind, ident, value ); return value; } } ---------------------------------------------------------------- Source/node/declNode/pathDefnNode/PathDefnListNode.java ---------------------------------------------------------------- package node.declNode.pathDefnNode; import node.*; import runEnv.*; public class PathDefnListNode extends ListNode< PathDefnNode > { public PathDefnListNode() { super( ", " ); } public PathDefnListNode( PathDefnNode node ) { this(); addElement( node ); } public void eval( int kind, RunEnv runEnv, PathArrayValue[] value ) { if ( value.length != size() ) throw new Error( "Incorrect number of path parameters" ); for ( int i = 0; i < size(); i++ ) { PathDefnNode element = elementAt( i ); value[ i ] = element.eval( kind, runEnv, value[ i ] ); } } } ---------------------------------------------------------------- Source/node/declNode/pathDefnNode/PathDefnNode.java ---------------------------------------------------------------- package node.declNode.pathDefnNode; import node.*; import runEnv.*; public abstract class PathDefnNode extends Node { protected String ident; public String ident() { return ident; } public abstract PathArrayValue eval( int kind, RunEnv runEnv, PathArrayValue value ); } ---------------------------------------------------------------- Source/node/declNode/pathDefnNode/SimplePathDefnNode.java ---------------------------------------------------------------- package node.declNode.pathDefnNode; import runEnv.*; public class SimplePathDefnNode extends PathDefnNode { public SimplePathDefnNode( String ident ) { this.ident = ident; } public String toString() { return ident; } public PathArrayValue eval( int kind, RunEnv runEnv, PathArrayValue value ) { if ( value == null ) value = new PathArrayValue( 1 ); if ( value.size() != 1 ) throw new Error( "Incompatible parameter " + value + " for " + this ); runEnv.declare( kind, ident, value ); return value; } } ---------------------------------------------------------------- Source/node/declNode/componentDeclNode/ComponentDeclNode.java ---------------------------------------------------------------- package node.declNode.componentDeclNode; import node.declNode.*; import node.declNode.pathDefnNode.*; import node.declNode.valueDefnNode.*; import runEnv.*; public class ComponentDeclNode extends DeclNode { private PathDefnListNode inputParamDecl; private String ident; private ValueDefnListNode paramDecl; private PathDefnListNode outputParamDecl; private BodyNode body; public PathDefnListNode inputParamDecl() { return inputParamDecl; } public String ident() { return ident; } public ValueDefnListNode paramDecl() { return paramDecl; } public PathDefnListNode outputParamDecl() { return outputParamDecl; } public ComponentDeclNode( PathDefnListNode inputParamDecl, String ident, ValueDefnListNode paramDecl, PathDefnListNode outputParamDecl, BodyNode body ) { this.inputParamDecl = inputParamDecl; this.ident = ident; this.paramDecl = paramDecl; this.outputParamDecl = outputParamDecl; this.body = body; } public String toString() { String inputParamsText = ""; String paramsText = ""; String outputParamsText = ""; if ( inputParamDecl.size() != 0 ) inputParamsText = "{ in " + inputParamDecl + " } "; if ( paramDecl.size() != 0 ) paramsText = "( " + paramDecl + " )"; if ( outputParamDecl.size() != 0 ) outputParamsText = " { out " + outputParamDecl + " }"; return "component " + inputParamsText + ident + paramsText + outputParamsText + body; } public void eval( RunEnv runEnv ) { runEnv.declare( RunDecl.COMPONENT, ident, new ComponentValue( this, runEnv ) ); } public void invoke( RunEnv declEnv, PathArrayValue[] inputParamValues, RunValue[] paramValues, PathArrayValue[] outputParamValues ) { RunEnv localEnv = new RunEnv( ident, declEnv ); paramDecl.eval( RunDecl.VALUEPARAM, localEnv, paramValues ); inputParamDecl.eval( RunDecl.INPUTPARAM, localEnv, inputParamValues ); outputParamDecl.eval( RunDecl.OUTPUTPARAM, localEnv, outputParamValues ); body.eval( localEnv ); } } ---------------------------------------------------------------- Source/node/stmtNode/invocationStmtNode/InvocListNode.java ---------------------------------------------------------------- package node.stmtNode.invocationStmtNode; import node.*; import node.exprNode.*; import node.pathNode.*; import node.declNode.componentDeclNode.*; import node.declNode.pathDefnNode.*; import node.declNode.valueDefnNode.*; import runEnv.*; import text.*; public class InvocListNode extends ListNode< InvocNode > { public InvocListNode() { super( "." ); } public InvocListNode( InvocNode node ) { this(); addElement( node ); } public void eval( RunEnv runEnv, PathArrayValue[] firstParamValues, PathArrayValue[] lastParamValues ) { PathArrayValue[] inputParamValues = null; PathArrayValue[] outputParamValues = null; for ( int i = 0; i < size(); i++ ) { InvocNode invocNode = elementAt( i ); String ident = invocNode.ident(); if ( i == 0 ) inputParamValues = firstParamValues; else inputParamValues = outputParamValues; if ( i == size() - 1 ) outputParamValues = lastParamValues; else { ComponentValue componentValue = runEnv.getValue( ident ).componentValue(); outputParamValues = new PathArrayValue[ componentValue.componentDecl().outputParamDecl().size() ]; } invocNode.eval( runEnv, inputParamValues, outputParamValues ); } } } ---------------------------------------------------------------- Source/node/stmtNode/invocationStmtNode/InvocNode.java ---------------------------------------------------------------- package node.stmtNode.invocationStmtNode; import node.*; import node.exprNode.*; import node.pathNode.*; import runEnv.*; public class InvocNode extends Node { private String ident; private ExprListNode valueParams; public String ident() { return ident; } public ExprListNode valueParams() { return valueParams; } public InvocNode( String ident, ExprListNode valueParams ) { this.ident = ident; this.valueParams = valueParams; } public String toString() { String valueParamsText = ""; if ( valueParams.size() != 0 ) valueParamsText = "( " + valueParams + " )"; return ident + valueParamsText; } public void eval( RunEnv runEnv, PathArrayValue[] inputParamValues, PathArrayValue[] outputParamValues ) { ComponentValue componentValue = runEnv.getValue( ident ).componentValue(); RunValue[] paramValues = valueParams.eval( runEnv ); componentValue.eval( inputParamValues, paramValues, outputParamValues ); } } ---------------------------------------------------------------- Source/node/stmtNode/invocationStmtNode/InvocationStmtNode.java ---------------------------------------------------------------- package node.stmtNode.invocationStmtNode; import node.stmtNode.*; import node.exprNode.*; import node.pathNode.*; import node.declNode.componentDeclNode.*; import node.declNode.pathDefnNode.*; import node.declNode.valueDefnNode.*; import runEnv.*; public class InvocationStmtNode extends StmtNode { private PathArrayListNode inputParams; private InvocListNode invocList; private PathArrayListNode outputParams; public InvocationStmtNode( PathArrayListNode inputParams, InvocListNode invocList, PathArrayListNode outputParams ) { this.inputParams = inputParams; this.invocList = invocList; this.outputParams = outputParams; } public String toString() { String inputParamsText = ""; String outputParamsText = ""; if ( inputParams.size() != 0 ) inputParamsText = "{ in " + inputParams + " } "; if ( outputParams.size() != 0 ) outputParamsText = " { out " + outputParams + " }"; return inputParamsText + invocList + outputParamsText + ";"; } public void eval( RunEnv runEnv ) { PathArrayValue[] inputParamValues = inputParams.eval( runEnv ); PathArrayValue[] outputParamValues = outputParams.eval( runEnv ); invocList.eval( runEnv, inputParamValues, outputParamValues ); } } ---------------------------------------------------------------- Source/node/pathNode/pathNameNode/IndexPathNameNode.java ---------------------------------------------------------------- package node.pathNode.pathNameNode; import node.exprNode.*; import runEnv.*; public class IndexPathNameNode extends PathNameNode { private String ident; private ExprNode index; public IndexPathNameNode( String ident, ExprNode index ) { this.ident = ident; this.index = index; } public String toString() { return ident + "[ " + index + " ]"; } public PathArrayValue eval( RunEnv runEnv ) { PathArrayValue pathArray = runEnv.getValue( ident ).pathArrayValue(); int indexValue = index.eval( runEnv ).intValue(); // System.err.println( "Indexing " + pathArray + "[ " + indexValue + " ]" ); return pathArray.index( indexValue ); } } ---------------------------------------------------------------- Source/node/pathNode/pathNameNode/PathNameListNode.java ---------------------------------------------------------------- package node.pathNode.pathNameNode; import node.*; import runEnv.*; public class PathNameListNode extends ListNode< PathNameNode > { public PathNameListNode() { super( " " ); } public PathNameListNode( PathNameNode node ) { this(); addElement( node ); } public PathArrayValue[] eval( RunEnv runEnv ) { PathArrayValue[] result = new PathArrayValue[ size() ]; for ( int i = 0; i < size(); i++ ) { PathNameNode element = elementAt( i ); result[ i ] = element.eval( runEnv ); } return result; } } ---------------------------------------------------------------- Source/node/pathNode/pathNameNode/PathNameNode.java ---------------------------------------------------------------- package node.pathNode.pathNameNode; import node.*; import runEnv.*; public abstract class PathNameNode extends Node { public abstract PathArrayValue eval( RunEnv runEnv ); } ---------------------------------------------------------------- Source/node/pathNode/pathNameNode/SimplePathNameNode.java ---------------------------------------------------------------- package node.pathNode.pathNameNode; import runEnv.*; public class SimplePathNameNode extends PathNameNode { private String ident; public SimplePathNameNode( String ident ) { this.ident = ident; } public String toString() { return ident; } public PathArrayValue eval( RunEnv runEnv ) { return runEnv.getValue( ident ).pathArrayValue(); } } ---------------------------------------------------------------- Source/node/pathNode/pathNameNode/SubArrayPathNameNode.java ---------------------------------------------------------------- package node.pathNode.pathNameNode; import node.exprNode.*; import runEnv.*; public class SubArrayPathNameNode extends PathNameNode { private String ident; private ExprNode size; private ExprNode base; public SubArrayPathNameNode( String ident, ExprNode size, ExprNode base ) { this.ident = ident; this.size = size; this.base = base; } public String toString() { return ident + "[ " + size + "@" + base + " ]"; } public PathArrayValue eval( RunEnv runEnv ) { PathArrayValue pathArray = runEnv.getValue( ident ).pathArrayValue(); int sizeValue = size.eval( runEnv ).intValue(); int baseValue = base.eval( runEnv ).intValue(); return pathArray.subArray( baseValue, sizeValue ); } } ---------------------------------------------------------------- Source/node/stmtNode/ifStmtNode/IfStmtNode.java ---------------------------------------------------------------- package node.stmtNode.ifStmtNode; import node.*; import node.stmtNode.*; import node.stmtNode.ifStmtNode.elseOptNode.*; import node.exprNode.*; import runEnv.*; public class IfStmtNode extends StmtNode { private ExprNode cond; private DeclStmtListNode thenPart; private ElseOptNode elsePart; public IfStmtNode( ExprNode cond, DeclStmtListNode thenPart, ElseOptNode elsePart ) { this.cond = cond; this.thenPart = thenPart; this.elsePart = elsePart; } public String toString() { return "if " + cond + "%nthen%+%n" + thenPart + "%-" + elsePart + "%nend"; } public void eval( RunEnv runEnv ) { if ( cond.eval( runEnv ).boolValue() ) { RunEnv localEnv = new RunEnv( "then", runEnv ); thenPart.eval( localEnv ); } else { elsePart.eval( runEnv ); } } } ---------------------------------------------------------------- Source/node/stmtNode/ifStmtNode/elseOptNode/ElseOpt0Node.java ---------------------------------------------------------------- package node.stmtNode.ifStmtNode.elseOptNode; import runEnv.*; public class ElseOpt0Node extends ElseOptNode { public ElseOpt0Node() { } public String toString() { return ""; } public void eval( RunEnv runEnv ) { } } ---------------------------------------------------------------- Source/node/stmtNode/ifStmtNode/elseOptNode/ElseOpt1Node.java ---------------------------------------------------------------- package node.stmtNode.ifStmtNode.elseOptNode; import node.*; import node.stmtNode.*; import node.exprNode.*; import runEnv.*; public class ElseOpt1Node extends ElseOptNode { private DeclStmtListNode elsePart; public ElseOpt1Node( DeclStmtListNode elsePart ) { this.elsePart = elsePart; } public String toString() { return "%nelse%+%n" + elsePart + "%-"; } public void eval( RunEnv runEnv ) { RunEnv localEnv = new RunEnv( "else", runEnv ); elsePart.eval( localEnv ); } } ---------------------------------------------------------------- Source/node/stmtNode/ifStmtNode/elseOptNode/ElseOpt2Node.java ---------------------------------------------------------------- package node.stmtNode.ifStmtNode.elseOptNode; import node.*; import node.stmtNode.*; import node.exprNode.*; import runEnv.*; public class ElseOpt2Node extends ElseOptNode { private ExprNode cond; private DeclStmtListNode thenPart; private ElseOptNode elsePart; public ElseOpt2Node( ExprNode cond, DeclStmtListNode thenPart, ElseOptNode elsePart ) { this.cond = cond; this.thenPart = thenPart; this.elsePart = elsePart; } public String toString() { return "%nelif " + cond + "%nthen%+%n" + thenPart + "%-" + elsePart; } public void eval( RunEnv runEnv ) { if ( cond.eval( runEnv ).boolValue() ) { RunEnv localEnv = new RunEnv( "then", runEnv ); thenPart.eval( localEnv ); } else elsePart.eval( runEnv ); } } ---------------------------------------------------------------- Source/node/stmtNode/ifStmtNode/elseOptNode/ElseOptNode.java ---------------------------------------------------------------- package node.stmtNode.ifStmtNode.elseOptNode; import node.*; import runEnv.*; public abstract class ElseOptNode extends Node { public abstract void eval( RunEnv runEnv ); } ---------------------------------------------------------------- Source/node/stmtNode/forStmtNode/ForStmtNode.java ---------------------------------------------------------------- package node.stmtNode.forStmtNode; import node.*; import node.stmtNode.*; import node.exprNode.*; import runEnv.*; import runEnv.basicValue.*; public class ForStmtNode extends StmtNode { private String ident; private ExprNode fromExpr; private ExprNode toExpr; private DeclStmtListNode doPart; public ForStmtNode( String ident, ExprNode fromExpr, ExprNode toExpr, DeclStmtListNode doPart ) { this.ident = ident; this.fromExpr = fromExpr; this.toExpr = toExpr; this.doPart = doPart; } public String toString() { return "for " + ident + " from " + fromExpr + " upto " + toExpr + "%ndo%n%+" + doPart + "%-%nend"; } public void eval( RunEnv runEnv ) { int fromValue = fromExpr.eval( runEnv ).intValue(); int toValue = toExpr.eval( runEnv ).intValue(); for ( int i = fromValue; i < toValue; i++ ) { RunEnv localEnv = new RunEnv( "for " + ident, runEnv ); localEnv.declare( RunDecl.VALUE, ident, new IntValue( i ) ); doPart.eval( localEnv ); } } } ---------------------------------------------------------------- TestPrograms/a1.empty/program.in ---------------------------------------------------------------- /************************************************************************************ a1.empty Run with -print -expand option Check program.print to ensure reprints properly. ************************************************************************************/ ---------------------------------------------------------------- TestPrograms/a1.empty/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/a1.empty/program.print ---------------------------------------------------------------- component literal( n, litValue ) { out result[ n ] }; component counter( name, x, y, base, n ) { out result[ n ] }; component input( name, x, y, base, n ) { out result[ n ] }; component { in opd[ n ] } output( name, x, y, base, n ); component { in read, write, init, visible, opd[ n ] } memory( name, x, y, base, n, initValue ) { out result[ n ] }; component { in opd[ n ] } or( n ) { out result }; component { in opd[ n ] } and( n ) { out result }; component { in opd[ n ] } xor( n ) { out result }; component { in opd[ n ] } not( n ) { out result[ n ] }; component { in opd[ n ] } join( n ) { out result[ n ] }; component { in opd[ m ] } decode( m ) { out result[ 1 << m ] }; component { in index[ m ], alternative[ ( 1 << m ) * n ] } select( m, n ) { out result[ n ] }; path clear, set; literal( 1, 0 ) { out clear }; literal( 1, 1 ) { out set }; ---------------------------------------------------------------- TestPrograms/a2.base/program.in ---------------------------------------------------------------- /************************************************************************************ a2.base Representation of numbers in a base, including reprinting. Should display 3 output text fields, with the hex values "ab", "cd", "ef". Check program.print to ensure reprints properly. ************************************************************************************/ path opd1[ 8 ]; path opd2[ 8 ]; path opd3[ 8 ]; literal( 8, 0b10101011 ){ out opd1 }; literal( 8, 205 ){ out opd2 }; literal( 8, 0xef ){ out opd3 }; { in opd1 }output( "ab", 10, 50, 16, 8 ); { in opd2 }output( "cd", 10, 100, 16, 8 ); { in opd3 }output( "ef", 10, 150, 16, 8 ); ---------------------------------------------------------------- TestPrograms/a2.base/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/a2.base/program.print ---------------------------------------------------------------- path opd1[ 8 ]; path opd2[ 8 ]; path opd3[ 8 ]; literal( 8, 0b10101011 ) { out opd1 }; literal( 8, 205 ) { out opd2 }; literal( 8, 0xef ) { out opd3 }; { in opd1 } output( "ab", 10, 50, 16, 8 ); { in opd2 } output( "cd", 10, 100, 16, 8 ); { in opd3 } output( "ef", 10, 150, 16, 8 ); ---------------------------------------------------------------- TestPrograms/b1.define/program.in ---------------------------------------------------------------- /************************************************************************************ b1.define Value declarations. Should display 2 output text fields, with the hex values "ab", "cd". Check program.print to ensure reprints properly. ************************************************************************************/ define x = 171, y = 205, n = 8; path opd1[ n ], opd2[ n ]; literal( n, x ){ out opd1 }; literal( n, y ){ out opd2 }; { in opd1 }output( "ab", 10, 50, 16, n ); { in opd2 }output( "cd", 10, 100, 16, n ); ---------------------------------------------------------------- TestPrograms/b1.define/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/b1.define/program.print ---------------------------------------------------------------- define x = 171, y = 205, n = 8; path opd1[ n ], opd2[ n ]; literal( n, x ) { out opd1 }; literal( n, y ) { out opd2 }; { in opd1 } output( "ab", 10, 50, 16, n ); { in opd2 } output( "cd", 10, 100, 16, n ); ---------------------------------------------------------------- TestPrograms/b2.redecl/program.in ---------------------------------------------------------------- /************************************************************************************ b2.redecl Generation of error messages when identifiers redeclared. Should generate error message saying n is being redeclared. ************************************************************************************/ define n = 4; path opd[ n ]; define n = 4; path opd[ n ]; ---------------------------------------------------------------- TestPrograms/b2.redecl/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/b2.redecl/program.print ---------------------------------------------------------------- define n = 4; path opd[ n ]; define n = 4; path opd[ n ]; ---------------------------------------------------------------- TestPrograms/b3.undecl/program.in ---------------------------------------------------------------- /************************************************************************************ b3.undecl Generation of error messages when identifiers undeclared. Should generate an error message saying n is undeclared. ************************************************************************************/ path opd[ n ]; ---------------------------------------------------------------- TestPrograms/b3.undecl/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/b3.undecl/program.print ---------------------------------------------------------------- path opd[ n ]; ---------------------------------------------------------------- TestPrograms/c1.comp/program.in ---------------------------------------------------------------- /************************************************************************************ c1.comp Component declaration and invocation, including reprinting. Should display 1 output text field, with the hex value "ab". Check program.print to ensure reprints properly. ************************************************************************************/ component lit8( value ){ out result[ 8 ] } begin literal( 8, value ){ out result }; end component { in opd[ 8 ] } out8( name, x, y ) begin { in opd }output( name, x, y, 16, 8 ); end path opd[ 8 ]; lit8( 171 ){ out opd }; { in opd }out8( "ab", 10, 50 ); ---------------------------------------------------------------- TestPrograms/c1.comp/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/c1.comp/program.print ---------------------------------------------------------------- component lit8( value ) { out result[ 8 ] } begin literal( 8, value ) { out result }; end component { in opd[ 8 ] } out8( name, x, y ) begin { in opd } output( name, x, y, 16, 8 ); end path opd[ 8 ]; lit8( 171 ) { out opd }; { in opd } out8( "ab", 10, 50 ); ---------------------------------------------------------------- TestPrograms/d1.index/program.in ---------------------------------------------------------------- /************************************************************************************ d1.index Indexing of paths. Input a four digit hexadecimal number in the input text field, and type return. Should display the low bit of the high digit in the output text field. Check values ffef and 0010 generate 0 and 1, repectively. Check program.print to ensure reprints properly. ************************************************************************************/ path opd[ 16 ]; input( "opd", 10, 50, 16, 16 ) { out opd }; { in opd[ 4 ] } output( "opd[ 4 ]", 10, 100, 16, 1 ); ---------------------------------------------------------------- TestPrograms/d1.index/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/d1.index/program.print ---------------------------------------------------------------- path opd[ 16 ]; input( "opd", 10, 50, 16, 16 ) { out opd }; { in opd[ 4 ] } output( "opd[ 4 ]", 10, 100, 16, 1 ); ---------------------------------------------------------------- TestPrograms/d2.subarray/program.in ---------------------------------------------------------------- /************************************************************************************ d2.subarray Path subarrays. Input a four digit hexadecimal number in the input text field, and type return. Should display the middle digits in the output text field. Check value abcd generates bc. Check program.print to ensure reprints properly. ************************************************************************************/ path opd[ 16 ]; input( "opd", 10, 50, 16, 16 ) { out opd }; { in opd[ 8 @ 4 ] } output( "opd[ 8 @ 4 ]", 10, 100, 16, 8 ); ---------------------------------------------------------------- TestPrograms/d2.subarray/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/d2.subarray/program.print ---------------------------------------------------------------- path opd[ 16 ]; input( "opd", 10, 50, 16, 16 ) { out opd }; { in opd[ 8@4 ] } output( "opd[ 8 @ 4 ]", 10, 100, 16, 8 ); ---------------------------------------------------------------- TestPrograms/d3.juxtapose/program.in ---------------------------------------------------------------- /************************************************************************************ d3.juxtapose Juxtaposition of paths. Input two one digit hexadecimal numbers in the input text fields, and type return for each one. Should display the concatenation of the digits in the output text field. Check that values a and b generate output ba. Check program.print to ensure reprints properly. ************************************************************************************/ path opd1[ 4 ], opd2[ 4 ]; input( "opd1", 10, 50, 16, 4 ) { out opd1 }; input( "opd2", 10, 100, 16, 4 ) { out opd2 }; { in opd2 opd1 } output( "opd2 opd1", 10, 150, 16, 2 * 4 ); ---------------------------------------------------------------- TestPrograms/d3.juxtapose/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/d3.juxtapose/program.print ---------------------------------------------------------------- path opd1[ 4 ], opd2[ 4 ]; input( "opd1", 10, 50, 16, 4 ) { out opd1 }; input( "opd2", 10, 100, 16, 4 ) { out opd2 }; { in opd2 opd1 } output( "opd2 opd1", 10, 150, 16, 2 * 4 ); ---------------------------------------------------------------- TestPrograms/e1.if/program.in ---------------------------------------------------------------- /************************************************************************************ e1.if If statements. Should display a single output text field, with the value 1. Check program.print to ensure reprints properly. ************************************************************************************/ define i = 1; path opd[ 4 ]; literal( 4, i ){ out opd }; if i == 0 then { in opd }output( "i = 0", 10, 50 * 0, 16, 4 ); elif i == 1 then { in opd }output( "i = 1", 10, 50 * 1, 16, 4 ); elif i == 2 then { in opd }output( "i = 2", 10, 50 * 2, 16, 4 ); else { in opd }output( "i > 2", 10, 50 * 3, 16, 4 ); end ---------------------------------------------------------------- TestPrograms/e1.if/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/e1.if/program.print ---------------------------------------------------------------- define i = 1; path opd[ 4 ]; literal( 4, i ) { out opd }; if i == 0 then { in opd } output( "i = 0", 10, 50 * 0, 16, 4 ); elif i == 1 then { in opd } output( "i = 1", 10, 50 * 1, 16, 4 ); elif i == 2 then { in opd } output( "i = 2", 10, 50 * 2, 16, 4 ); else { in opd } output( "i > 2", 10, 50 * 3, 16, 4 ); end ---------------------------------------------------------------- TestPrograms/e2.if/program.in ---------------------------------------------------------------- /************************************************************************************ e2.if If statements. Should display a single output text field, with the value 3. Check program.print to ensure reprints properly. ************************************************************************************/ define i = 3; if i == 0 then path opd[ 4 ]; literal( 4, 0 ){ out opd }; { in opd }output( "i = 0", 10, 50 * 0, 16, 4 ); elif i == 1 then path opd[ 4 ]; literal( 4, 1 ){ out opd }; { in opd }output( "i = 1", 10, 50 * 1, 16, 4 ); elif i == 2 then path opd[ 4 ]; literal( 4, 2 ){ out opd }; { in opd }output( "i = 2", 10, 50 * 2, 16, 4 ); else path opd[ 4 ]; literal( 4, 3 ){ out opd }; { in opd }output( "i > 2", 10, 50 * 3, 16, 4 ); end ---------------------------------------------------------------- TestPrograms/e2.if/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/e2.if/program.print ---------------------------------------------------------------- define i = 3; if i == 0 then path opd[ 4 ]; literal( 4, 0 ) { out opd }; { in opd } output( "i = 0", 10, 50 * 0, 16, 4 ); elif i == 1 then path opd[ 4 ]; literal( 4, 1 ) { out opd }; { in opd } output( "i = 1", 10, 50 * 1, 16, 4 ); elif i == 2 then path opd[ 4 ]; literal( 4, 2 ) { out opd }; { in opd } output( "i = 2", 10, 50 * 2, 16, 4 ); else path opd[ 4 ]; literal( 4, 3 ) { out opd }; { in opd } output( "i > 2", 10, 50 * 3, 16, 4 ); end ---------------------------------------------------------------- TestPrograms/e3.iferror/program.in ---------------------------------------------------------------- /************************************************************************************ e3.iferror Scope of local declarations in if statements. Should generate an error message to say Identifier opd undeclared at literal( 4, 1 ) { out opd }; Check program.print to ensure reprints properly. ************************************************************************************/ define i = 3; if i == 0 then path opd[ 4 ]; literal( 4, 0 ){ out opd }; { in opd }output( "i = 0", 10, 50 * 0, 16, 4 ); elif i == 1 then path opd[ 4 ]; literal( 4, 1 ){ out opd }; { in opd }output( "i = 1", 10, 50 * 1, 16, 4 ); elif i == 2 then path opd[ 4 ]; literal( 4, 1 ){ out opd }; { in opd }output( "i = 2", 10, 50 * 2, 16, 4 ); end literal( 4, 1 ){ out opd }; { in opd }output( "global", 10, 50 * 3, 16, 4 ); ---------------------------------------------------------------- TestPrograms/e3.iferror/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/e3.iferror/program.print ---------------------------------------------------------------- define i = 3; if i == 0 then path opd[ 4 ]; literal( 4, 0 ) { out opd }; { in opd } output( "i = 0", 10, 50 * 0, 16, 4 ); elif i == 1 then path opd[ 4 ]; literal( 4, 1 ) { out opd }; { in opd } output( "i = 1", 10, 50 * 1, 16, 4 ); elif i == 2 then path opd[ 4 ]; literal( 4, 1 ) { out opd }; { in opd } output( "i = 2", 10, 50 * 2, 16, 4 ); end literal( 4, 1 ) { out opd }; { in opd } output( "global", 10, 50 * 3, 16, 4 ); ---------------------------------------------------------------- TestPrograms/f1.for/program.in ---------------------------------------------------------------- /************************************************************************************ f1.for For loops. Should display 7 output text fields, with the values 1, 2, 3, 4, 5, 6, 7. Check program.print to ensure reprints properly. ************************************************************************************/ for i from 1 upto 8 do path opd[ 4 ]; literal( 4, i ){ out opd }; { in opd }output( "i = " & i, 10, 50 * i, 16, 4 ); end ---------------------------------------------------------------- TestPrograms/f1.for/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/f1.for/program.print ---------------------------------------------------------------- for i from 1 upto 8 do path opd[ 4 ]; literal( 4, i ) { out opd }; { in opd } output( "i = " & i, 10, 50 * i, 16, 4 ); end ---------------------------------------------------------------- TestPrograms/g1.pipe/program.in ---------------------------------------------------------------- /************************************************************************************ g1.pipe Pipelining of invocations. Input two four digit hexadecimal numbers in the input text fields, and type return for each one. Should display the or of the digits in the output text field. Check values a0c0 and 0b00 generate output abc0. Check program.print to ensure reprints properly. ************************************************************************************/ component { in opd0[ n ], opd1[ n ] } orBits( n ) { out result[ n ] } begin for i from 0 upto n do { in opd1[ i ] opd0[ i ] } or( 2 ) { out result[ i ] }; end end define base = 16, n = 16; path opd1[ n ], opd2[ n ]; input( "opd1", 10, 50, base, n ) { out opd1 }; input( "opd2", 10, 100, base, n ) { out opd2 }; { in opd1, opd2 }orBits( n ).output( "or", 10, 150, base, n ); ---------------------------------------------------------------- TestPrograms/g1.pipe/program.err ---------------------------------------------------------------- Reprinting ... ---------------------------------------------------------------- TestPrograms/g1.pipe/program.print ---------------------------------------------------------------- component { in opd0[ n ], opd1[ n ] } orBits( n ) { out result[ n ] } begin for i from 0 upto n do { in opd1[ i ] opd0[ i ] } or( 2 ) { out result[ i ] }; end end define base = 16, n = 16; path opd1[ n ], opd2[ n ]; input( "opd1", 10, 50, base, n ) { out opd1 }; input( "opd2", 10, 100, base, n ) { out opd2 }; { in opd1, opd2 } orBits( n ).output( "or", 10, 150, base, n );